DistributedFactorGraphs Types
DistributedFactorGraphs Module
DistributedFactorGraphs.DistributedFactorGraphs — ModuleDistributedFactorGraphs.jl provides a flexible factor graph API for use in the Caesar.jl ecosystem.
The package supplies:
- A standardized API for interacting with factor graphs
- Implementations of the API for in-memory and database-driven operation
- Visualization extensions to validate the underlying graph
Types
Abstract DFG
DistributedFactorGraphs.MetadataTypes — TypeTypes valid for small data.
DistributedFactorGraphs.AbstractDFG — Typeabstract type AbstractDFG{V<:AbstractGraphVariable, F<:AbstractGraphFactor}Abstract parent struct for a DFG graph.
DistributedFactorGraphs.AbstractDFGParams — Typeabstract type AbstractDFGParamsAbstract parent struct for solver parameters.
DistributedFactorGraphs.AbstractGraphFactor — Typeabstract type AbstractGraphFactor <: AbstractGraphNodeAn abstract DFG factor.
DistributedFactorGraphs.AbstractGraphNode — Typeabstract type AbstractGraphNodeAbstract parent struct for DFG variables and factors.
DistributedFactorGraphs.AbstractGraphVariable — Typeabstract type AbstractGraphVariable <: AbstractGraphNodeAn abstract DFG variable.
DistributedFactorGraphs.NoSolverParams — Typestruct NoSolverParams <: AbstractDFGParamsEmpty structure for solver parameters.
Summary DFG
DFG Variable Nodes
DistributedFactorGraphs.MeanMaxPPE — Typestruct MeanMaxPPE <: AbstractPointParametricEstData container to store Parameteric Point Estimate (PPE) for mean and max.
DistributedFactorGraphs.PackedState — Typemutable struct PackedStatePacked State structure for serializing DFGVariables.
Fields:
id::Union{Nothing, Base.UUID}vecval::Vector{Float64}dimval::Int64vecbw::Vector{Float64}dimbw::Int64BayesNetOutVertIDs::Vector{Symbol}dimIDs::Vector{Int64}dims::Int64eliminated::BoolBayesNetVertID::Symbolseparator::Vector{Symbol}variableType::Stringinitialized::BoolinfoPerCoord::Vector{Float64}ismargin::Booldontmargin::BoolsolveInProgress::Int64solvedCount::Int64solveKey::Symbolcovar::Vector{Float64}_version::VersionNumber
DistributedFactorGraphs.State — Typemutable struct State{T<:AbstractStateType, P, N}Data container for solver-specific data.
T: Variable type, such as Position1, or RoME.Pose2, etc. P: Variable point type, the type of the manifold point. N: Manifold dimension. Fields:
id::Union{Nothing, Base.UUID}: Globally unique identifier.
val::Vector: Vector of on-manifold points used to represent a ManifoldKernelDensity (or parametric) belief.
bw::Matrix{Float64}: Common kernel bandwith parameter used with ManifoldKernelDensity, see fieldcovarfor the parametric covariance.
covar::Array{StaticArraysCore.SMatrix{N, N, Float64}, 1} where N: Parametric (Gaussian) covariance.BayesNetOutVertIDs::Vector{Symbol}dimIDs::Vector{Int64}dims::Int64eliminated::Bool: Flag used by junction (Bayes) tree construction algorithm to know whether this variable has yet been included in the tree construction.
BayesNetVertID::Symbolseparator::Vector{Symbol}initialized::Bool: False if initial numerical values are not yet available or stored values are not ready for further processing yet.
infoPerCoord::Vector{Float64}: Stores the amount information (per measurement dimension) captured in each coordinate dimension.
ismargin::Bool: Should this variable solveKey be treated as marginalized in inference computations.
dontmargin::Bool: Should this variable solveKey always be kept fluid and not be automatically marginalized.
solveInProgress::Int64: Convenience flag on whether a solver is currently busy working on this variable solveKey.
solvedCount::Int64: How many times has a solver updated this variable solveKey estimte.
solveKey::Symbol: solveKey identifier associated with this State object.
events::Dict{Symbol, Base.GenericCondition{ReentrantLock}}: Future proofing field for when more multithreading operations on graph nodes are implemented, these conditions are meant to be used for atomic write transactions to this VND.
DistributedFactorGraphs.VariableCompute — Typestruct VariableCompute{T<:AbstractStateType, P, N} <: AbstractGraphVariableComplete variable structure for a DistributedFactorGraph variable.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the variablelabel::Symbol: Variable label, e.g. :x1. Accessor:getLabeltimestamp::TimeZones.ZonedDateTime: Variable timestamp. Accessors:getTimestamp,setTimestampnstime::Dates.Nanosecond: Nanoseconds since a user-understood epoch (i.e unix epoch, robot boot time, etc.)tags::Set{Symbol}: Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK]. Accessors:getTags,mergeTags!, andremoveTags!ppeDict::Dict{Symbol, AbstractPointParametricEst}: Dictionary of parametric point estimates keyed by solverDataDict keys Accessors:addPPE!,updatePPE!, anddeletePPE!solverDataDict::Dict{Symbol, State{T, P, N}} where {T<:AbstractStateType, P, N}: Dictionary of solver data. May be a subset of all solutions if a solver label was specified in the get call. Accessors:addState!,mergeState!, anddeleteState!smallData::Dict{Symbol, Union{Bool, Float64, Int64, Vector{Bool}, Vector{Float64}, Vector{Int64}, Vector{String}, String}}: Dictionary of small data associated with this variable. Accessors:getMetadata,setMetadata!dataDict::Dict{Symbol, Blobentry}: Dictionary of large data associated with this variable. Accessors:addBlobentry!,getBlobentry,mergeBlobentry!, anddeleteBlobentry!solvable::Base.RefValue{Int64}: Solvable flag for the variable. Accessors:getSolvable,setSolvable!
DistributedFactorGraphs.VariableCompute — MethodVariableCompute(label, T; timestamp, solvable, kwargs...)
The default VariableCompute constructor.
DistributedFactorGraphs.VariableDFG — Typestruct VariableDFG <: AbstractGraphVariableThe Variable information packed in a way that accomdates multi-lang using json.
Notes:
- timestamp is a
ZonedDateTimein UTC. - nstime can be used as mission time, with the convention that the timestamp millis coincide with the mission start nstime
- e.g. timestamp is
2020-01-01 06:30:01.250 UTCand first nstime is250_000_000.
- e.g. timestamp is
DistributedFactorGraphs.VariableSkeleton — Typestruct VariableSkeleton <: AbstractGraphVariableSkeleton variable structure for a DistributedFactorGraph variable.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the variablelabel::Symbol: Variable label, e.g. :x1. Accessor:getLabeltags::Set{Symbol}: Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK]. Accessors:getTags,mergeTags!, andremoveTags!
DistributedFactorGraphs.VariableSummary — Typestruct VariableSummary <: AbstractGraphVariableSummary variable structure for a DistributedFactorGraph variable.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the variablelabel::Symbol: Variable label, e.g. :x1. Accessor:getLabeltimestamp::TimeZones.ZonedDateTime: Variable timestamp. Accessors:getTimestamp,setTimestamptags::Set{Symbol}: Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK]. Accessors:getTags,mergeTags!, andremoveTags!ppeDict::Dict{Symbol, <:AbstractPointParametricEst}: Dictionary of parametric point estimates keyed by solverDataDict keys Accessors:addPPE!,updatePPE!, anddeletePPE!variableTypeName::Symbol: Symbol for the variableType for the underlying variable. Accessor:getVariableTypedataDict::Dict{Symbol, Blobentry}: Dictionary of large data associated with this variable. Accessors:addBlobentry!,getBlobentry,mergeBlobentry!, anddeleteBlobentry!
DistributedFactorGraphs.getEstimateFields — MethodgetEstimateFields(_)
Return the fields of MeanMaxPPE that are estimates. NOTE: This is needed for each AbstractPointParametricEst. Closest we can get to a decorator pattern.
DFG Factor Nodes
DistributedFactorGraphs.FactorCompute — Typestruct FactorCompute{FT<:AbstractObservation, N} <: AbstractGraphFactorComplete factor structure for a DistributedFactorGraph factor.
DevNotes
TODO make consistent the order of fields skeleton Skeleton, Summary, thru FactorCompute
- e.g. timestamp should be a later field.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the factorlabel::Symbol: Factor label, e.g. :x1f1. Accessor:getLabeltags::Set{Symbol}: Factor tags, e.g [:FACTOR]. Accessors:getTags,mergeTags!, andremoveTags!_variableOrderSymbols::Tuple{Vararg{Symbol, N}} where N: Internal cache of the ordering of the neighbor variables. Rather use getVariableOrder to get the list as this is an internal value. Accessors:getVariableOrdertimestamp::TimeZones.ZonedDateTime: Variable timestamp. Accessors:getTimestamp,setTimestampnstime::Dates.Nanosecond: Nano second timesolvable::Base.RefValue{Int64}: Solvable flag for the factor. Accessors:getSolvable,setSolvable!smallData::Dict{Symbol, Union{Bool, Float64, Int64, Vector{Bool}, Vector{Float64}, Vector{Int64}, Vector{String}, String}}: Dictionary of small data associated with this variable. Accessors:getMetadata,setMetadata!observation::AbstractObservation: Observation function or measurement for this factor. Accessors:getObservation(@ref)state::DistributedFactorGraphs.FactorState: Describes the current state of the factor. Persisted in serialization. Accessors:getFactorStatesolvercache::Base.RefValue{<:AbstractFactorCache}: Temporary, non-persistent memory used internally by the solver for intermediate numerical computations and buffers.solvercacheis lazily allocated and only used during factor operations; it is not serialized or retained after solving. Accessors:getCache,setCache!
DistributedFactorGraphs.FactorDFG — Typestruct FactorDFG <: AbstractGraphFactorThe Factor information packed in a way that accomdates multi-lang using json.
DistributedFactorGraphs.FactorSkeleton — Typestruct FactorSkeleton <: AbstractGraphFactorSkeleton factor structure for a DistributedFactorGraph factor.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the factorlabel::Symbol: Factor label, e.g. :x1f1. Accessor:getLabeltags::Set{Symbol}: Factor tags, e.g [:FACTOR]. Accessors:getTags,mergeTags!, andremoveTags!_variableOrderSymbols::Vector{Symbol}: Internal cache of the ordering of the neighbor variables. Rather use listNeighbors to get the list as this is an internal value. Accessors:getVariableOrder
DistributedFactorGraphs.FactorSummary — Typestruct FactorSummary <: AbstractGraphFactorRead-only summary factor structure for a DistributedFactorGraph factor.
Fields:
id::Union{Nothing, Base.UUID}: The ID for the factorlabel::Symbol: Factor label, e.g. :x1f1. Accessor:getLabeltags::Set{Symbol}: Factor tags, e.g [:FACTOR]. Accessors:getTags,mergeTags!, andremoveTags!_variableOrderSymbols::Vector{Symbol}: Internal cache of the ordering of the neighbor variables. Rather use listNeighbors to get the list as this is an internal value. Accessors:getVariableOrdertimestamp::TimeZones.ZonedDateTime: Variable timestamp. Accessors:getTimestamp
Error Types
DistributedFactorGraphs.IdExistsError — TypeIdExistsError(Id)Error thrown when attempting to add an Id that already exists in the collection.
DistributedFactorGraphs.IdNotFoundError — TypeIdNotFoundError(Id, available)Error thrown when a requested Id is not found.
DistributedFactorGraphs.LabelExistsError — TypeLabelExistsError(label)Error thrown when attempting to add a label that already exists in the collection.
DistributedFactorGraphs.LabelNotFoundError — TypeLabelNotFoundError(label, available)Error thrown when a requested label is not found in the factor graph.
DistributedFactorGraphs.SerializationError — TypeSerializationError(msg)Error thrown when serialization or deserialization fails.
DFG Plots [GraphMakie.jl]
DistributedFactorGraphs.plotDFG — FunctionPlots the structure of the factor graph. GraphMakie must be imported before DistributedFactorGraphs for these functions to be available. Returns the plot context.
E.g.
using GraphMakie
using DistributedFactorGraphs
# ... Make graph...
plotDFG(fg)More information at GraphMakie.jl
Drivers
GraphsDFGs
DistributedFactorGraphs.GraphsDFGs.GraphsDFG — TypeAn in-memory DistributedFactorGraph based on Graphs.jl with parameters:
- T: Solver parameters (defaults to
NoSolverParams()) - V: Variable type
- F: Factor type
DistributedFactorGraphs.GraphsDFGs.GraphsDFG — MethodGraphsDFG(; ...)
Create an in-memory GraphsDFG with the following parameters:
- T: Solver parameters (defaults to
NoSolverParams()) - V: Variable type
- F: Factor type
DistributedFactorGraphs.GraphsDFGs.packDFGMetadata — MethodpackDFGMetadata(fg)
Packing function to serialize DFG metadata from.
DistributedFactorGraphs.GraphsDFGs.savedot_attributes — Methodsavedot_attributes(io, dfg)
A replacement for to_dot that saves only hardcoded factor graph plotting attributes.
DistributedFactorGraphs.GraphsDFGs.traverseGraphTopologicalSort — FunctiontraverseGraphTopologicalSort(fg, s)
traverseGraphTopologicalSort(fg, s, fs_tree)
Return a topological sort of a factor graph as a vector of vertex labels in topological order. Starting from s::Symbol
DistributedFactorGraphs._getDuplicatedEmptyDFG — Method_getDuplicatedEmptyDFG(dfg)
Gets an empty and unique GraphsDFG derived from an existing DFG.
FileDFG
DistributedFactorGraphs.loadDFG! — MethodloadDFG!(dfgLoadInto, dst; overwriteDFGMetadata)
Load a DFG from a saved folder.
Example
using DistributedFactorGraphs, IncrementalInference
# Create a DFG - can make one directly, e.g. GraphsDFG{NoSolverParams}() or use IIF:
dfg = initfg()
# Load the graph
loadDFG!(dfg, "/tmp/savedgraph.tar.gz")
# Use the DFG as you do normally.
ls(dfg)DistributedFactorGraphs.loadDFG — MethodDistributedFactorGraphs.saveDFG — MethodsaveDFG(folder, dfg; saveMetadata)
Save a DFG to a folder. Will create/overwrite folder if it exists.
DevNotes:
- TODO remove
compresskwarg.
Example
using DistributedFactorGraphs, IncrementalInference
# Create a DFG - can make one directly, e.g. GraphsDFG{NoSolverParams}() or use IIF:
dfg = initfg()
# ... Add stuff to graph using either IIF or DFG:
v1 = addVariable!(dfg, :a, ContinuousScalar, tags = [:POSE], solvable=0)
# Now save it:
saveDFG(dfg, "/tmp/saveDFG.tar.gz")