Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable solver data concept #231

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CompatHelper

on:
schedule:
- cron: '00 00 * * *'

jobs:
CompatHelper:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.2.0]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
2 changes: 2 additions & 0 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
export AbstractDFG
export AbstractParams, NoSolverParams
export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor

export getVariablePPE
export DFGNodeParams
export SkeletonDFGVariable, SkeletonDFGFactor
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
Expand Down
46 changes: 41 additions & 5 deletions src/FileDFG/services/FileDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE], solvable=0)
saveDFG(dfg, "/tmp/saveDFG")
```
"""
function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
function saveDFG(dfg::AbstractDFG, folder::String; compress::Symbol=:gzip)
variables = getVariables(dfg)
factors = getFactors(dfg)
varFolder = "$folder/variables"
Expand Down Expand Up @@ -43,6 +43,16 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
JSON2.write(io, fPacked)
close(io)
end

# compress newly saved folder, skip if not supported format
!(compress in [:gzip]) && return
savepath = folder[end] == '/' ? folder[1:end-1] : folder
savedir = dirname(savepath)
savename = splitpath(string(savepath))[end]
@assert savename != ""
# temporarily change working directory to get correct zipped path
run( pipeline(`tar -zcf - -C $savedir $savename`, stdout="$savepath.tar.gz") )
Base.rm(joinpath(savedir,savename), recursive=true)
end

"""
Expand All @@ -56,20 +66,46 @@ using DistributedFactorGraphs, IncrementalInference
# Create a DFG - can make one directly, e.g. GraphsDFG{NoSolverParams}() or use IIF:
dfg = initfg()
# Load the graph
loadDFG("/tmp/savedgraph", IncrementalInference, dfg)
loadDFG("/tmp/savedgraph.tar.gz", IncrementalInference, dfg)
loadDFG("/tmp/savedgraph", IncrementalInference, dfg) # alternative
# Use the DFG as you do normally.
ls(dfg)
```
"""
function loadDFG(folder::String, iifModule, dfgLoadInto::G) where G <: AbstractDFG
function loadDFG(dst::String, iifModule, dfgLoadInto::G; loaddir=joinpath("/","tmp","caesar","random")) where G <: AbstractDFG
# Check if zipped destination (dst) by first doing fuzzy search from user supplied dst
folder = dst # working directory for fileDFG variable and factor operations
dstname = dst # path name could either be legacy FileDFG dir or .tar.gz file of FileDFG files.
unzip = false
# add if doesn't have .tar.gz extension
lastdirname = splitpath(dstname)[end]
if !isdir(dst)
unzip = true
sdst = split(lastdirname, '.')
if sdst[end] != "gz" # length(sdst) == 1 &&
dstname *= ".tar.gz"
lastdirname *= ".tar.gz"
end
end
# do actual unzipping
if unzip
@show sfolder = split(dstname, '.')
Base.mkpath(loaddir)
folder = joinpath(loaddir, lastdirname[1:(end-length(".tar.gz"))]) #splitpath(string(sfolder[end-2]))[end]
@info "loadDFG detected a gzip $dstname -- unpacking via $loaddir now..."
Base.rm(folder, recursive=true, force=true)
# unzip the tar file
run(`tar -zxf $dstname -C $loaddir`)
end
# extract the factor graph from fileDFG folder
variables = DFGVariable[]
factors = DFGFactor[]
varFolder = "$folder/variables"
factorFolder = "$folder/factors"
# Folder preparations
!isdir(folder) && error("Can't load DFG graph - folder '$folder' doesn't exist")
!isdir(varFolder) && error("Can't load DFG graph - folder '$folder' doesn't exist")
!isdir(factorFolder) && error("Can't load DFG graph - folder '$folder' doesn't exist")
!isdir(varFolder) && error("Can't load DFG graph - folder '$varFolder' doesn't exist")
!isdir(factorFolder) && error("Can't load DFG graph - folder '$factorFolder' doesn't exist")

varFiles = readdir(varFolder)
factorFiles = readdir(factorFolder)
Expand Down
4 changes: 2 additions & 2 deletions src/LightDFG/entities/LightDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ Base.propertynames(x::LightDFG, private::Bool=false) =

Base.getproperty(x::LightDFG,f::Symbol) = begin
if f == :nodeCounter
@error "Field nodeCounter depreciated. returning number of nodes"
@error "Field nodeCounter deprecated. returning number of nodes"
nv(x.g)
elseif f == :labelDict
@error "Field labelDict depreciated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
@error "Field labelDict deprecated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
#TODO: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/111
copy(x.g.labels.sym_int)
else
Expand Down
4 changes: 2 additions & 2 deletions src/attic/MetaGraphsDFG/entities/MetaGraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Base.propertynames(x::MetaGraphsDFG, private::Bool=false) =

Base.getproperty(x::MetaGraphsDFG,f::Symbol) = begin
if f == :nodeCounter
@warn "Field nodeCounter depreciated. returning number of nodes"
@warn "Field nodeCounter deprecated. returning number of nodes"
nv(x.g)
elseif f == :labelDict
@warn "Field labelDict depreciated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
@warn "Field labelDict deprecated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
copy(x.g.metaindex[:label])
else
getfield(x,f)
Expand Down
4 changes: 2 additions & 2 deletions src/attic/SymbolDFG/entities/SymbolDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Base.propertynames(x::SymbolDFG, private::Bool=false) =

Base.getproperty(x::SymbolDFG,f::Symbol) = begin
if f == :nodeCounter
@error "Field nodeCounter depreciated. returning number of nodes"
@error "Field nodeCounter deprecated. returning number of nodes"
nv(x.g)
elseif f == :labelDict
@error "Field labelDict depreciated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
@error "Field labelDict deprecated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
copy(x.g.fadjdict)
else
getfield(x,f)
Expand Down
127 changes: 126 additions & 1 deletion src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

include("DFGVariable/PackedVariableNodeData.jl")
include("DFGVariable/PointParametricEst.jl")
include("DFGVariable/VariableNodeData.jl")
Expand Down Expand Up @@ -55,3 +54,129 @@ DFGVariable(label::Symbol, softtype::T;
solvable::Int=1,
_internalId::Int64=0) where {T <: InferenceVariable} =
DFGVariable{T}(label, now(), tags, estimateDict, solverDataDict, smallData, bigData, solvable, DFGNodeParams(solvable, _internalId))

"""
$SIGNATURES
DFGVariable constructors.
"""
function DFGVariable(label::Symbol, _internalId::Int64 = 0) #where {T <:InferenceVariable}
st = stacktrace()
@warn "DFGVariable(label::Symbol, _internalId::Int64 = 0) is deprecated please use DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where T <: InferenceVariable. Enable DEBUG logging for the stack trace."
@debug st
T = InferenceVariable
DFGVariable(label, now(), Symbol[],
Dict{Symbol, MeanMaxPPE}(),
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData()),
Dict{String, String}(),
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
end
DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where {T <: InferenceVariable} =
DFGVariable(label, now(), Symbol[],
Dict{Symbol, MeanMaxPPE}(),
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData{T}()),
Dict{String, String}(),
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)

"""
$(SIGNATURES)
Structure for first-class citizens of a DFGVariable.
"""
mutable struct DFGVariableSummary <: AbstractDFGVariable
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, <:AbstractPointParametricEst}
Copy link
Member

@dehann dehann Jan 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest v0.5.3 now has this as ppeDict

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see here:

ppeDict::Dict{Symbol, <:AbstractPointParametricEst}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will likely fall out naturally when merging all this to master, just ask to keep an eye on it when we do please.

softtypename::Symbol
_internalId::Int64
end


# SKELETON DFG
"""
$(TYPEDEF)
Skeleton variable with essentials.
"""
struct SkeletonDFGVariable <: AbstractDFGVariable
label::Symbol
tags::Vector{Symbol}
end

SkeletonDFGVariable(label::Symbol) = SkeletonDFGVariable(label, Symbol[])


# Accessors

const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}
const VariableDataLevel1 = Union{DFGVariable, DFGVariableSummary}
const VariableDataLevel2 = Union{DFGVariable}


"""
$SIGNATURES

