Skip to content

Commit 2e90242

Browse files
committed
Renaming id(...) to internalId(...) so it's not used. Cleaning up estimateDict.
1 parent 64c0370 commit 2e90242

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
255255
# props["label"] = Symbol(variable.label)
256256
timestamp = DateTime(props["timestamp"])
257257
tags = JSON2.read(props["tags"], Vector{Symbol})
258-
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, VariableEstimate})
258+
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
259259
smallData = nothing
260260
smallData = JSON2.read(props["smallData"], Dict{String, String})
261261

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariab
2525
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
2626

2727
export DFGVariable
28-
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, id, smallData, bigData
28+
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, internalId, smallData, bigData
2929
export setSolverData
3030
export label, data, id
3131

src/FileDFG/services/FileDFG.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function _unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable wh
1616
label = Symbol(packedProps["label"])
1717
timestamp = DateTime(packedProps["timestamp"])
1818
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
19-
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, VariableEstimate})
19+
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
2020
smallData = nothing
2121
smallData = JSON2.read(packedProps["smallData"], Dict{String, String})
2222

@@ -137,10 +137,7 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
137137
end
138138
end
139139

140-
function loadDFG(folder::String,
141-
iifModule,
142-
dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
143-
#
140+
function loadDFG(folder::String, iifModule, dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
144141
variables = DFGVariable[]
145142
factors = DFGFactor[]
146143
varFolder = "$folder/variables"

src/entities/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ end
4949

5050
label(f::F) where F <: DFGFactor = f.label
5151
data(f::F) where F <: DFGFactor = f.data
52-
id(f::F) where F <: DFGFactor = f._internalId
52+
internalId(f::F) where F <: DFGFactor = f._internalId
5353

5454
# Simply for convenience - don't export
5555
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}

src/entities/DFGVariable.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ mutable struct PackedVariableNodeData
7272
end
7373

7474
struct VariableEstimate
75-
estimate::Vector{Float64}
75+
solverKey::Symbol
7676
type::Symbol
77-
key::Symbol
77+
estimate::Vector{Float64}
7878
lastUpdatedTimestamp::DateTime
79+
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}, lastUpdatedTimestamp::DateTime=now()) = new(solverKey, type, estimate, lastUpdatedTimestamp)
7980
end
8081

8182
"""
@@ -86,14 +87,14 @@ mutable struct DFGVariable <: DFGNode
8687
label::Symbol
8788
timestamp::DateTime
8889
tags::Vector{Symbol}
89-
estimateDict::Dict{Symbol, VariableEstimate}
90+
estimateDict::Dict{Symbol, Dict{Symbol, VariableEstimate}}
9091
solverDataDict::Dict{Symbol, VariableNodeData}
9192
smallData::Dict{String, String}
9293
bigData::Any
9394
ready::Int
9495
backendset::Int
9596
_internalId::Int64
96-
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
97+
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
9798
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, 0)
9899
end
99100

@@ -103,12 +104,11 @@ timestamp(v::DFGVariable) = v.timestamp
103104
tags(v::DFGVariable) = v.tags
104105
estimates(v::DFGVariable) = v.estimateDict
105106
estimate(v::DFGVariable, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
106-
#solverData(v::DFGVariable) = haskey(v.solverDataDict, :default) ? v.solverDataDict[:default] : nothing
107107
solverData(v::DFGVariable, key::Symbol=:default) = haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
108108
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
109109
setSolverData(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
110110
solverDataDict(v::DFGVariable) = v.solverDataDict
111-
id(v::DFGVariable) = v._internalId
111+
internalId(v::DFGVariable) = v._internalId
112112
# Todo: Complete this.
113113
smallData(v::DFGVariable) = v.smallData
114114
bigData(v::DFGVariable) = v.bigData

test/FileDFG.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22
using DistributedFactorGraphs
33
using IncrementalInference, RoME
4+
using Dates
45

56
# Make a simple graph
67
dfg = GraphsDFG{SolverParams}(params=SolverParams())
@@ -17,7 +18,7 @@ for i in 0:5
1718
addFactor!(dfg, [psym;nsym], pp )
1819
end
1920

20-
# Save it
21+
# Save with no solution
2122
saveFolder = "/tmp/fileDFG"
2223
saveDFG(dfg, saveFolder)
2324
@test readdir("$saveFolder/variables") == ["x0.json", "x1.json", "x2.json", "x3.json", "x4.json", "x5.json", "x6.json"]
@@ -27,4 +28,27 @@ retDFG = loadDFG(saveFolder, IncrementalInference)
2728
@test symdiff(ls(dfg), ls(dfg)) == []
2829
@test symdiff(lsf(dfg), lsf(retDFG)) == []
2930

31+
# Now solve the graph and update the solver results
32+
# TODO: When PPE estimates are available, make the update happen here
33+
for variable in getVariables(dfg)
34+
variable.estimateDict[:default] = Dict{Symbol, VariableEstimate}(:MAP => VariableEstimate(:default, :MAP, round.(rand(3)*1000), now()))
35+
end
36+
saveDFG(dfg, saveFolder)
37+
retDFG = loadDFG(saveFolder, IncrementalInference)
38+
for retVar in getVariables(retDFG)
39+
origVar = getVariable(dfg, retVar.label).estimateDict[:default][:MAP]
40+
@test retVar.estimateDict[:default][:MAP].estimate == origVar.estimate
41+
@test retVar.estimateDict[:default][:MAP].type == origVar.type
42+
@test retVar.estimateDict[:default][:MAP].solverKey == origVar.solverKey
43+
end
44+
45+
# Now saving solverDataDict
46+
tree, smtasks = batchSolve!(dfg, treeinit=true, drawpdf=false, show=false,
47+
returntasks=true, limititers=50,
48+
upsolve=true, downsolve=true )
49+
saveDFG(dfg, saveFolder)
50+
retDFG = loadDFG(saveFolder, IncrementalInference)
51+
x0 = getVariable(dfg, :x0)
52+
x0ret = getVariable(retDFG, :x0)
53+
solverData(x0) == solverData(x0ret)
3054
# Success!

test/interfaceTests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ end
8787
@test solverData(v1) === v1.solverDataDict[:default]
8888
@test solverData(v1, :default) === v1.solverDataDict[:default]
8989
@test solverDataDict(v1) == v1.solverDataDict
90-
@test id(v1) == v1._internalId
90+
@test internalId(v1) == v1._internalId
9191

9292
@test label(f1) == f1.label
9393
@test data(f1) == f1.data
94-
@test id(f1) == f1._internalId
94+
@test internalId(f1) == f1._internalId
9595
end
9696

9797
# Connectivity test

0 commit comments

Comments
 (0)