Skip to content

Commit

Permalink
Merge pull request #670 from JuliaRobotics/21Q1/maint/deprmaxparallel
Browse files Browse the repository at this point in the history
some cleanup and depr maxparallel -> .maxincidence
  • Loading branch information
dehann authored Jan 6, 2021
2 parents 69ff966 + 4e35ac9 commit 7ac6d16
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Caesar"
uuid = "62eebf14-49bc-5f46-9df9-f7b7ef379406"
keywords = ["SLAM", "state-estimation", "MM-iSAM", "MM-iSAMv2", "inference", "robotics", "ROS"]
desc = "Non-Gaussian simultaneous localization and mapping"
version = "0.7.1"
version = "0.8.0"

[deps]
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
Expand Down Expand Up @@ -54,7 +54,7 @@ FFTW = "1"
FileIO = "1"
ImageCore = "0.7, 0.8, 0.9"
ImageMagick = "0.7, 1.0, 1.1"
IncrementalInference = "0.16, 0.17, 0.18, 0.19"
IncrementalInference = "0.20.1"
JLD2 = "0.1, 0.2, 0.3"
JSON = "0.18, 0.19, 0.20, 0.21, 0.22, 0.23"
JSON2 = "0.3, 0.4"
Expand All @@ -64,7 +64,7 @@ Optim = "1"
ProgressMeter = "0.9, 1"
Reexport = "0.2, 1.0"
Requires = "0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 1"
RoME = "0.9, 0.10, 0.11"
RoME = "0.10, 0.11, 0.12"
Rotations = "0.13, 1"
TensorCast = "0.2, 0.3"
TimeZones = "1.3.1, 1.4"
Expand Down
12 changes: 6 additions & 6 deletions docs/src/concepts/adding_variables_factors.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ In a trivial example of Pose2:
All factors inherit from one of the following types, depending on their function:
* AbstractPrior: AbstractPrior are priors (unary factors) that provide an absolute constraint for a single variable. A simple example of this is an absolute GPS prior, or equivalently a (0, 0, 0) starting location in a [`Pose2`](@ref) scenario.
* Requires: A getSample function
* AbstractRelativeFactorMinimize: AbstractRelativeFactorMinimize are relative factors that introduce an algebraic relationship between two or more variables. A simple example of this is an odometry factor between two pose variables, or a range factor indicating the range between a pose and another variable.
* AbstractRelativeMinimize: AbstractRelativeMinimize are relative factors that introduce an algebraic relationship between two or more variables. A simple example of this is an odometry factor between two pose variables, or a range factor indicating the range between a pose and another variable.
* Requires: A getSample function and a residual function definition
* The minimize suffix specifies that the residual function of this factor will be enforced by numerical minimization (find me the minimum of this function)
* AbstractRelativeFactor: AbstractRelativeFactor are relative factors that introduce algebraic relationships between two or more variables. They are the same as AbstractRelativeFactorMinimize, however they use root finding to find the zero crossings (rather than numerical minimization).
* AbstractRelativeRoots: AbstractRelativeRoots are relative factors that introduce algebraic relationships between two or more variables. They are the same as AbstractRelativeMinimize, however they use root finding to find the zero crossings (rather than numerical minimization).
* Requires: A getSample function and a residual function definition

How do you decide which to use?
* If you are creating factors for world-frame information that will be tied to a single variable, inherit from AbstractPrior
* GPS coordinates should be priors
* If you are creating factors for local-frame relationships between variables, inherit from AbstractRelativeFactorMinimize
* If you are creating factors for local-frame relationships between variables, inherit from AbstractRelativeMinimize
* Odometry and bearing deltas should be introduced as pairwise factors and should be local frame
TBD: sUsers **should** start with AbstractRelativeFactorMinimize, discuss why and when they should promote their factors to AbstractRelativeFactor.
TBD: sUsers **should** start with AbstractRelativeMinimize, discuss why and when they should promote their factors to AbstractRelativeRoots.

> Note: AbstractRelativeFactorMinimize does not imply that the overall inference algorithm only minimizes an objective function. The Multi-model iSAM algorithm is built around fixed-point analysis. Minimization is used here to locally enforce the residual function.
> Note: AbstractRelativeMinimize does not imply that the overall inference algorithm only minimizes an objective function. The Multi-model iSAM algorithm is built around fixed-point analysis. Minimization is used here to locally enforce the residual function.
What you need to build in the new factor:
* A struct for the factor itself
Expand All @@ -131,7 +131,7 @@ AbstractRelativeRoots
### Pose2Point2BearingRange Struct

