Skip to content

Commit 39565e0

Browse files
authored
Towards DFG v1 deprecated/renamed fields and serialization changes (#1892)
* Update some deprecated/renamed fields * getVariableType -> getStateKind, getFactorType -> getObservation * fix searialization
1 parent 914928c commit 39565e0

62 files changed

Lines changed: 463 additions & 449 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IncrementalInference/ext/FluxModelsSerialization.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _deserializeFluxDataBase64(sdata::AbstractString)
3333
return data
3434
end
3535

36-
function DFG.packDistribution(obj::FluxModelsDistribution)
36+
function DFG.pack(obj::FluxModelsDistribution)
3737
#
3838

3939
# and the specialSampler function -- likely to be deprecated
@@ -75,7 +75,7 @@ function DFG.packDistribution(obj::FluxModelsDistribution)
7575
#
7676
end
7777

78-
function DFG.unpackDistribution(obj::PackedFluxModelsDistribution)
78+
function DFG.unpack(obj::PackedFluxModelsDistribution)
7979
#
8080
obj.serializeHollow && @warn(
8181
"Deserialization of FluxModelsDistribution.serializationHollow=true is not yet well developed, please open issues at IncrementalInference.jl accordingly."
@@ -104,15 +104,15 @@ function Base.convert(
104104
)
105105
#
106106
# convert to packed type first
107-
return DFG.packDistribution(obj)
107+
return DFG.pack(obj)
108108
end
109109

110110
function convert(
111111
::Union{Type{<:SamplableBelief}, Type{<:FluxModelsDistribution}},
112112
obj::PackedFluxModelsDistribution,
113113
)
114114
#
115-
return DFG.unpackDistribution(obj)
115+
return DFG.unpack(obj)
116116
end
117117

118118
#

IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ end
174174
# # backward direction
175175
# prob = oder.backwardProblem
176176
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
177-
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[1]))),
177+
# convert(Tuple, getManifold(getStateKind(cf.fullvariables[1]))),
178178
# )
179179
# # FIXME use ccw.varValsAll containter?
180180
# (getBelief(cf.fullvariables[2]) |> getPoints)[cf._sampleIdx]
@@ -183,7 +183,7 @@ end
183183
# prob = oder.forwardProblem
184184
# # buffer manifold operations for use during factor evaluation
185185
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
186-
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[2]))),
186+
# convert(Tuple, getManifold(getStateKind(cf.fullvariables[2]))),
187187
# )
188188
# # FIXME use ccw.varValsAll containter?
189189
# (getBelief(cf.fullvariables[1]) |> getPoints)[cf._sampleIdx]
@@ -254,15 +254,15 @@ end
254254
# # backward direction
255255
# prob = oder.backwardProblem
256256
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
257-
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[1]))),
257+
# convert(Tuple, getManifold(getStateKind(cf.fullvariables[1]))),
258258
# )
259259
# cf._legacyParams[2]
260260
# else
261261
# # forward backward
262262
# prob = oder.forwardProblem
263263
# # buffer manifold operations for use during factor evaluation
264264
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
265-
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[2]))),
265+
# convert(Tuple, getManifold(getStateKind(cf.fullvariables[2]))),
266266
# )
267267
# cf._legacyParams[1]
268268
# end
@@ -290,7 +290,7 @@ function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int
290290

291291
# how many trajectories to propagate?
292292
#
293-
v2T = getVariableType(cf.fullvariables[2])
293+
v2T = getStateKind(cf.fullvariables[2])
294294
meas = [allocate(getPointIdentity(v2T)) for _ = 1:N]
295295
# meas = [zeros(getDimension(cf.fullvariables[2])) for _ = 1:N]
296296

@@ -299,7 +299,7 @@ function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int
299299
u0pts, M = if cf.solvefor == 1
300300
# backward direction
301301
prob = oder.backwardProblem
302-
M_ = getManifold(getVariableType(cf.fullvariables[1]))
302+
M_ = getManifold(getStateKind(cf.fullvariables[1]))
303303
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
304304
AMP._manifoldtuple(M_),
305305
)
@@ -308,7 +308,7 @@ function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int
308308
else
309309
# forward backward
310310
prob = oder.forwardProblem
311-
M_ = getManifold(getVariableType(cf.fullvariables[2]))
311+
M_ = getManifold(getStateKind(cf.fullvariables[2]))
312312
# buffer manifold operations for use during factor evaluation
313313
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
314314
AMP._manifoldtuple(M_),

