|
1 |
| -# add more julia processes |
2 |
| -using Distributed |
3 |
| -nprocs() < 4 ? addprocs(5-nprocs()) : nothing |
4 |
| - |
5 |
| -# tell Julia that you want to use these modules/namespaces |
| 1 | +using Revise |
6 | 2 | using Neo4j # So that DFG initializes the database driver.
|
7 | 3 | using RoME
|
8 | 4 | using DistributedFactorGraphs
|
9 |
| -## Inter-operating visualization packages for Caesar/RoME/IncrementalInference exist |
10 |
| -# using RoMEPlotting |
11 |
| - |
| 5 | +using Test |
12 | 6 |
|
13 | 7 | # start with an empty factor graph object
|
14 | 8 | # fg = initfg()
|
15 |
| -global cgDFG = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test", |
| 9 | +cloudFg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test", |
16 | 10 | "testUser", "testRobot", "testSession",
|
17 | 11 | nothing,
|
18 | 12 | nothing,
|
19 | 13 | IncrementalInference.decodePackedType,
|
20 |
| - solverParams=SolverParams(0, nothing, nothing, false, 0, false)) |
21 |
| -fg = cgDFG |
22 |
| -clearSession!!(fg) |
23 |
| -# fg = initfg() |
| 14 | + IncrementalInference.rebuildFactorMetadata!, |
| 15 | + solverParams=SolverParams()) |
| 16 | +clearSession!!(cloudFg) |
| 17 | +# cloudFg = initfg() |
24 | 18 |
|
25 | 19 | # Add the first pose :x0
|
26 |
| -addVariable!(fg, :x0, Pose2) |
| 20 | +x0 = addVariable!(cloudFg, :x0, Pose2) |
| 21 | +IncrementalInference.compareVariable(x0, getVariable(cloudFg, :x0)) |
27 | 22 |
|
28 | 23 | # Add at a fixed location PriorPose2 to pin :x0 to a starting location (10,10, pi/4)
|
29 |
| -prior = addFactor!(fg, [:x0], PriorPose2( MvNormal([10; 10; pi/6.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) ) |
30 |
| - |
31 |
| -# Drive around in a hexagon |
| 24 | +prior = addFactor!(cloudFg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) ) |
| 25 | +# retPrior = getFactor(cloudFg, :x0f1) |
| 26 | +# Do the check |
| 27 | +# IncrementalInference.compareFactor(prior, retPrior) |
| 28 | +# Testing |
| 29 | + |
| 30 | +# retPrior.data.fnc.cpt = prior.data.fnc.cpt |
| 31 | +# # This one |
| 32 | +# prior.data.fnc.cpt[1].factormetadata |
| 33 | +# deserialized: Any[Pose2(3, String[], (:Euclid, :Euclid, :Circular))] |
| 34 | +# vs. |
| 35 | +# original: Pose2[Pose2(3, String[], (:Euclid, :Euclid, :Circular))] |
| 36 | + |
| 37 | +# Drive around in a hexagon in the cloud |
32 | 38 | for i in 0:5
|
33 | 39 | psym = Symbol("x$i")
|
34 | 40 | nsym = Symbol("x$(i+1)")
|
35 |
| - addVariable!(fg, nsym, Pose2) |
| 41 | + addVariable!(cloudFg, nsym, Pose2) |
36 | 42 | pp = Pose2Pose2(MvNormal([10.0;0;pi/3], Matrix(Diagonal([0.1;0.1;0.1].^2))))
|
37 |
| - addFactor!(fg, [psym;nsym], pp ) |
| 43 | + addFactor!(cloudFg, [psym;nsym], pp ) |
38 | 44 | end
|
39 | 45 |
|
40 |
| -retPrior = getFactor(fg, :x0f1) |
41 |
| -IncrementalInference.compareFactor(prior, retPrior) |
| 46 | +# Right, let's copy it into local memory for solving... |
| 47 | +localFg = GraphsDFG{SolverParams}(params=SolverParams()) |
| 48 | +DistributedFactorGraphs._copyIntoGraph!(cloudFg, localFg, union(getVariableIds(fg), getFactorIds(fg)), true) |
| 49 | +# Some checks |
| 50 | +@test getVariableIds(localFg) == getVariableIds(cloudFg) |
| 51 | +@test getFactorIds(localFg) == getFactorIds(cloudFg) |
| 52 | +@test isFullyConnected(localFg) |
| 53 | +# Show it |
| 54 | +toDotFile(localFg, "/tmp/localfg.dot") |
| 55 | + |
| 56 | +# Alrighty! At this point, we should be able to solve locally... |
| 57 | +# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling |
| 58 | +batchSolve!(localFg, drawpdf=true, show=true) |
| 59 | +# Erm, whut? Error = mcmcIterationIDs -- unaccounted variables |
42 | 60 |
|
43 |
| -# for factId in getFactorIds(fg) |
44 |
| -# @show getFactor(fg, factId) |
45 |
| -# end |
| 61 | +#### WIP and general debugging |
46 | 62 |
|
47 |
| -# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling |
48 |
| -batchSolve!(fg, drawpdf=true, show=true) |
| 63 | +# Testing with GenericMarginal |
| 64 | +# This will not work because GenericMarginal *shouldn't* really be persisted. |
| 65 | +# That would mean we're decomposing the cloud graph... |
| 66 | +# genmarg = GenericMarginal() |
| 67 | +# Xi = [getVariable(fg, :x0)] |
| 68 | +# addFactor!(fg, Xi, genmarg, autoinit=false) |
49 | 69 |
|
50 | 70 | # For Juno/Jupyter style use
|
51 |
| -pl = drawPoses(fg, meanmax=:mean) |
| 71 | +pl = drawPoses(localFg, meanmax=:mean) |
52 | 72 | plotPose(fg, :x6)
|
53 | 73 | # For scripting use-cases you can export the image
|
54 | 74 | Gadfly.draw(Gadfly.PDF("/tmp/test1.pdf", 20cm, 10cm),pl) # or PNG(...)
|
|
0 commit comments