Skip to content

Commit 74aef9e

Browse files
authored
Consolidate test and some cleanup (#287)
* WIP Sorting and grouping tests. * Deprecate some PPE functions * Skeleton and Summary mostly consolidated * update return type and bugfix in mergeVariableSolverData! * test better types, getFactors tags
1 parent 3c50f90 commit 74aef9e

File tree

14 files changed

+1318
-1432
lines changed

14 files changed

+1318
-1432
lines changed

src/Deprecated.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,27 @@ Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
8080
end
8181
end
8282

83-
@deprecate getEstimates(v::VariableDataLevel1) getVariablePPEs(v)
83+
@deprecate getEstimates(v::VariableDataLevel1) getPPEDict(v)
84+
85+
@deprecate estimates(v::VariableDataLevel1) getPPEDict(v)
86+
87+
@deprecate getVariablePPEs(v::VariableDataLevel1) getPPEDict(v)
88+
89+
@deprecate getVariablePPE(args...) getPPE(args...)
90+
#FIXME SORT UIT en deprecate, too many aliases
91+
92+
93+
"""
94+
$SIGNATURES
95+
96+
Return dictionary with Parametric Point Estimates (PPE) values.
97+
98+
Notes:
99+
- Equivalent to `getVariablePPEs`.
100+
"""
101+
#TODO deprecate, maar gebruik dalk naam om vector te kry soos getVariables/getFactors
102+
getPPEs(vari::VariableDataLevel1)::Dict = getVariablePPEs(vari)
84103

85-
@deprecate estimates(v::VariableDataLevel1) getVariablePPEs(v)
86104

87105
@deprecate getEstimate(v::VariableDataLevel1, key::Symbol=:default) getVariablePPE(v, key)
88106

@@ -120,6 +138,8 @@ Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
120138

121139
@deprecate internalId(args...) getInternalId(args...)
122140

141+
#FIXME TODO based on API definition of merge, in some cases the Noun is really not needed.
142+
# @deprecate mergeUpdateVariableSolverData!(args...) mergeVariableSolverData!(args...)
123143

124144

125145
export getLabelDict

src/DistributedFactorGraphs.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ using JSON2
1010
using LinearAlgebra
1111
using SparseArrays
1212

13+
# TODO
14+
# - hasOrphans: actually check if there are orphaned factors
15+
# getFactorFunction vs getFactorType, does the same thing
16+
#
17+
1318
# Entities
1419
include("entities/AbstractDFG.jl")
1520

@@ -36,6 +41,7 @@ export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
3641
export getNeighborhood, getSubgraph, getSubgraphAroundNode
3742

3843
export getUserId, getRobotId, getSessionId
44+
export getDFGInfo
3945

4046
# Define variable levels
4147
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}
@@ -71,7 +77,7 @@ export getVariableOrder
7177

7278
# Services/AbstractDFG Exports
7379
export isInitialized, getFactorFunction, isVariable, isFactor
74-
export isSolveInProgress, getSolvable, setSolvable!, getSolveInProgress
80+
export isSolveInProgress, getSolvable, setSolvable!, getSolveInProgress, isSolvable
7581
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
7682

7783
# Solver (IIF) Exports

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,17 @@ function getVariables(dfg::GraphsDFG,
202202
return variables
203203
end
204204

205-
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{DFGFactor}
205+
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{DFGFactor}
206206
factors = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGFactor) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
207207

208208
if regexFilter != nothing
209209
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
210210
end
211+
212+
if length(tags) > 0
213+
mask = map(v -> length(intersect(v.tags, tags)) > 0, factors )
214+
return factors[mask]
215+
end
211216
return factors
212217
end
213218

src/LightDFG/services/LightDFG.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function listVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing
168168
end
169169
end
170170

171-
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{AbstractDFGFactor}
171+
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{AbstractDFGFactor}
172172
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
173173
factors = collect(values(dfg.g.factors))
174174
if regexFilter != nothing
@@ -177,6 +177,10 @@ function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; s
177177
if solvable != 0
178178
factors = filter(f -> _isSolvable(dfg, f.label, solvable), factors)
179179
end
180+
if length(tags) > 0
181+
mask = map(v -> length(intersect(v.tags, tags)) > 0, factors )
182+
return factors[mask]
183+
end
180184
return factors
181185
end
182186

src/entities/AbstractDFG.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ The common node parameters for variables and factors.
2727
mutable struct DFGNodeParams
2828
solvable::Int
2929
_internalId::Int64
30-
DFGNodeParams() = new(0, 0)
31-
DFGNodeParams(solvable::Int, _internalId::Int64) = new(solvable, _internalId)
3230
end
31+
DFGNodeParams() = DFGNodeParams(0, 0)
3332

