Skip to content

Commit 4c1a729

Browse files
committed
compat fixes on loading fileDFG
1 parent bad0893 commit 4c1a729

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1111
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1212
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1313
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
14+
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
1415
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1516
ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
1617
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using Reexport
2525
using JSON
2626
using Unmarshal
2727
using JSON2 # JSON2 requires all properties to be in correct sequence, can't guarantee that from DB.
28+
# using JSON3
2829
using LinearAlgebra
2930
using SparseArrays
3031
using UUIDs

src/FileDFG/services/FileDFG.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
129129

130130
varFiles = readdir(varFolder)
131131
factorFiles = readdir(factorFolder)
132-
for varFile in varFiles
132+
@showprogress 1 "loading variables" for varFile in varFiles
133133
packedData = JSON.parsefile("$varFolder/$varFile"; dicttype=Dict{String, Any})
134134
# open("$varFolder/$varFile") do io
135135
# packedData = JSON.parse(io; dicttype=Dict{String, Any})
@@ -141,7 +141,7 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
141141
# Adding variables
142142
map(v->addVariable!(dfgLoadInto, v), variables)
143143

144-
for factorFile in factorFiles
144+
@showprogress 1 "loading factors" for factorFile in factorFiles
145145
open("$factorFolder/$factorFile") do io
146146
packedData = JSON2.read(io, Dict{String, Any})
147147
push!(factors, unpackFactor(dfgLoadInto, packedData))
@@ -155,7 +155,7 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
155155
# Finally, rebuild the CCW's for the factors to completely reinflate them
156156
# NOTE CREATES A NEW DFGFactor IF CCW TYPE CHANGES
157157
@info "Rebuilding CCW's for the factors..."
158-
for factor in factors
158+
@showprogress 1 "build factor operational memory" for factor in factors
159159
rebuildFactorMetadata!(dfgLoadInto, factor)
160160
end
161161

src/services/Serialization.jl

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ function unpackVariable(
307307

308308
# FIXME, drop nested packing, see DFG #867
309309
# string serialization using packVariable and CGDFG serialization (Vector{String})
310-
tags = Symbol.(packedProps["tags"])
310+
tags_ = if packedProps["tags"] isa String
311+
Symbol.(JSON2.read(packedProps["tags"], Vector{String}))
312+
else
313+
Symbol.(packedProps["tags"])
314+
end
311315

312316
# FIXME, drop nested packing, see DFG #867
313317
ppeDict = if unpackPPEs && haskey(packedProps,"ppesDict")
@@ -345,15 +349,24 @@ function unpackVariable(
345349
isnothing(variableType) && error("Cannot deserialize variableType '$variableTypeString' in variable '$label'")
346350
pointType = getPointType(variableType)
347351

352+
_ensureid!(s::Dict) = begin s["id"] = haskey(s, "id") ? s["id"] : nothing end
353+
_ensureid!(s::PackedVariableNodeData) = s
354+
348355
# FIXME, drop nested packing, see DFG #867
349356
solverData = if unpackSolverData && haskey(packedProps, "solverDataDict")
350357
packed = if packedProps["solverDataDict"] isa String
351-
JSON2.read(packedProps["solverDataDict"], Dict{String, PackedVariableNodeData})
358+
# JSON2.read(packedProps["solverDataDict"], Dict{String, PackedVariableNodeData})
359+
# JSON3.read(packedProps["solverDataDict"], Dict{String, PackedVariableNodeData})
360+
jdc = JSON.parse(packedProps["solverDataDict"])
361+
jpvd = Dict{String,PackedVariableNodeData}()
362+
for (k,v) in jdc
363+
_ensureid!(v)
364+
jpvd[k] = transcodeType(PackedVariableNodeData, v)
365+
end
366+
jpvd
352367
else
353368
packedProps["solverDataDict"]
354369
end
355-
_ensureid!(s::Dict) = begin s["id"]=nothing; end
356-
_ensureid!(s::PackedVariableNodeData) = s
357370
packedvals = values(packed)
358371
_ensureid!.(packedvals)
359372
# TODO deprecate, this is for DFG18 compat only
@@ -365,17 +378,20 @@ function unpackVariable(
365378
# Rebuild DFGVariable using the first solver variableType in solverData
366379
# @info "dbg Serialization 171" variableType Symbol(packedProps["label"]) timestamp nstime ppeDict solverData smallData Dict{Symbol,AbstractDataEntry}() Ref(packedProps["solvable"])
367380
# variable = DFGVariable{variableType}(Symbol(packedProps["label"]), timestamp, nstime, Set(tags), ppeDict, solverData, smallData, Dict{Symbol,AbstractDataEntry}(), Ref(packedProps["solvable"]))
368-
variable = DFGVariable( id = id,
369-
Symbol(packedProps["label"]),
370-
variableType,
371-
timestamp=timestamp,
372-
nstime=nstime,
373-
tags=Set{Symbol}(tags),
374-
estimateDict=ppeDict,
375-
solverDataDict=solverData,
376-
smallData=smallData,
377-
dataDict=Dict{Symbol,AbstractDataEntry}(),
378-
solvable=packedProps["solvable"] )
381+
382+
variable = DFGVariable{variableType}(;
383+
id=id,
384+
label = Symbol(packedProps["label"]),
385+
# variableType = variableType,
386+
timestamp = timestamp,
387+
nstime = nstime,
388+
tags = Set{Symbol}(tags_),
389+
ppeDict = ppeDict,
390+
solverDataDict = solverData,
391+
smallData= smallData,
392+
dataDict = Dict{Symbol,AbstractDataEntry}(),
393+
solvable = Ref(Int(packedProps["solvable"]))
394+
)
379395
#
380396

381397
# Now rehydrate complete DataEntry type.

0 commit comments

Comments
 (0)