```julia
mutable struct Pose2Point2BearingRange{B <: IIF.SamplableBelief, R <: IIF.SamplableBelief} <: IncrementalInference.AbstractRelativeFactor
mutable struct Pose2Point2BearingRange{B <: IIF.SamplableBelief, R <: IIF.SamplableBelief} <: IncrementalInference.AbstractRelativeRoots
bearing::B
range::R
Pose2Point2BearingRange{B,R}() where {B,R} = new{B,R}()
Expand Down
6 changes: 3 additions & 3 deletions docs/src/concepts/available_varfacs.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ You can check for the latest factor types by running the following in your termi
```julia
using RoME, Caesar
println("- Singletons (priors): ")
println.(sort(string.(subtypes(IncrementalInference.AbstractPrior))));
println.(sort(string.(subtypes(IIF.AbstractPrior))));
println("- Pairwise (variable constraints): ")
println.(sort(string.(subtypes(IncrementalInference.AbstractRelativeFactor))));
println.(sort(string.(subtypes(IIF.AbstractRelativeRoots))));
println("- Pairwise (variable minimization constraints): ")
println.(sort(string.(subtypes(IncrementalInference.AbstractRelativeFactorMinimize))));
println.(sort(string.(subtypes(IIF.AbstractRelativeMinimize))));
```

### Priors (Absolute Data)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/basic_definingfactors.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Prior(t::T) where {T <: SamplableBelief} = Prior{T}(t)
# sampling function
getSample(s::Prior, N::Int=1) = (reshape(rand(s.z,N),1,:), )

struct LinearOffset{T} <: IncrementalInference.AbstractRelativeFactor where T <: SamplableBelief
struct LinearOffset{T <: SamplableBelief} <: IncrementalInference.AbstractRelativeRoots
z::T
end
getSample(s::LinearOffset, N::Int=1) = (reshape(rand(s.z,N),1,:), )
Expand Down
3 changes: 3 additions & 0 deletions docs/src/examples/interm_dynpose.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ getSample(dp2v::DynPoint2VelocityPrior, N::Int=1) = (rand(dp2v.z,N), )

### `DynPoint2DynPoint2` (preintegration)

!!! warning
`::IIF.FactorMetadata` is being refactored and improved. Some of the content below is out of date. See IIF #1025 for details. (1Q2021)

The basic idea is that change in position is composed of three components (originating from double integration of Newton's second law):

![deltapositionplus](https://user-images.githubusercontent.com/6412556/40951449-05bdfed8-6845-11e8-8c4f-31fd92523819.gif)
Expand Down
14 changes: 5 additions & 9 deletions docs/src/principles/bayestreePrinciples.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ fg = generateCanonicalFG_Kaess()
# ...

## build the tree
tree = resetBuildTree!(fg)
tree = buildTreeReset!(fg)
```

The temporary values are `reset` from the distributed factor graph object `fg<:AbstractDFG` and a new tree is constructed. This `resetBuildTree!` call can be repeated as many times the user desires and results should be consistent for the same factor graph structure (regardless of numerical values contained within).
The temporary values are `reset` from the distributed factor graph object `fg<:AbstractDFG` and a new tree is constructed. This `buildTreeReset!` call can be repeated as many times the user desires and results should be consistent for the same factor graph structure (regardless of numerical values contained within).

```@docs
resetBuildTree!
buildTreeReset!
```

## Variable Ordering
Expand All @@ -60,11 +60,7 @@ vo = [:x1; :l3; :x2; ...]

And then reset the factor graph and build a new tree
```julia
resetBuildTreeFromOrder!(fg, vo)
```

```@docs
resetBuildTreeFromOrder!
buildTreeReset!(fg, vo)
```

!!! note
Expand All @@ -87,7 +83,7 @@ tree, smt, hist = solveTree!(fg)

### Get the Elimination Order Used

The solver internally uses [`resetBuildTree!`](@ref) which sometimes requires the user extract the variable elimination order after the fact. This can be done with:
The solver internally uses [`buildTreeReset!`](@ref) which sometimes requires the user extract the variable elimination order after the fact. This can be done with:
```@docs
getEliminationOrder
```
Expand Down
4 changes: 3 additions & 1 deletion examples/basic/quickBatchSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ factrs = setdiff(lsf(fg), lsf(fg, r"drt"))
ensureAllInitialized!(fg)