3433
"""
3534
$(TYPEDEF)

src/services/AbstractDFG.jl

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Getters
1616
"""
1717
$(SIGNATURES)
18+
Convenience function to get all the matadata of a DFG
1819
"""
1920
getDFGInfo(dfg::AbstractDFG) = (dfg.description, dfg.userId, dfg.robotId, dfg.sessionId, dfg.userData, dfg.robotData, dfg.sessionData, dfg.solverParams)
2021

@@ -268,12 +269,14 @@ end
268269
Get a DFGVariable with a specific solver key.
269270
In memory types still return a reference, other types returns a variable with only solveKey.
270271
"""
271-
function getVariable(dfg::G, label::Symbol, solveKey::Symbol)::AbstractDFGVariable where G <: AbstractDFG
272+
function getVariable(dfg::AbstractDFG, label::Symbol, solveKey::Symbol)::AbstractDFGVariable
272273

273274
var = getVariable(dfg, label)
274275

275-
if !haskey(var.solverDataDict, solveKey)
276+
if isa(var, DFGVariable) && !haskey(var.solverDataDict, solveKey)
276277
error("Solvekey '$solveKey' does not exists in the variable")
278+
elseif !isa(var, DFGVariable)
279+
@warn "getVariable(dfg, label, solveKey) only supported for type DFGVariable."
277280
end
278281

279282
return var
@@ -394,7 +397,7 @@ end
394397
List the DFGFactors in the DFG.
395398
Optionally specify a label regular expression to retrieves a subset of the factors.
396399
"""
397-
function getFactors(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{AbstractDFGFactor} where G <: AbstractDFG
400+
function getFactors(dfg::G, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{AbstractDFGFactor} where G <: AbstractDFG
398401
error("getFactors not implemented for $(typeof(dfg))")
399402
end
400403

@@ -712,7 +715,13 @@ end
712715

713716
"""
714717
$(SIGNATURES)
715-
Get variable PPE for a given solve key.
718+
Get the parametric point estimate (PPE) for a variable in the factor graph for a given solve key.
719+
720+
Notes
721+
- Defaults on keywords `solveKey` and `method`
722+
723+
Related
724+
getMeanPPE, getMaxPPE, getKDEMean, getKDEFit, getPPEs, getVariablePPEs
716725
"""
717726
function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default)::AbstractPointParametricEst
718727
v = getVariable(dfg, variablekey)
@@ -721,7 +730,7 @@ function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default):
721730
end
722731

723732
# Not the most efficient call but it at least reuses above (in memory it's probably ok)
724-
getPPE(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=default)::AbstractPointParametricEst = getPPE(dfg, sourceVariable.label, ppekey)
733+
getPPE(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=default)::AbstractPointParametricEst = getPPE(dfg, sourceVariable.label, ppekey)
725734

726735
"""
727736
$(SIGNATURES)
@@ -765,14 +774,14 @@ end
765774
Update PPE data if it exists, otherwise add it.
766775
NOTE: Copies the PPE data.
767776
"""
768-
updatePPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:default) =
777+
updatePPE!(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=:default) =
769778
updatePPE!(dfg, sourceVariable.label, deepcopy(getPPE(sourceVariable, ppekey)), ppekey)
770779

771780
"""
772781
$(SIGNATURES)
773782
Update PPE data if it exists, otherwise add it.
774783
"""
775-
function updatePPE!(dfg::AbstractDFG, sourceVariables::Vector{<:DFGVariable}, ppekey::Symbol=:default)
784+
function updatePPE!(dfg::AbstractDFG, sourceVariables::Vector{<:VariableDataLevel1}, ppekey::Symbol=:default)
776785
#I think cloud would do this in bulk for speed
777786
for var in sourceVariables
778787
updatePPE!(dfg, var.label, getPPE(dfg, var, ppekey), ppekey)
@@ -802,34 +811,69 @@ deletePPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:defaul
802811

803812
####
804813

814+
815+
export mergeVariableSolverData!, mergePPEs!, mergeVariableData!, mergeGraphVariableData!
816+
# update is implied, see API wiki
817+
@deprecate mergeUpdateVariableSolverData!(dfg, sourceVariable) mergeVariableData!(dfg, sourceVariable)
818+
@deprecate mergeUpdateGraphSolverData!(sourceDFG, destDFG, varSyms) mergeGraphVariableData!(destDFG, sourceDFG, varSyms)
819+
805820
"""
806821
$(SIGNATURES)
807822
Merges and updates solver and estimate data for a variable (variable can be from another graph).
808-
Note: Makes a copy of the estimates and solver data so that there is no coupling
809-
between graphs.
823+
If the same key is present in another collection, the value for that key will be the value it has in the last collection listed (updated).
824+
Note: Makes a copy of the estimates and solver data so that there is no coupling between graphs.
810825
"""
811-
function mergeUpdateVariableSolverData!(dfg::AbstractDFG, sourceVariable::AbstractDFGVariable)::AbstractDFGVariable
812-
if !exists(dfg, sourceVariable)
813-
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
814-
end
815-
var = getVariable(dfg, sourceVariable.label)
826+
#TODO API
827+
function mergeVariableSolverData!(destVariable::DFGVariable, sourceVariable::DFGVariable)::DFGVariable
828+
# We don't know which graph this came from, must be copied!
829+
merge!(destVariable.solverDataDict, deepcopy(sourceVariable.solverDataDict))
830+
return destVariable
831+
end
832+
833+
"""
834+
$(SIGNATURES)
835+
Merges and updates solver and estimate data for a variable (variable can be from another graph).
836+
Note: Makes a copy of the estimates and solver data so that there is no coupling between graphs.
837+
"""
838+
#TODO API and only correct level
839+
function mergePPEs!(destVariable::AbstractDFGVariable, sourceVariable::AbstractDFGVariable)::AbstractDFGVariable
816840
# We don't know which graph this came from, must be copied!
817-
merge!(var.ppeDict, deepcopy(sourceVariable.ppeDict))
841+
merge!(destVariable.ppeDict, deepcopy(sourceVariable.ppeDict))
842+
return destVariable
843+
end
844+
845+
"""
846+
$(SIGNATURES)
847+
Merges and updates solver and estimate data for a variable (variable can be from another graph).
848+
Note: Makes a copy of the estimates and solver data so that there is no coupling between graphs.
849+
"""
850+
#TODO API
851+
function mergeVariableData!(dfg::AbstractDFG, sourceVariable::AbstractDFGVariable)::AbstractDFGVariable
852+
853+
var = getVariable(dfg, sourceVariable.label)
854+
855+
mergePPEs!(var, sourceVariable)
818856
# If this variable has solverDataDict (summaries do not)
819-
:solverDataDict in fieldnames(typeof(var)) && merge!(var.solverDataDict, deepcopy(sourceVariable.solverDataDict))
820-
return sourceVariable
857+
:solverDataDict in fieldnames(typeof(var)) && mergeVariableSolverData!(var, sourceVariable)
858+
859+
#update if its not a InMemoryDFGTypes, otherwise it was a reference
860+
# if satelite nodes are used it can be updated seprarately
861+
# !(isa(dfg, InMemoryDFGTypes)) && updateVariable!(dfg, var)
862+
863+
return var
821864
end
822865

823866
"""
824867
$(SIGNATURES)
825868
Common function to update all solver data and estimates from one graph to another.
826869
This should be used to push local solve data back into a cloud graph, for example.
827870
"""
828-
function mergeUpdateGraphSolverData!(sourceDFG::G, destDFG::H, varSyms::Vector{Symbol})::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
871+
#TODO API
872+
function mergeGraphVariableData!(destDFG::H, sourceDFG::G, varSyms::Vector{Symbol})::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
829873
# Update all variables in the destination
830874
# (For now... we may change this soon)
831875
for variableId in varSyms
832-
mergeUpdateVariableSolverData!(destDFG, getVariable(sourceDFG, variableId))
876+
mergeVariableData!(destDFG, getVariable(sourceDFG, variableId))
833877
end
834878
end
835879

@@ -924,13 +968,15 @@ Related
924968
925969
isSolvable
926970
"""
927-
function getSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default)::Int
971+
function getSolveInProgress(var::Union{DFGVariable, DFGFactor}, solveKey::Symbol=:default)::Int
928972
# Variable
929973
var isa DFGVariable && return haskey(getSolverDataDict(var), solveKey) ? getSolverDataDict(var)[solveKey].solveInProgress : 0
930974
# Factor
931975
return getSolverData(var).solveInProgress
932976
end
933977

