79
79
80
80
typeModuleName (varT:: Type{<:InferenceVariable} ) = typeModuleName (varT ())
81
81
82
- function getTypeFromSerializationModule (variableTypeString:: String )
82
+ function getTypeFromSerializationModule (_typeString:: AbstractString )
83
+ @debug " DFG converting type string to Julia type" _typeString
83
84
try
84
85
# split the type at last `.`
85
- split_st = split (variableTypeString , r" \. (?!.*\. )" )
86
+ split_st = split (_typeString , r" \. (?!.*\. )" )
86
87
# if module is specified look for the module in main, otherwise use Main
87
88
if length (split_st) == 2
88
89
m = getfield (Main, Symbol (split_st[1 ]))
@@ -102,7 +103,7 @@ function getTypeFromSerializationModule(variableTypeString::String)
102
103
return ret
103
104
104
105
catch ex
105
- @error " Unable to deserialize soft type $(variableTypeString ) "
106
+ @error " Unable to deserialize type $(_typeString ) "
106
107
io = IOBuffer ()
107
108
showerror (io, ex, catch_backtrace ())
108
109
err = String (take! (io))
@@ -152,11 +153,12 @@ end
152
153
153
154
"""
154
155
$(SIGNATURES)
155
- Unpack a Dict{String, Any} into a PPE.
156
+
157
+ Common unpack a Dict{String, Any} into a PPE.
156
158
"""
157
159
function _unpackPPE (
158
160
packedPPE:: Dict{String, Any} ;
159
- _type = pop! (packedPPE, " _type" )
161
+ _type = pop! (packedPPE, " _type" ) # required for generic use
160
162
)
161
163
#
162
164
# Cleanup Zoned timestamp, which is always UTC
@@ -165,18 +167,32 @@ function _unpackPPE(
165
167
end
166
168
167
169
# !haskey(packedPPE, "_type") && error("Cannot find type key '_type' in packed PPE data")
168
- (_type === nothing || _type == " " ) && error (" Cannot deserialize PPE, type key is empty" )
170
+ if (_type === nothing || _type == " " )
171
+ @warn " Cannot deserialize PPE, unknown type key, trying DistributedFactorGraphs.MeanMaxPPE" _type
172
+ _type = " DistributedFactorGraphs.MeanMaxPPE"
173
+ end
174
+ ppeType = DistributedFactorGraphs. getTypeFromSerializationModule (_type)
175
+
169
176
ppe = Unmarshal. unmarshal (
170
- DistributedFactorGraphs. getTypeFromSerializationModule (_type),
171
- packedPPE
172
- )
177
+ ppeType,
178
+ packedPPE
179
+ )
180
+ # _pk = Symbol(packedPPE["solveKey"])
181
+ # ppe = MeanMaxPPE(;
182
+ # solveKey=_pk,
183
+ # suggested=float.(pd["suggested"]),
184
+ # max=float.(pd["max"]),
185
+ # mean=float.(pd["mean"]),
186
+ # lastUpdatedTimestamp=DateTime(string(pd["lastUpdatedTimestamp"]))
187
+ # )
188
+
173
189
return ppe
174
190
end
175
191
176
192
# returns a DFGVariable
177
193
function unpackVariable (dfg:: G ,
178
194
packedProps:: Dict{String, Any} ;
179
- unpackPPEs:: Bool = haskey (packedProps, " ppeDict " ) ,
195
+ unpackPPEs:: Bool = true ,
180
196
unpackSolverData:: Bool = true ,
181
197
unpackBigData:: Bool = true ) where G <: AbstractDFG
182
198
@debug " Unpacking variable:\r\n $packedProps "
@@ -188,32 +204,31 @@ function unpackVariable(dfg::G,
188
204
# Parse it
189
205
timestamp = ZonedDateTime (packedProps[" timestamp" ])
190
206
nstime = Nanosecond (get (packedProps, " nstime" , 0 ))
191
- # Supporting string serialization using packVariable and CGDFG serialization (Vector{String})
192
- if packedProps[" tags" ] isa String
193
- tags = JSON2. read (packedProps[" tags" ], Vector{Symbol})
207
+
208
+ # FIXME , drop nested packing, see DFG #867
209
+ # string serialization using packVariable and CGDFG serialization (Vector{String})
210
+ tags = if packedProps[" tags" ] isa String
211
+ JSON2. read (packedProps[" tags" ], Vector{Symbol})
194
212
else
195
- tags = Symbol .(packedProps[" tags" ])
213
+ Symbol .(packedProps[" tags" ])
196
214
end
197
- ppeDict = if unpackPPEs
215
+
216
+ ppeDict = if haskey (packedProps," ppesDict" )
217
+ # FIXME , drop nested packing, see DFG #867
198
218
JSON2. read (packedProps[" ppeDict" ], Dict{Symbol, MeanMaxPPE})
199
219
elseif haskey (packedProps," ppes" ) && packedProps[" ppes" ] isa AbstractVector
220
+ # these different cases are not well covered in tests, but first fix #867
221
+ # TODO dont hardcode the ppeType (which is already discovered for each entry in _updatePPE)
200
222
ppedict = Dict {Symbol, MeanMaxPPE} ()
201
223
for pd in packedProps[" ppes" ]
202
- # FIXME unmarshalling, consolidate with _unpackPPE
203
- pk = pd[" solveKey" ]
204
- _pk = Symbol (pk)
205
- ppedict[_pk] = MeanMaxPPE (;
206
- solveKey= _pk,
207
- suggested= float .(pd[" suggested" ]),
208
- max= float .(pd[" max" ]),
209
- mean= float .(pd[" mean" ]),
210
- lastUpdatedTimestamp= DateTime (string (pd[" lastUpdatedTimestamp" ]))
211
- )
224
+ _type = haskey (pd, " _type" ) ? pd[" _type" ] : " DistributedFactorGraphs.MeanMaxPPE"
225
+ ppedict[Symbol (pd[" solveKey" ])] = _unpackPPE (pd; _type)
212
226
end
213
227
ppedict
214
228
else
215
229
Dict {Symbol, MeanMaxPPE} ()
216
230
end
231
+
217
232
smallData = JSON2. read (packedProps[" smallData" ], Dict{Symbol, SmallDataTypes})
218
233
219
234
variableTypeString = if haskey (packedProps, " softtype" )
0 commit comments