Skip to content

Commit 8591d3a

Browse files
committed
Adding single call to push graphs solverDicts and estimateDicts
1 parent 6474d51 commit 8591d3a

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ Update solver and estimate data for a variable (variable can be from another gra
395395
"""
396396
function updateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
397397
if !exists(dfg, sourceVariable)
398-
error("Source variable '$(variable.label)' doesn't exist in the graph.")
398+
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
399399
end
400400
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sourceVariable.label)
401401
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "estimateDict", JSON2.write(sourceVariable.estimateDict))

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export label, data, id
3131

3232
# Services/AbstractDFG Exports
3333
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
34+
export updateGraphSolverData!
3435

3536
# Solver (IIF) Exports
3637
export VariableNodeData, PackedVariableNodeData, VariableEstimate

src/GraphsDFG/GraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export getAddHistory, getDescription, getLabelDict
1313
export addVariable!, addFactor!
1414
export ls, lsf, getVariables, getFactors, getVariableIds, getFactorIds
1515
export getVariable, getFactor
16-
export updateVariable!, updateFactor!
16+
export updateVariable!, updateFactor!, updateVariableSolverData!
1717
export deleteVariable!, deleteFactor!
1818
export getAdjacencyMatrix
1919
export getNeighbors

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ function updateVariable!(dfg::GraphsDFG, variable::DFGVariable)::DFGVariable
164164
return variable
165165
end
166166

167+
"""
168+
$(SIGNATURES)
169+
Update solver and estimate data for a variable (variable can be from another graph).
170+
"""
171+
function updateVariableSolverData!(dfg::GraphsDFG, sourceVariable::DFGVariable)::DFGVariable
172+
if !haskey(dfg.labelDict, sourceVariable.label)
173+
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
174+
end
175+
dfg.g.vertices[dfg.labelDict[variable.label]].dfgNode.estimateDict = deepcopy(variable.estimateDict)
176+
dfg.g.vertices[dfg.labelDict[variable.label]].dfgNode.solverDataDict = deepcopy(variable.solverDataDict)
177+
return sourceVariable
178+
end
179+
167180
"""
168181
$(SIGNATURES)
169182
Update a complete DFGFactor in the DFG.

src/services/AbstractDFG.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{
6767
return nothing
6868
end
6969

70+
"""
71+
$(SIGNATURES)
72+
Common function to update all solver data and estimates from one graph to another.
73+
This should be used to push local solve data back into a cloud graph, for example.
74+
"""
75+
function updateGraphSolverData!(sourceDFG::G, destDFG::H, varSyms::Vector{Symbol})::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
76+
# Update all variables in the destination
77+
# (For now... we may change this soon)
78+
for variableId in varSyms
79+
updateVariableSolverData!(destDFG, getVariable(sourceDFG, variableId))
80+
end
81+
end
82+
7083
## Utility functions for getting type names and modules (from IncrementalInference)
7184
function _getmodule(t::T) where T
7285
T.name.module

test/HexagonalCloud.jl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Revise
1+
# using Revise
22
using Neo4j # So that DFG initializes the database driver.
33
using RoME
44
using DistributedFactorGraphs
@@ -14,13 +14,10 @@ cloudFg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
1414
IncrementalInference.rebuildFactorMetadata!,
1515
solverParams=SolverParams())
1616
# cloudFg = GraphsDFG{SolverParams}(params=SolverParams())
17-
# cloudFg = GraphsDFG{SolverParams}(params=SolverParams())
1817
clearSession!!(cloudFg)
19-
# cloudFg = initfg()
2018

2119
# Add the first pose :x0
2220
x0 = addVariable!(cloudFg, :x0, Pose2)
23-
IncrementalInference.compareVariable(x0, getVariable(cloudFg, :x0))
2421

2522
# Add at a fixed location PriorPose2 to pin :x0 to a starting location (10,10, pi/4)
2623
prior = addFactor!(cloudFg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) )
@@ -44,30 +41,15 @@ DistributedFactorGraphs._copyIntoGraph!(cloudFg, localFg, union(getVariableIds(c
4441
# Show it
4542
toDotFile(localFg, "/tmp/localfg.dot")
4643

47-
# Alrighty! At this point, we should be able to solve locally...
48-
# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling
49-
# Can do with graph too!
50-
# tree, smt, hist = solveTree!(localFg)
51-
52-
# wipeBuildNewTree!(localFg)
53-
tree, smt, hist = solveTree!(localFg, tree) # Recycle
54-
# batchSolve!(localFg, drawpdf=true, show=true)
55-
# Erm, whut? Error = mcmcIterationIDs -- unaccounted variables
56-
57-
# Trying new method.
58-
# tree, smtasks = batchSolve!(localFg, treeinit=true, drawpdf=true, show=true,
59-
# returntasks=true, limititers=50,
60-
# upsolve=true, downsolve=true )
44+
tree, smtasks = batchSolve!(localFg, treeinit=true, drawpdf=false, show=false,
45+
returntasks=true, limititers=50,
46+
upsolve=true, downsolve=true )
6147

6248
# Testing writing estimates
6349
for variable in getVariables(localFg)
6450
means = mean(getData(variable).val, dims=2)[:]
6551
variable.estimateDict[:default] = Dict{Symbol, VariableEstimate}(:Mean => VariableEstimate(:default, :Mean, means, now()))
6652
end
6753

68-
x0 = getVariable(localFg, :x0)
69-
data = getData(x0)
70-
# Update back to cloud.
71-
for variable in getVariables(localFg)
72-
updateVariableSolverData!(cloudFg, variable)
73-
end
54+
# Push updates back to cloud.
55+
updateGraphSolverData!(localFg, cloudFg, ls(localFg))

0 commit comments

Comments
 (0)