978+
isSolveInProgress(node::Union{DFGVariable, DFGFactor}, solvekey::Symbol=:default) = getSolveInProgress(node, solvekey) > 0
979+
934980
"""
935981
$SIGNATURES
936982

src/services/CompareUtils.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import Base.==
55

66
#=
7-
TODO <:InferenceVariable: please someone confirm this, I'm not fully up to date why softtype was created.
8-
For now abstract `InferenceVariable`s are considered equal if they are the same type (except for labels, that I feel are deprecated)
7+
For now abstract `InferenceVariable`s are considered equal if they are the same type, dims, and manifolds (abels are deprecated)
98
If your implentation has aditional properties such as `DynPose2` with `ut::Int64` (microsecond time) or support different manifolds
10-
implement compare if needed. softtype sounds a bit if it can be a trait, or in the future, rather a normal julia type.
9+
implement compare if needed.
1110
=#
12-
==(a::InferenceVariable,b::InferenceVariable) = typeof(a) == typeof(b)
11+
==(a::InferenceVariable,b::InferenceVariable) = typeof(a) == typeof(b) && a.dims == b.dims && a.manifolds == b.manifolds
1312

1413
==(a::ConvolutionObject, b::ConvolutionObject) = typeof(a) == typeof(b)
1514

src/services/DFGFactor.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ Retrieve solver data structure stored in a factor.
106106
function getSolverData(f::F) where F <: DFGFactor
107107
return f.solverData
108108
end
109+
110+
#TODO don't know if this is used, added for completeness
111+
setSolverData!(f::DFGFactor, data::GenericFunctionNodeData) = f.solverData = data

0 commit comments

Comments
 (0)