Skip to content

Commit 6474d51

Browse files
committed
Function to update only solverDicts and estimates back to cloud.
1 parent 2e90242 commit 6474d51

File tree

3 files changed

+33
-63
lines changed

3 files changed

+33
-63
lines changed

src/CloudGraphsDFG/CloudGraphsDFG.jl

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

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,20 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
389389
return variable
390390
end
391391

392+
"""
393+
$(SIGNATURES)
394+
Update solver and estimate data for a variable (variable can be from another graph).
395+
"""
396+
function updateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
397+
if !exists(dfg, sourceVariable)
398+
error("Source variable '$(variable.label)' doesn't exist in the graph.")
399+
end
400+
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sourceVariable.label)
401+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "estimateDict", JSON2.write(sourceVariable.estimateDict))
402+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "solverDataDict", JSON2.write(Dict(keys(sourceVariable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(sourceVariable.solverDataDict)))))
403+
return sourceVariable
404+
end
405+
392406
"""
393407
$(SIGNATURES)
394408
Update a complete DFGFactor in the DFG.

test/HexagonalCloud.jl

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Revise
22
using Neo4j # So that DFG initializes the database driver.
33
using RoME
44
using DistributedFactorGraphs
5-
using Test
5+
using Test, Dates
66

77
# start with an empty factor graph object
88
# fg = initfg()
@@ -24,17 +24,6 @@ IncrementalInference.compareVariable(x0, getVariable(cloudFg, :x0))
2424

2525
# Add at a fixed location PriorPose2 to pin :x0 to a starting location (10,10, pi/4)
2626
prior = addFactor!(cloudFg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) )
27-
# retPrior = getFactor(cloudFg, :x0f1)
28-
# Do the check
29-
# IncrementalInference.compareFactor(prior, retPrior)
30-
# Testing
31-
32-
# retPrior.data.fnc.cpt = prior.data.fnc.cpt
33-
# # This one
34-
# prior.data.fnc.cpt[1].factormetadata
35-
# deserialized: Any[Pose2(3, String[], (:Euclid, :Euclid, :Circular))]
36-
# vs.
37-
# original: Pose2[Pose2(3, String[], (:Euclid, :Euclid, :Circular))]
3827

3928
# Drive around in a hexagon in the cloud
4029
for i in 0:5
@@ -58,60 +47,27 @@ toDotFile(localFg, "/tmp/localfg.dot")
5847
# Alrighty! At this point, we should be able to solve locally...
5948
# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling
6049
# Can do with graph too!
61-
tree, smt, hist = solveTree!(localFg)
50+
# tree, smt, hist = solveTree!(localFg)
6251

63-
wipeBuildNewTree!(localFg)
52+
# wipeBuildNewTree!(localFg)
6453
tree, smt, hist = solveTree!(localFg, tree) # Recycle
6554
# batchSolve!(localFg, drawpdf=true, show=true)
6655
# Erm, whut? Error = mcmcIterationIDs -- unaccounted variables
6756

6857
# Trying new method.
69-
tree, smtasks = batchSolve!(localFg, treeinit=true, drawpdf=true, show=true,
70-
returntasks=true, limititers=50,
71-
upsolve=true, downsolve=true )
72-
73-
#### WIP and general debugging
74-
75-
# Testing with GenericMarginal
76-
# This will not work because GenericMarginal *shouldn't* really be persisted.
77-
# That would mean we're decomposing the cloud graph...
78-
# genmarg = GenericMarginal()
79-
# Xi = [getVariable(fg, :x0)]
80-
# addFactor!(fg, Xi, genmarg, autoinit=false)
81-
82-
# For Juno/Jupyter style use
83-
pl = drawPoses(localFg, meanmax=:mean)
84-
plotPose(fg, :x6)
85-
# For scripting use-cases you can export the image
86-
Gadfly.draw(Gadfly.PDF("/tmp/test1.pdf", 20cm, 10cm),pl) # or PNG(...)
87-
88-
89-
# Add landmarks with Bearing range measurements
90-
addVariable!(fg, :l1, Point2, labels=["LANDMARK"])
91-
p2br = Pose2Point2BearingRange(Normal(0,0.1),Normal(20.0,1.0))
92-
addFactor!(fg, [:x0; :l1], p2br )
93-
94-
95-
# Initialize :l1 numerical values but do not rerun solver
96-
ensureAllInitialized!(fg)
97-
pl = drawPosesLandms(fg)
98-
Gadfly.draw(Gadfly.PDF("/tmp/test2.pdf", 20cm, 10cm),pl) # or PNG(...)
99-
100-
101-
# Add landmarks with Bearing range measurements
102-
p2br2 = Pose2Point2BearingRange(Normal(0,0.1),Normal(20.0,1.0))
103-
addFactor!(fg, [:x6; :l1], p2br2 )
104-
105-
106-
# solve
107-
batchSolve!(fg, drawpdf=true)
108-
109-
110-
# redraw
111-
pl = drawPosesLandms(fg, meanmax=:mean)
112-
Gadfly.draw(Gadfly.PDF("/tmp/test3.pdf", 20cm, 10cm),pl) # or PNG(...)
113-
114-
115-
58+
# tree, smtasks = batchSolve!(localFg, treeinit=true, drawpdf=true, show=true,
59+
# returntasks=true, limititers=50,
60+
# upsolve=true, downsolve=true )
61+
62+
# Testing writing estimates
63+
for variable in getVariables(localFg)
64+
means = mean(getData(variable).val, dims=2)[:]
65+
variable.estimateDict[:default] = Dict{Symbol, VariableEstimate}(:Mean => VariableEstimate(:default, :Mean, means, now()))
66+
end
11667

117-
#
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

0 commit comments

Comments
 (0)