getSolverParams(fg).drawtree = true
@time solveTree!(fg, maxparallel=1000);
getSolverParams(fg).maxincidence = 1000

@time solveTree!(fg);

savepath = splitpath(ARGS[1])
savename = split(savepath[end], '.')[1]
Expand Down
3 changes: 2 additions & 1 deletion examples/marine/asv/kayaks/PointSource_script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ writeGraphPdf(fg,viewerapp="", engine="neato", filepath = "/tmp/test.pdf")
# getSolverParams(fg).drawtree = true
getSolverParams(fg).limititers=500
#getSolverParams(fg).showtree = true
getSolverParams(fg).maxincidence = 200

tree, smt, hist = solveTree!(fg,maxparallel=200)
tree, smt, hist = solveTree!(fg)

# Some Debuggging
# @time L1 = approxConv(fg,:l1x1x2x3x4x5x6x7x8f1,:l1)
Expand Down
5 changes: 3 additions & 2 deletions examples/marine/asv/kayaks/dynsas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cfgFile = joinpath(ENV["HOME"],"data","sas","SAS2D.yaml")
cfgd=loadConfigFile(cfgFile)

fg = initfg();
getSolverParams(fg).maxincidence = 400
beacon = :l1
addVariable!(fg, beacon, Point2 )
tree = emptyBayesTree();
Expand Down Expand Up @@ -124,9 +125,9 @@ while pose_counter < totalposes-2
setValKDE!(fg,lstpose,XXkde);

if sas_counter > 1
tree, smt, hist = solveTree!(fg,tree, maxparallel=400)
tree, smt, hist = solveTree!(fg,tree)
else
tree, smt, hist = solveTree!(fg, maxparallel=400)
tree, smt, hist = solveTree!(fg)
end