IncrementalInference/src/CliqueStateMachine/services/CliqueStateMachine.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,16 @@ function presolveChecklist_StateMachine(csmc::CliqStateMachineContainer)
175175
csmc,
176176
"CSM-0b create empty data for $(getLabel(var)) on solveKey=$(csmc.solveKey)",
177177
)
178-
varType = getVariableType(var)
178+
varType = getStateKind(var)
179179
# FIXME check the marginalization requirements
180180
setDefaultNodeData!(
181181
var,
182182
0,
183-
getSolverParams(csmc.cliqSubFg).N,
184-
getDimension(varType);
183+
getSolverParams(csmc.cliqSubFg).N;
185184
solveKey = csmc.solveKey,
186185
initialized = false,
187186
varType = varType,
188-
dontmargin = false,
187+
# dontmargin = false,
189188
)
190189
#
191190
@info "create vnd solveKey" csmc.solveKey N

IncrementalInference/src/Deprecated.jl

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
2+
# moved here from DistributedFactorGraphs.jl, replace with new way.
3+
function typeModuleName(variableType::StateType)
4+
Base.depwarn("typeModuleName is obsolete", :typeModuleName)
5+
io = IOBuffer()
6+
ioc = IOContext(io, :module => DistributedFactorGraphs)
7+
show(ioc, typeof(variableType))
8+
return String(take!(io))
9+
end
10+
11+
"""
12+
$(SIGNATURES)
13+
Get a type from the serialization module.
14+
"""
15+
function getTypeFromSerializationModule(_typeString::AbstractString)
16+
@debug "DFG converting type string to Julia type" _typeString
17+
try
18+
# split the type at last `.`
19+
split_st = split(_typeString, r"\.(?!.*\.)")
20+
#if module is specified look for the module in main, otherwise use Main
21+
if length(split_st) == 2
22+
m = getfield(Main, Symbol(split_st[1]))
23+
else
24+
m = Main
25+
end
26+
noparams = split(split_st[end], r"{")
27+
ret = if 1 < length(noparams)
28+
# fix #671, but does not work with specific module yet
29+
bidx = findfirst(r"{", split_st[end])[1]
30+
@error("getTypeFromSerializationModule eval obsolete")
31+
Core.eval(m, Base.Meta.parse("$(noparams[1])$(split_st[end][bidx:end])"))
32+
else
33+
getfield(m, Symbol(split_st[end]))
34+
end
35+
36+
return ret
37+
38+
catch ex
39+
@error "Unable to deserialize type $(_typeString)"
40+
io = IOBuffer()
41+
showerror(io, ex, catch_backtrace())
42+
err = String(take!(io))
43+
@error(err)
44+
end
45+
return nothing
46+
end
47+
48+
149
## ================================================================================================
250
## Deprecated in v0.36
351
## ================================================================================================
@@ -161,7 +209,7 @@ setVariablePosteriorEstimates!(args...; kw...) = error("PPEs are obsolete (use `
161209

162210
@deprecate calcPPE(
163211
var::VariableCompute,
164-
varType::StateType = getVariableType(var);
212+
varType::StateType = getStateKind(var);
165213
solveKey::Symbol = :default,
166214
kwargs...,
167215
) calcMeanMaxSuggested(var, solveKey)
@@ -246,7 +294,7 @@ end
246294
# function ManifoldsVector(fg::AbstractDFG, varIds::Vector{Symbol})
247295
# manis = Bool[]
248296
# for k = varIds
249-
# push!(manis, getVariableType(fg, k) |> getManifold)
297+
# push!(manis, getStateKind(fg, k) |> getManifold)
250298
# end
251299
# ManifoldsVector(manis)
252300
# end
@@ -309,7 +357,7 @@ function solveGraphParametric2(
309357

310358
for vId in varIds
311359
p = getState(fg, vId, solvekey).val[1]
312-
flatvar[vId] = getCoordinates(getVariableType(fg, vId), p)
360+
flatvar[vId] = getCoordinates(getStateKind(fg, vId), p)
313361
end
314362

315363
initValues = flatvar.X
@@ -379,7 +427,7 @@ end
379427
# ) where {N_, F <: AbstractRelativeRoots, S, T}
380428
# #
381429
# # error("<:AbstractRelativeRoots is obsolete, use one of the other <:AbstractRelative types instead.")
382-
# # TODO get xDim = getDimension(getVariableType(Xi[sfidx])) but without having Xi
430+
# # TODO get xDim = getDimension(getStateKind(Xi[sfidx])) but without having Xi
383431
# if testshuffle || ccwl.partial
384432
# error(
385433
# "<:AbstractRelativeRoots factors with less or more measurement dimensions than variable dimensions have been discontinued, rather use <:AbstractManifoldMinimize.",
@@ -442,8 +490,8 @@ function Base.getproperty(ccw::CommonConvWrapper, f::Symbol)
442490
error("CommonConvWrapper.params is deprecated, use .varValsAll instead")
443491
return ccw.varValsAll[]
444492
elseif f == :vartypes
445-
@warn "CommonConvWrapper.vartypes is deprecated, use typeof.(getVariableType.(ccw.fullvariables) instead" maxlog=3
446-
return typeof.(getVariableType.(ccw.fullvariables))
493+
@warn "CommonConvWrapper.vartypes is deprecated, use typeof.(getStateKind.(ccw.fullvariables) instead" maxlog=3
494+
return typeof.(getStateKind.(ccw.fullvariables))
447495
elseif f == :hypotheses
448496
@warn "CommonConvWrapper.hypotheses is now under ccw.hyporecipe.hypotheses" maxlog=5
449497
return ccw.hyporecipe.hypotheses

IncrementalInference/src/ExportAPI.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ export CSMHistory,
9595
getVariableOrder,
9696
isVariable,
9797
isFactor,
98-
getFactorType,
98+
getObservation,
9999
getSofttype,
100-
getVariableType,
100+
getStateKind,
101101
getLogPath,
102102
joinLogPath,
103103
lsfPriors,
@@ -299,7 +299,7 @@ export ContinuousScalar, ContinuousEuclid # TODO figure out if this will be depr
299299
export Circular, Circle
300300

301301
# serializing distributions
302-
export packDistribution, unpackDistribution
302+
export pack, unpack
303303
export PackedCategorical #, PackedDiscreteNonParametric
304304
export PackedUniform, PackedNormal
305305
export PackedZeroMeanDiagNormal,

IncrementalInference/src/Factors/GenericFunctions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function convert(
238238
)
239239
#
240240

241-
varT = DFG.typeModuleName(getVariableType(obj.M))
241+
varT = typeModuleName(getStateKind(obj.M))
242242

243243
c = AMP.makeCoordsFromPoint(obj.M, obj.p)
244244

@@ -255,7 +255,7 @@ function convert(
255255
#
256256

257257
# piggy back on serialization of StateType rather than try serialize anything Manifolds.jl
258-
M = DFG.getTypeFromSerializationModule(obj.varType) |> getManifold
258+
M = getTypeFromSerializationModule(obj.varType) |> getManifold
259259

260260
# TODO this is too excessive
261261
e0 = getPointIdentity(M)

IncrementalInference/src/Factors/LinearRelative.jl

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
export LinearRelative, PackedLinearRelative
2+
export LinearRelative
33

44
"""
55
$(TYPEDEF)
@@ -10,8 +10,8 @@ Default linear offset between two scalar variables.
1010
X_2 = X_1 + η_Z
1111
```
1212
"""
13-
struct LinearRelative{N, T <: SamplableBelief} <: RelativeObservation
14-
Z::T
13+
DFG.@tags struct LinearRelative{N, T <: SamplableBelief} <: RelativeObservation
14+
Z::T & (lower = DFG.Packed, choosetype = DFG.resolvePackedType)
1515
end
1616

1717
# need several helper constructors since the dimension over which LinearRelative will be used is unknown at this point
@@ -56,24 +56,4 @@ function Base.convert(
5656
return LieGroups.TranslationGroup(N)
5757
end
5858

59-
"""
60-
$(TYPEDEF)
61-
Serialization type for `LinearRelative` binary factor.
62-
"""
63-
Base.@kwdef mutable struct PackedLinearRelative <: AbstractPackedObservation
64-
Z::PackedBelief
65-
end
66-
function convert(::Type{PackedLinearRelative}, d::LinearRelative)
67-
return PackedLinearRelative(convert(PackedBelief, d.Z))
68-
end
69-
function convert(::Type{LinearRelative}, d::PackedLinearRelative)
70-
return LinearRelative(convert(SamplableBelief, d.Z))
71-
end
72-
function DFG.pack(d::LinearRelative)
73-
return PackedLinearRelative(DFG.packDistribution(d.Z))
74-
end
75-
function DFG.unpack(d::PackedLinearRelative)
76-
return LinearRelative(DFG.unpackDistribution(d.Z))
77-
end
78-
7959
#

IncrementalInference/src/Factors/Mixture.jl

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,18 @@ function Mixture(f::Type{<:AbstractObservation}, args...)
5454
return f(Mixture(args...))
5555
end
5656

57-
Base.@kwdef struct PackedMixture{C} <: PackedBelief
58-
_type::String = "IncrementalInference.PackedMixture"
59-
components::C
60-
prior::PackedCategorical
57+
DFG.@tags struct PackedMixture
58+
components::NamedTuple & (choosetype = obj->NamedTuple{Tuple(Symbol.(keys(obj))), Tuple{DFG.resolveType.(values(obj))...}}, )
59+
prior & (lower = DFG.Packed, choosetype = DFG.resolvePackedType)
6160
end
6261

63-
# FIXME 🦨 use JSON properly (in JSONv1 upgrade)
64-
function PackedMixture(_type::String, comp_obj::JSON3.Object, prior_obj::JSON3.Object)
65-
PackedMixture(
66-
_type,
67-
NamedTuple(map(c -> c[1]=>convert(PackedBelief, c[2]), collect(pairs(comp_obj)))),
68-
PackedCategorical(; prior_obj...),
69-
)
70-
end
71-
72-
73-
function DFG.packDistribution(m::Mixture)
74-
PackedMixture(;
75-
components = map(packDistribution, m.components),
76-
prior = PackedCategorical(; p = m.prior.p)
77-
)
62+
function DFG.pack(m::Mixture)
63+
PackedMixture(map(DFG.Packed, m.components), m.prior)
7864
end
7965

80-
function DFG.unpackDistribution(pm::PackedMixture)
66+
function DFG.unpack(pm::PackedMixture)
8167
Mixture(
82-
map(unpackDistribution, pm.components),
83-
unpackDistribution(pm.prior)
68+
map(unpack, pm.components),
69+
pm.prior
8470
)
8571
end

IncrementalInference/src/Factors/PartialPrior.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ Base.@kwdef struct PackedPartialPrior <: AbstractPackedObservation
3535
end
3636

3737
function convert(::Type{PackedPartialPrior}, d::PartialPrior)
38-
return PackedPartialPrior(DFG.typeModuleName(d.varType), convert(PackedBelief, d.Z), [d.partial...;])
38+
return PackedPartialPrior(typeModuleName(d.varType), convert(PackedBelief, d.Z), [d.partial...;])
3939
# return PackedPartialPrior(convert(PackedBelief, d.Z), [d.partial...;])
4040
end
4141
function convert(::Type{PartialPrior}, d::PackedPartialPrior)
42-
return PartialPrior(DFG.getTypeFromSerializationModule(d.varType), convert(SamplableBelief, d.Z),(d.partials...,))
42+
return PartialPrior(getTypeFromSerializationModule(d.varType), convert(SamplableBelief, d.Z),(d.partials...,))
4343
# return PartialPrior(convert(SamplableBelief, d.Z), (d.partials...,))
4444
end

0 commit comments

Comments
 (0)