Return the estimates for a variable.
"""
getEstimates(v::VariableDataLevel1) = v.estimateDict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too has been deprecated, see master branch.


"""
$SIGNATURES

Return the estimates for a variable.

DEPRECATED, estimates -> getEstimates
"""
function estimates(v::VariableDataLevel1)
@warn "Deprecated estimates, use getEstimates instead."
getEstimates(v)
end

"""
$SIGNATURES

Return a keyed estimate (default is :default) for a variable.
"""
getEstimate(v::VariableDataLevel1, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing

"""
$SIGNATURES

Return a keyed estimate (default is :default) for a variable.
"""
function estimate(v::VariableDataLevel1, key::Symbol=:default)
@warn "DEPRECATED estimate, use getEstimate instead."
getEstimate(v, key)
end


"""
$SIGNATURES

Get the parametric point estimate (PPE) for a variable in the factor graph.

Notes
- Defaults on keywords `solveKey` and `method`

Related

getMeanPPE, getMaxPPE, getKDEMean, getKDEFit
"""
function getVariablePPE(vari::DFGVariable; solveKey::Symbol=:default, method::Function=getSuggestedPPE)
getEstimates(vari)[solveKey] |> getSuggestedPPE
end

getVariablePPE(dfg::AbstractDFG, vsym::Symbol; solveKey::Symbol=:default, method::Function=getSuggestedPPE) = getVariablePPE(getVariable(dfg,vsym), solveKey=solveKey, method=method)

"""
$(SIGNATURES)

Variable nodes softtype information holding a variety of meta data associated with the type of variable stored in that node of the factor graph.

Related

getVariableType
"""
function getSofttype(vnd::VariableNodeData)
return vnd.softtype
end
function getSofttype(v::DFGVariable; solveKey::Symbol=:default)
return getSofttype(solverData(v, solveKey))
Loading