53
53
54
54
# Corrects any `::ZonedDateTime` fields of T in corresponding `interm::Dict` as `dateformat"yyyy-mm-ddTHH:MM:SS.ssszzz"`
55
55
function standardizeZDTStrings! (T, interm:: Dict )
56
+
56
57
for (name, typ) in zip (fieldnames (T), T. types)
57
58
if typ <: ZonedDateTime
58
59
namestr = string (name)
@@ -125,16 +126,16 @@ function packVariable(dfg::AbstractDFG, v::DFGVariable)
125
126
props[" label" ] = string (v. label)
126
127
props[" timestamp" ] = Dates. format (v. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )
127
128
props[" nstime" ] = string (v. nstime. value)
128
- props[" tags" ] = JSON2. write (v. tags)
129
- props[" ppeDict" ] = JSON2. write (v. ppeDict)
130
- props[" solverDataDict" ] = JSON2 . write (Dict (keys (v. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (v. solverDataDict))))
131
- props[" smallData" ] = JSON2. write (v. smallData)
129
+ props[" tags" ] = v . tags # JSON2.write(v.tags)
130
+ props[" ppeDict" ] = v . ppeDict # JSON2.write(v.ppeDict)
131
+ props[" solverDataDict" ] = (Dict (keys (v. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (v. solverDataDict)))) # JSON2.write
132
+ props[" smallData" ] = v . smallData # JSON2.write(v.smallData)
132
133
props[" solvable" ] = v. solvable
133
134
props[" variableType" ] = typeModuleName (getVariableType (v))
134
- props[" dataEntry" ] = JSON2 . write (Dict (keys (v. dataDict) .=> map (bde -> JSON. json (bde), values (v. dataDict))))
135
- props[" dataEntryType" ] = JSON2 . write (Dict (keys (v. dataDict) .=> map (bde -> typeof (bde), values (v. dataDict))))
135
+ props[" dataEntry" ] = (Dict (keys (v. dataDict) .=> values (v . dataDict))) # map(bde -> JSON.json(bde), values(v.dataDict)))) #JSON2.write
136
+ props[" dataEntryType" ] = (Dict (keys (v. dataDict) .=> map (bde -> typeof (bde), values (v. dataDict)))) # JSON2.write
136
137
props[" _version" ] = _getDFGVersion ()
137
- return props:: Dict{String, Any}
138
+ return props # ::Dict{String, Any}
138
139
end
139
140
140
141
"""
@@ -192,7 +193,14 @@ function _unpackVariableNodeData(
192
193
return unpackVariableNodeData (dfg, packedVND)
193
194
end
194
195
195
- # returns a DFGVariable
196
+ """
197
+ $SIGNATURES
198
+ Returns a DFGVariable.
199
+
200
+ DevNotes
201
+ - v0.19 packVariable fixed nested JSON bug on these fields, see #867:
202
+ - `tags`, `ppeDict`, `solverDataDict`, `smallData`, `dataEntry`, `dataEntryType`
203
+ """
196
204
function unpackVariable (
197
205
dfg:: AbstractDFG ,
198
206
packedProps:: Dict{String, Any} ;
@@ -236,7 +244,19 @@ function unpackVariable(
236
244
Dict {Symbol, MeanMaxPPE} ()
237
245
end
238
246
239
- smallData = JSON2. read (packedProps[" smallData" ], Dict{Symbol, SmallDataTypes})
247
+ smallData = if haskey (packedProps, " smallData" )
248
+ if packedProps[" smallData" ] isa String
249
+ JSON2. read (packedProps[" smallData" ], Dict{Symbol, SmallDataTypes})
250
+ elseif packedProps[" smallData" ] isa Dict
251
+ Dict {Symbol, SmallDataTypes} ( Symbol .(keys (packedProps[" smallData" ])) .=> values (packedProps[" smallData" ]) )
252
+ # packedProps["smallData"]
253
+ else
254
+ @warn " unknown smallData deserialization on $label , type $(typeof (packedProps[" smallData" ])) " maxlog= 10
255
+ Dict {Symbol, SmallDataTypes} ()
256
+ end
257
+ else
258
+ Dict {Symbol, SmallDataTypes} ()
259
+ end
240
260
241
261
variableTypeString = packedProps[" variableType" ]
242
262
@@ -246,7 +266,11 @@ function unpackVariable(
246
266
247
267
# FIXME , drop nested packing, see DFG #867
248
268
solverData = if unpackSolverData && haskey (packedProps, " solverDataDict" )
249
- packed = JSON2. read (packedProps[" solverDataDict" ], Dict{String, PackedVariableNodeData})
269
+ packed = if packedProps[" solverDataDict" ] isa String
270
+ JSON2. read (packedProps[" solverDataDict" ], Dict{String, PackedVariableNodeData})
271
+ else
272
+ packedProps[" solverDataDict" ]
273
+ end
250
274
Dict {Symbol, VariableNodeData{variableType, pointType}} (Symbol .(keys (packed)) .=> map (p -> unpackVariableNodeData (dfg, p), values (packed)))
251
275
elseif unpackPPEs && haskey (packedProps," solverData" ) && packedProps[" solverData" ] isa AbstractVector
252
276
solverdict = Dict {Symbol, VariableNodeData{variableType, pointType}} ()
@@ -275,16 +299,42 @@ function unpackVariable(
275
299
# Now rehydrate complete DataEntry type.
276
300
if unpackBigData
277
301
# TODO Deprecate - for backward compatibility between v0.8 and v0.9, remove in v0.10
278
- dataElemTypes = JSON2. read (packedProps[" dataEntryType" ], Dict{Symbol, Symbol})
302
+ dataElemTypes = if packedProps[" dataEntryType" ] isa String
303
+ JSON2. read (packedProps[" dataEntryType" ], Dict{Symbol, String})
304
+ else
305
+ # packedProps["dataEntryType"]
306
+ Dict {Symbol, String} ( Symbol .(keys (packedProps[" dataEntryType" ])) .=> values (packedProps[" dataEntryType" ]) )
307
+ end
279
308
for (k,name) in dataElemTypes
280
- dataElemTypes[k] = Symbol (split (string (name), ' .' )[end ])
309
+ val = split (string (name), ' .' )[end ]
310
+ dataElemTypes[k] = val
311
+ end
312
+
313
+ dataIntermed = if packedProps[" dataEntry" ] isa String
314
+ JSON2. read (packedProps[" dataEntry" ], Dict{Symbol, String})
315
+ elseif packedProps[" dataEntry" ] isa NamedTuple
316
+ # case where JSON2 did unpacking of all fields as hard types (no longer String)
317
+ # Dict{Symbol, String}( Symbol.(keys(packedProps["dataEntry"])) .=> values(packedProps["dataEntry"]) )
318
+ for i in 1 : length (packedProps[" dataEntry" ])
319
+ k = keys (packedProps[" dataEntry" ])[i]
320
+ bdeInter = values (packedProps[" dataEntry" ])[i]
321
+ objType = getfield (DistributedFactorGraphs, Symbol (dataElemTypes[k]))
322
+ # standardizeZDTStrings!(objType, bdeInter)
323
+ # fullVal = Unmarshal.unmarshal(objType, bdeInter)
324
+ variable. dataDict[k] = objType (;bdeInter... )
325
+ end
326
+ # forcefully skip, since variabe.dataDict already populated here
327
+ Dict {Symbol,String} ()
328
+ else
329
+ Dict ( Symbol .(keys (packedProps[" dataEntry" ])) .=> values (packedProps[" dataEntry" ]) )
281
330
end
282
331
283
- dataIntermed = JSON2. read (packedProps[" dataEntry" ], Dict{Symbol, String})
332
+ _doparse (s) = s
333
+ _doparse (s:: String ) = JSON. parse (s)
284
334
285
335
for (k,bdeInter) in dataIntermed
286
- interm = JSON. parse (bdeInter)
287
- objType = getfield (DistributedFactorGraphs, dataElemTypes[k])
336
+ interm = _doparse (bdeInter) # JSON.parse(bdeInter) # bdeInter
337
+ objType = getfield (DistributedFactorGraphs, Symbol ( dataElemTypes[k]) )
288
338
standardizeZDTStrings! (objType, interm)
289
339
fullVal = Unmarshal. unmarshal (objType, interm)
290
340
variable. dataDict[k] = fullVal
@@ -329,7 +379,7 @@ function packVariableNodeData(::G, d::VariableNodeData{T}) where {G <: AbstractD
329
379
d. solveKey)
330
380
end
331
381
332
- function unpackVariableNodeData (dfg:: G , d:: PackedVariableNodeData ) where G <: AbstractDFG
382
+ function unpackVariableNodeData (dfg:: G , d:: Union{<: PackedVariableNodeData,<:NamedTuple} ) where G <: AbstractDFG
333
383
@debug " Dispatching conversion packed variable -> variable for type $(string (d. variableType)) "
334
384
# Figuring out the variableType
335
385
# TODO deprecated remove in v0.11 - for backward compatibility for saved variableTypes.
@@ -352,13 +402,31 @@ function unpackVariableNodeData(dfg::G, d::PackedVariableNodeData) where G <: Ab
352
402
BW = reshape (d. vecbw,r4,c4)
353
403
354
404
#
355
- return VariableNodeData {T, getPointType(T)} (vals, BW, d. BayesNetOutVertIDs,
356
- d. dimIDs, d. dims, d. eliminated, d. BayesNetVertID, d. separator,
357
- T (), d. initialized, d. infoPerCoord, d. ismargin, d. dontmargin,
358
- d. solveInProgress, d. solvedCount, d. solveKey,
405
+ return VariableNodeData {T, getPointType(T)} (
406
+ vals,
407
+ BW,
408
+ Symbol .(d. BayesNetOutVertIDs),
409
+ d. dimIDs,
410
+ d. dims,
411
+ d. eliminated,
412
+ Symbol (d. BayesNetVertID),
413
+ Symbol .(d. separator),
414
+ T (),
415
+ d. initialized,
416
+ d. infoPerCoord,
417
+ d. ismargin,
418
+ d. dontmargin,
419
+ d. solveInProgress,
420
+ d. solvedCount,
421
+ Symbol (d. solveKey),
359
422
Dict {Symbol,Threads.Condition} () )
360
423
end
361
424
425
+ unpackVariableNodeData (
426
+ dfg:: AbstractDFG ,
427
+ d:: Dict ) = unpackVariableNodeData (dfg, Unmarshal. unmarshal (PackedVariableNodeData, d))
428
+
429
+
362
430
# #==============================================================================
363
431
# # Factor Packing and unpacking
364
432
# #==============================================================================
0 commit comments