Skip to content

Commit 9c5356b

Browse files
committed
unpack solverData or solverDataDict
1 parent eae4554 commit 9c5356b

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/Neo4jDFG/services/Neo4jDFG.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,6 @@ end
728728

729729
## VariableSolverData CRUD
730730

731-
"""
732-
$(SIGNATURES)
733-
Unpack a Dict{String, Any} into a PPE.
734-
"""
735-
function _unpackVariableNodeData(dfg::G, packedDict::Dict{String, Any})::VariableNodeData where G <: AbstractDFG
736-
packedVND = Unmarshal.unmarshal(PackedVariableNodeData, packedDict)
737-
return unpackVariableNodeData(dfg, packedVND)
738-
end
739-
740731
function listVariableSolverData(dfg::Neo4jDFG, variablekey::Symbol; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::Vector{Symbol}
741732
return _listVarSubnodesForType(dfg, variablekey, VariableNodeData, "solveKey"; currentTransaction=currentTransaction)
742733
end

src/services/Serialization.jl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,30 @@ function _unpackPPE(
189189
return ppe
190190
end
191191

192+
"""
193+
$(SIGNATURES)
194+
195+
Unpack a Dict{String, Any} into a PPE.
196+
197+
Notes:
198+
- returns `::VariableNodeData`
199+
"""
200+
function _unpackVariableNodeData(
201+
dfg::AbstractDFG,
202+
packedDict::Dict{String, Any}
203+
)
204+
#
205+
packedVND = Unmarshal.unmarshal(PackedVariableNodeData, packedDict)
206+
return unpackVariableNodeData(dfg, packedVND)
207+
end
208+
192209
# returns a DFGVariable
193210
function unpackVariable(dfg::G,
194211
packedProps::Dict{String, Any};
195212
unpackPPEs::Bool=true,
196213
unpackSolverData::Bool=true,
197214
unpackBigData::Bool=true) where G <: AbstractDFG
215+
#
198216
@debug "Unpacking variable:\r\n$packedProps"
199217
# Version checking.
200218
_versionCheck(packedProps)
@@ -213,10 +231,10 @@ function unpackVariable(dfg::G,
213231
Symbol.(packedProps["tags"])
214232
end
215233

216-
ppeDict = if haskey(packedProps,"ppesDict")
234+
ppeDict = if unpackPPEs && haskey(packedProps,"ppesDict")
217235
# FIXME, drop nested packing, see DFG #867
218236
JSON2.read(packedProps["ppeDict"], Dict{Symbol, MeanMaxPPE})
219-
elseif haskey(packedProps,"ppes") && packedProps["ppes"] isa AbstractVector
237+
elseif unpackPPEs && haskey(packedProps,"ppes") && packedProps["ppes"] isa AbstractVector
220238
# these different cases are not well covered in tests, but first fix #867
221239
# TODO dont hardcode the ppeType (which is already discovered for each entry in _updatePPE)
222240
ppedict = Dict{Symbol, MeanMaxPPE}()
@@ -237,11 +255,18 @@ function unpackVariable(dfg::G,
237255
isnothing(variableType) && error("Cannot deserialize variableType '$variableTypeString' in variable '$label'")
238256
pointType = getPointType(variableType)
239257

240-
if unpackSolverData
258+
solverData = if unpackSolverData && haskey(packedProps, "solverDataDict")
241259
packed = JSON2.read(packedProps["solverDataDict"], Dict{String, PackedVariableNodeData})
242-
solverData = Dict{Symbol, VariableNodeData{variableType, pointType}}(Symbol.(keys(packed)) .=> map(p -> unpackVariableNodeData(dfg, p), values(packed)))
260+
Dict{Symbol, VariableNodeData{variableType, pointType}}(Symbol.(keys(packed)) .=> map(p -> unpackVariableNodeData(dfg, p), values(packed)))
261+
elseif unpackPPEs && haskey(packedProps,"solverData") && packedProps["solverData"] isa AbstractVector
262+
solverdict = Dict{Symbol, VariableNodeData{variableType, pointType}}()
263+
for sd in packedProps["solverData"]
264+
# _type = haskey(sd, "_type") ? sd["_type"] : "DistributedFactorGraphs.PackedVariableNodeData"
265+
solverdict[Symbol(sd["solveKey"])] = _unpackVariableNodeData(dfg, sd)
266+
end
267+
solverdict
243268
else
244-
solverData = Dict{Symbol, VariableNodeData{variableType, pointType}}()
269+
Dict{Symbol, VariableNodeData{variableType, pointType}}()
245270
end
246271
# Rebuild DFGVariable using the first solver variableType in solverData
247272
# @info "dbg Serialization 171" variableType Symbol(packedProps["label"]) timestamp nstime ppeDict solverData smallData Dict{Symbol,AbstractDataEntry}() Ref(packedProps["solvable"])

0 commit comments

Comments
 (0)