writeGraphPdf(fg,viewerapp="", engine="neato", filepath=scriptHeader*"fg.pdf")
Expand Down
8 changes: 5 additions & 3 deletions examples/marine/asv/kayaks/dynsas_ljscript.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ function main(expID::String, datastart::Int, dataend::Int, fgap::Int, gps_gap::I
cfgd=loadConfigFile(cfgFile)

fg = initfg();
getSolverParams(fg).maxincidence = 1000

beacon = :l1
addVariable!(fg, beacon, Point2 )
tree = emptyBayesTree();
tree = BayesTree();

pose_counter = 1
sas_counter = 1
Expand Down Expand Up @@ -114,9 +116,9 @@ function main(expID::String, datastart::Int, dataend::Int, fgap::Int, gps_gap::I
setValKDE!(fg,lstpose,XXkde);

if sas_counter > 1
tree, smt, hist = solveTree!(fg,tree, maxparallel=400)
tree, smt, hist = solveTree!(fg,tree)
else
tree, smt, hist = solveTree!(fg, maxparallel=400)
tree, smt, hist = solveTree!(fg)
end

writeGraphPdf(fg,viewerapp="", engine="neato", filepath=scriptHeader*"fg.pdf")
Expand Down
8 changes: 5 additions & 3 deletions examples/marine/asv/kayaks/dynsas_timed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ function main(expID::String, datastart::Int, dataend::Int, fgap::Int, gps_gap::I
cfgd=loadConfigFile(cfgFile)

fg = initfg();
getSolverParams(fg).maxincidence = 400

beacon = :l1
addVariable!(fg, beacon, Point2 )
tree = emptyBayesTree();
tree = BayesTree();

pose_counter = 1
sas_counter = 1
Expand Down Expand Up @@ -123,9 +125,9 @@ function main(expID::String, datastart::Int, dataend::Int, fgap::Int, gps_gap::I

println("Solving at SAS-F: $(sas_counter), Pos: $(pose_counter) \n");
if sas_counter > 1
@time tree, smt, hist = solveTree!(fg,tree, maxparallel=400)
@time tree, smt, hist = solveTree!(fg,tree)
else
@time tree, smt, hist = solveTree!(fg, maxparallel=400)
@time tree, smt, hist = solveTree!(fg)
end

# writeGraphPdf(fg,viewerapp="", engine="neato", filepath=scriptHeader*"fg.pdf")
Expand Down
6 changes: 3 additions & 3 deletions examples/marine/asv/kayaks/rangeOnlySLAM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ getSolverParams(fg).showtree = false
getSolverParams(fg).async = true
getSolverParams(fg).multiproc = true
getSolverParams(fg).downsolve = true
getSolverParams(fg).maxincidence = 100


tree, smt, hist = solveTree!(fg, maxparallel=100)
tree, smt, hist = solveTree!(fg)
drawTree(tree,filepath = "/tmp/test.pdf")
# fg2 = deepcopy(fg)
# tree, smt, hist = solveTree!(fg,tree,maxparallel=100)
# tree, smt, hist = solveTree!(fg,tree)

# plotSASDefault(fg,expID, posData,igt,datadir=allpaths[1],savedir=scriptHeader*"SASdefault.pdf")
plotSASDefault(fg,expID, posData,igt,dposData, datadir=allpaths[1], savedir="/tmp/caesar/test.pdf")
Expand Down
12 changes: 7 additions & 5 deletions examples/marine/asv/kayaks/rangeOnlySLAM_dbg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ getSolverParams(fg).async = true
getSolverParams(fg).multiproc = false
getSolverParams(fg).upsolve = true
getSolverParams(fg).downsolve = false
getSolverParams(fg).maxincidence = 100


# writeGraphPdf(fg, show=true)

ensureAllInitialized!(fg)

tree, smt, hist = solveTree!(fg, maxparallel=100)
tree, smt, hist = solveTree!(fg0)
drawTree(tree,filepath = "/tmp/caesar/bt.pdf", show=true, imgs=false)
# fg2 = deepcopy(fg)
# tree, smt, hist = solveTree!(fg,tree,maxparallel=100)
# tree, smt, hist = solveTree!(fg,tree)

# plotSASDefault(fg,expID, posData, igt, dposData, datadir=allpaths[1],savedir="/tmp/caesar/plotsas.pdf");
# # plotSASDefault(fg,expID, posData,igt,dposData, datadir=allpaths[1], savedir="/tmp/caesar/test.pdf")
Expand Down Expand Up @@ -312,21 +313,22 @@ getSolverParams(fg).async = true
getSolverParams(fg).multiproc = false
getSolverParams(fg).upsolve = true
getSolverParams(fg).downsolve = false
getSolverParams(fg).maxincidence = 100


# writeGraphPdf(fg, show=true)

# ensureAllInitialized!(fg)

tree, smt, hist = solveTree!(fg, maxparallel=100)
tree, smt, hist = solveTree!(fg)


plotKDE(fg, reverse(sortVarNested(ls(fg, r"x"))), levels=1)
plotKDE(fg, reverse(sortDFG(ls(fg, r"x"))), levels=1)

getSolverParams(fg).upsolve = false
getSolverParams(fg).downsolve = true

tree, smt, hist = solveTree!(fg, maxparallel=100)
tree, smt, hist = solveTree!(fg)



Expand Down
5 changes: 3 additions & 2 deletions examples/marine/asv/kayaks/rangeOnlySLAM_ljscript.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ function main(expID::String, rangegap::Int, wstart::Int, wend::Int, trialID::Int
getSolverParams(fg).drawtree = false
getSolverParams(fg).showtree = false
getSolverParams(fg).limititers=500
getSolverParams(fg).maxincidence = 400


tree, smt, hist = solveTree!(fg, maxparallel=400)
tree, smt, hist = solveTree!(fg, maxparallel=400)
tree, smt, hist = solveTree!(fg)
tree, smt, hist = solveTree!(fg)
drawTree(tree, filepath=scriptHeader*"bt.pdf")

plotSASDefault(fg,expID, posData,igt,dposData,datadir=allpaths[1],savedir=scriptHeader*"SASdefault.pdf")
Expand Down
5 changes: 3 additions & 2 deletions examples/marine/asv/kayaks/rangeOnlySLAM_timed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ function main(expID::String, rangegap::Int, wstart::Int, wend::Int, trialID::Int
getSolverParams(fg).drawtree = false
getSolverParams(fg).showtree = false
getSolverParams(fg).limititers=500
getSolverParams(fg).maxincidence = 400


tree, smt, hist = solveTree!(fg, maxparallel=400)
tree, smt, hist = solveTree!(fg)
println("Ended Script with $(rangecounter) range factors \n")

# tree, smt, hist = solveTree!(fg, maxparallel=400)
# tree, smt, hist = solveTree!(fg)
# drawTree(tree, filepath=scriptHeader*"bt.pdf")

# plotSASDefault(fg,expID, posData,igt,dposData,datadir=allpaths[1],savedir=scriptHeader*"SASdefault.pdf")
Expand Down
5 changes: 2 additions & 3 deletions examples/marine/asv/kayaks/testRangeOnlyOdo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ end
getSolverParams(fg).drawtree = true
getSolverParams(fg).showtree = false
getSolverParams(fg).dbg = true
getSolverParams(fg).maxincidence = 200


ensureAllInitialized!(fg)
tree, smt, hist = solveTree!(fg, maxparallel=200, recordcliqs=[:x19;:x169;:x166;:x134;:x171])
tree, smt, hist = solveTree!(fg, recordcliqs=[:x19;:x169;:x166;:x134;:x171])


fetchCliqTaskHistoryAll!(smt, hist)
Expand Down Expand Up @@ -137,8 +138,6 @@ Gadfly.plot(x=out,Geom.histogram,Coord.cartesian(xmin=0, xmax=100, ymin=0, ymax=

using RoMEPlotting

# tree = wipeBuildNewTree!(fg, maxparallel=200)
# spyCliqMat(tree, :x169)

drawTree(tree, show=true)

Expand Down
3 changes: 2 additions & 1 deletion examples/marine/auv/Sandshark/LCM_SLAM_client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ end

dontMarginalizeVariablesAll!(fg)
setSolvable!(getVariable(fg, :drt_ref), 0)
tree, smt, hist = solveTree!(fg, maxparallel=1000)
getSolverParams(fg).maxincidence = 1000
tree, smt, hist = solveTree!(fg)

saveDFG(fg, joinpath(getLogPath(fg),"fg_batchsolve") )

Expand Down
3 changes: 2 additions & 1 deletion examples/marine/auv/Sandshark/SandsharkUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ end
# getSolverParams(dfg).qfl = dashboard[:SOLVESTRIDE]
# getSolverParams(dfg).isfixedlag = true
# getSolverParams(dfg).limitfixeddown = limitfixeddown
# getSolverParams(dfg).maxincidence = 1000
#
# # allow async process
# # getSolverParams(dfg).async = true
Expand Down Expand Up @@ -337,7 +338,7 @@ end
# dt_save1 = (time_ns()-t0)/1e9
# # constrain solve with the latest pose at the top
# # @show latestPose = intersect(getLastPoses(dfg, filterLabel=r"x\d", number=12), ls(dfg, r"x\d", solvable=1))[end]
# tree, smt, hist = solveTree!(dfg, tree, maxparallel=1000) # , variableConstraints=[latestPose;]
# tree, smt, hist = solveTree!(dfg, tree) # , variableConstraints=[latestPose;]
# dt_solve = (time_ns()-t0)/1e9
# !dbg ? nothing : saveDFG(dfg, joinpath(getLogPath(dfg), "fg_after_$(lasp)"))
#
Expand Down
6 changes: 4 additions & 2 deletions examples/marine/auv/Sandshark/Sandshark_script_pieces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ tree1 = wipeBuildNewTree!(fg1)
# getSolverParams(fg1).isfixedlag = true
# getSolverParams(fg1).qfl = 20

getSolverParams(fg1).maxincidence = 200

# first solve and initialization
getSolverParams(fg1).drawtree = true
# getSolverParams(fg).showtree = false
Expand All @@ -226,7 +228,7 @@ for STEP in 0:10:50
global storeLast

runEpochs!(fg1, epochs, STEP, index1, acousticRate=3)
poses = sortVarNested(ls(fg1, r"x"))
poses = sortDFG(ls(fg1, r"x"))

if STEP-laglength >= 0
@show poses[1], poses[end], poses[end-laglength]
Expand All @@ -239,7 +241,7 @@ for STEP in 0:10:50

drawGraph(fg1, filepath=joinpath(getSolverParams(fg1).logpath, "graphs", "fg_$(STEP)_.pdf"))
saveDFG(fg1, joinpath(getSolverParams(fg1).logpath, "graphs", "fg_$(STEP)_before"))
@time tree1, smt, hist = solveTree!(fg1, tree1, maxparallel=200)
@time tree1, smt, hist = solveTree!(fg1, tree1)
saveDFG(fg1, joinpath(getSolverParams(fg1).logpath, "graphs", "fg_$(STEP)_after"))

pla = drawPosesLandmarksAndOdo(fg1, ppbrDict, navkeys, X, Y, lblkeys, lblX, lblY)
Expand Down
Loading

0 comments on commit 7ac6d16

Please sign in to comment.