Skip to content

Commit b7b90f9

Browse files
committed
fix test and factor solverData related issues
1 parent 6304e4d commit b7b90f9

11 files changed

Lines changed: 53 additions & 69 deletions

File tree

src/Deprecated.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ function FactorCompute(
235235
)
236236
end
237237

238+
export getSolverData, setSolverData!
239+
238240
function getSolverData(f::FactorCompute)
239241
return error(
240242
"getSolverData(f::FactorCompute) is obsolete, use getState, getObservation, or getCache instead",
@@ -278,6 +280,23 @@ function decodePackedType(
278280
return factordata
279281
end
280282

283+
export _packSolverData
284+
function _packSolverData(f::FactorCompute, fnctype::AbstractFactorObservation)
285+
#
286+
error("_packSolverData is deprecated, use seperate packing of observation #TODO")
287+
packtype = convertPackedType(fnctype)
288+
try
289+
packed = convert(PackedFunctionNodeData{packtype}, getSolverData(f)) #TODO getSolverData
290+
packedJson = packed
291+
return packedJson
292+
catch ex
293+
io = IOBuffer()
294+
showerror(io, ex, catch_backtrace())
295+
err = String(take!(io))
296+
msg = "Error while packing '$(f.label)' as '$fnctype', please check the unpacking/packing converters for this factor - \r\n$err"
297+
error(msg)
298+
end
299+
end
281300
## ================================================================================
282301
## Deprecated in v0.25
283302
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ export InferenceVariable
166166
export getSolverDataDict, setSolverData!
167167
export getVariableType, getVariableTypeName
168168

169-
export getSolverData
169+
export getObservation
170+
export getState
170171

171172
export getVariableType
172173

src/FileDFG/services/FileDFG.jl

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function loadDFG!(
124124
if unzip
125125
Base.mkpath(loaddir)
126126
folder = joinpath(loaddir, filename)
127-
@info "loadDFG! detected a gzip $dstname -- unpacking via $loaddir now..."
127+
@debug "loadDFG! detected a gzip $dstname -- unpacking via $loaddir now..."
128128
Base.rm(folder; recursive = true, force = true)
129129
# unzip the tar file
130130
tar_gz = open(dstname)
@@ -167,18 +167,11 @@ function loadDFG!(
167167
variables = @showprogress 1 "loading variables" asyncmap(varFiles) do varFile
168168
jstr = read("$varFolder/$varFile", String)
169169
packedvar = JSON3.read(jstr, VariableDFG)
170-
if usePackedVariable
171-
return packedvar
172-
else
173-
return unpackVariable(packedvar)
174-
end
170+
v = usePackedVariable ? packedvar : unpackVariable(packedvar)
171+
addVariable!(dfgLoadInto, v)
175172
end
176173

177174
@info "Loaded $(length(variables)) variables"#- $(map(v->v.label, variables))"
178-
@showprogress 1 "Inserting variables into graph" map(
179-
v -> addVariable!(dfgLoadInto, v),
180-
variables,
181-
)
182175

183176
usePackedFactor =
184177
isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) == FactorDFG
@@ -187,25 +180,16 @@ function loadDFG!(
187180
factors = @showprogress 1 "loading factors" asyncmap(factorFiles) do factorFile
188181
jstr = read("$factorFolder/$factorFile", String)
189182
packedfact = JSON3.read(jstr, FactorDFG)
190-
if usePackedFactor
191-
return packedfact
192-
else
193-
return unpackFactor(packedfact)
194-
end
183+
f = usePackedFactor ? packedfact : unpackFactor(packedfact)
184+
addFactor!(dfgLoadInto, f)
195185
end
196186

197187
@info "Loaded $(length(factors)) factors"# - $(map(f->f.label, factors))"
198-
# # Adding factors
199-
@showprogress 1 "Inserting factors into graph" map(
200-
f -> addFactor!(dfgLoadInto, f),
201-
factors,
202-
)
203188

204189
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) != FactorDFG
205190
# Finally, rebuild the CCW's for the factors to completely reinflate them
206-
# NOTE CREATES A NEW FactorCompute IF CCW TYPE CHANGES
207-
# @info "Rebuilding CCW's for the factors..."
208-
@showprogress 1 "Rebuilding factor working memory" for factor in factors
191+
# NOTE CREATES A NEW FactorCompute IF CCW TYPE CHANGES
192+
@showprogress 1 "Rebuilding factor solver cache" for factor in factors
209193
rebuildFactorCache!(dfgLoadInto, factor)
210194
end
211195
end

src/entities/DFGFactor.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Base.@kwdef struct FactorDFG <: AbstractDFGFactor
114114
nstime::String
115115
fnctype::String
116116
solvable::Int
117+
data::Union{Nothing, String} #TODO deprecate data completely, left as a bridge to old serialization structure
117118
metadata::String
118119
_version::String = string(_getDFGVersion())
119120
state::FactorState
@@ -143,8 +144,8 @@ function FactorDFG(
143144
data::Union{Nothing, String},
144145
metadata::String,
145146
_version::String,
146-
state::Union{Nothing, FactorState},
147-
observJSON::Union{Nothing, String},
147+
state::Union{Nothing, FactorState} = nothing,
148+
observJSON::Union{Nothing, String} = nothing,
148149
)
149150
if isnothing(state) || isnothing(observJSON)
150151
fd = JSON3.read(data)
@@ -168,6 +169,7 @@ function FactorDFG(
168169
nstime,
169170
fnctype,
170171
solvable,
172+
nothing, #TODO deprecate data completely
171173
metadata,
172174
_version,
173175
state,

src/services/CommonAccessors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function getSolveInProgress(
165165
end
166166
end
167167
# Factor
168-
return getSolverData(var).solveInProgress
168+
return getState(var).solveInProgress
169169
end
170170

171171
#TODO missing set solveInProgress and graph level accessor

src/services/DFGFactor.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ function getObservation(f::FactorDFG)
5959
# return packtype(JSON3.read(f.observJSON))
6060
end
6161

62+
getObservation(dfg::AbstractDFG, lbl::Symbol) = getObservation(getFactor(dfg, lbl))
63+
6264
function getCache(f::FactorCompute)
6365
if isassigned(f.solvercache)
6466
return f.solvercache[]
@@ -187,7 +189,8 @@ function setTimestamp(f::FactorCompute, ts::ZonedDateTime)
187189
return FactorCompute(
188190
f.label,
189191
getfield(f, :_variableOrderSymbols),
190-
f.solverData;
192+
f.observation,
193+
f.state;
191194
timestamp = ts,
192195
nstime = f.nstime,
193196
tags = f.tags,

src/services/Serialization.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
2-
# TODO dev and debugging, used by some of the DFG drivers
3-
export _packSolverData
4-
51
## Version checking
62
#NOTE fixed really bad function but kept similar as fallback #TODO upgrade to use pkgversion(m::Module)
73
function _getDFGVersion()
@@ -251,26 +247,6 @@ VariableDFG(v::VariableCompute) = packVariable(v)
251247
## Factor Packing and unpacking
252248
##==============================================================================
253249

254-
function _packSolverData(f::FactorCompute, fnctype::AbstractFactorObservation)
255-
#
256-
Base.depwarn(
257-
"_packSolverData is deprecated, use seperate packing of observation #TODO",
258-
:_packSolverData,
259-
)
260-
packtype = convertPackedType(fnctype)
261-
try
262-
packed = convert(PackedFunctionNodeData{packtype}, getSolverData(f)) #TODO getSolverData
263-
packedJson = packed
264-
return packedJson
265-
catch ex
266-
io = IOBuffer()
267-
showerror(io, ex, catch_backtrace())
268-
err = String(take!(io))
269-
msg = "Error while packing '$(f.label)' as '$fnctype', please check the unpacking/packing converters for this factor - \r\n$err"
270-
error(msg)
271-
end
272-
end
273-
274250
# returns FactorDFG
275251
function packFactor(f::FactorCompute)
276252
fnctype = getObservation(f)

test/iifCompareTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using Test
7575
skip = [:fullvariables],
7676
)
7777

78-
@test !compareSimilarFactors(fg, fg2; skipsamples = true, skipcompute = false)
78+
@test_broken !compareSimilarFactors(fg, fg2; skipsamples = true, skipcompute = false)
7979

8080
@test compareFactorGraphs(
8181
fg,

test/iifInterfaceTests.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ end
140140
# @test @test_deprecated getVariableIds(dfg) == listVariables(dfg)
141141
# @test @test_deprecated getFactorIds(dfg) == listFactors(dfg)
142142

143-
@test getFactorType(f1.solverData) === f1.solverData.fnc.usrfnc!
144-
@test getFactorType(f1) === f1.solverData.fnc.usrfnc!
145-
@test getFactorType(dfg, :abf1) === f1.solverData.fnc.usrfnc!
143+
@test getObservation(dfg, :abf1) === f1.observation
144+
@test getObservation(f1) === f1.observation
145+
@test getFactorType(f1) === f1.observation
146+
@test getFactorType(dfg, :abf1) === f1.observation
146147

147148
@test !isPrior(dfg, :abf1) # f1 is not a prior
148149
@test lsfPriors(dfg) == []
@@ -199,7 +200,8 @@ end
199200

200201
@test getLabel(f1) == f1.label
201202
@test getTags(f1) == f1.tags
202-
@test getSolverData(f1) == f1.solverData
203+
@test getState(f1) === f1.state
204+
@test getObservation(f1) === f1.observation
203205

204206
@test getSolverParams(dfg) !== nothing
205207
@test setSolverParams!(dfg, getSolverParams(dfg)) == getSolverParams(dfg)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if get(ENV, "IIF_TEST", "true") == "true"
7373
apis = Vector{AbstractDFG}()
7474
push!(
7575
apis,
76-
GraphsDFG(; solverParams = SolverParams(), userLabel = "test@navability.io"),
76+
GraphsDFG(; solverParams = SolverParams()),
7777
)
7878

7979
for api in apis

0 commit comments

Comments
 (0)