Skip to content

Commit bd40774

Browse files
committed
Some Progress on tests, bit of a mess still
1 parent 851fae2 commit bd40774

File tree

9 files changed

+129
-42
lines changed

9 files changed

+129
-42
lines changed

src/Deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Base.getproperty(x::VariableDataLevel1,f::Symbol) = begin
99
if f == :estimateDict
1010
@warn "estimateDict is deprecated, use ppeDict instead"
1111
getfield(x, :ppeDict)
12+
elseif f == :solvable
13+
getfield(x,:_dfgNodeParams).solvable
14+
elseif f == :_internalId
15+
getfield(x,:_dfgNodeParams)._internalId
1216
else
1317
getfield(x,f)
1418
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export getVariableOrder
6868

6969
# Services/AbstractDFG Exports
7070
export isInitialized, getFactorFunction, isVariable, isFactor
71-
export isSolvable, isSolveInProgress, getSolvable, setSolvable!
71+
export isSolvable, isSolveInProgress, getSolvable, setSolvable!, getSolveInProgress
7272
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
7373

7474
# Solver (IIF) Exports

src/LightDFG/entities/LightDFG.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,26 @@ Create an in-memory LightDFG with the following parameters:
5050
- V: Variable type
5151
- F: Factor type
5252
"""
53-
LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); kwargs...) where T <: AbstractParams = LightDFG{T,DFGVariable,DFGFactor}(g; kwargs...)
53+
LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); kwargs...) where T <: AbstractParams =
54+
LightDFG{T,DFGVariable,DFGFactor}(g; kwargs...)
5455

55-
Base.propertynames(x::LightDFG, private::Bool=false) =
56-
(:g, :description, :userId, :robotId, :sessionId, :nodeCounter, :labelDict, :addHistory, :solverParams)
57-
# (private ? fieldnames(typeof(x)) : ())...)
56+
LightDFG(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); params::T=NoSolverParams(), kwargs...) where T =
57+
LightDFG{T,DFGVariable,DFGFactor}(g; params=params, kwargs...)
5858

59-
Base.getproperty(x::LightDFG,f::Symbol) = begin
60-
if f == :nodeCounter
61-
@error "Field nodeCounter deprecated. returning number of nodes"
62-
nv(x.g)
63-
elseif f == :labelDict
64-
@error "Field labelDict deprecated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
65-
#TODO: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/111
66-
copy(x.g.labels.sym_int)
67-
else
68-
getfield(x,f)
69-
end
70-
end
59+
# Fully depcrecate nodeCounter and labelDict
60+
# Base.propertynames(x::LightDFG, private::Bool=false) =
61+
# (:g, :description, :userId, :robotId, :sessionId, :nodeCounter, :labelDict, :addHistory, :solverParams)
62+
# # (private ? fieldnames(typeof(x)) : ())...)
63+
#
64+
# Base.getproperty(x::LightDFG,f::Symbol) = begin
65+
# if f == :nodeCounter
66+
# @error "Field nodeCounter deprecated. returning number of nodes"
67+
# nv(x.g)
68+
# elseif f == :labelDict
69+
# @error "Field labelDict deprecated. Consider using exists(dfg,label) or getLabelDict(dfg) instead. Returning internals copy"
70+
# #TODO: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/111
71+
# copy(x.g.labels.sym_int)
72+
# else
73+
# getfield(x,f)
74+
# end
75+
# end

src/LightDFG/services/LightDFG.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function addVariable!(dfg::LightDFG{<:AbstractParams, V, <:AbstractDFGFactor}, v
6767
return true
6868
end
6969

70-
function addFactor!(dfg::LightDFG{<:AbstractParams, V, F}, variables::Vector{V}, factor::F)::Bool where {V <: AbstractDFGVariable, F <: AbstractDFGFactor}
70+
function addFactor!(dfg::LightDFG{<:AbstractParams, V, F}, variables::Vector{<:V}, factor::F)::Bool where {V <: AbstractDFGVariable, F <: AbstractDFGFactor}
7171
# if haskey(dfg.g.metaindex[:label], factor.label)
7272
# error("Factor '$(factor.label)' already exists in the factor graph")
7373
# end
@@ -115,7 +115,7 @@ end
115115

116116
#TODO Sam, I would say if we handle the update vsd corectly this function is only needed in the cloud.
117117
# In memory types are just passing pointers along so no perfomrance issue.
118-
function getVariable(dfg::LightDFG, label::Symbol; solveKey::Union{Nothing, Symbol})::Union{Nothing, AbstractDFGVariable}
118+
function getVariable(dfg::LightDFG, label::Symbol; solveKey::Union{Nothing, Symbol}=nothing)::Union{Nothing, AbstractDFGVariable}
119119

120120
if !haskey(dfg.g.variables, label)
121121
@warn "Variable '$label' does not exists in the factor graph"
@@ -393,7 +393,7 @@ end
393393

394394
function getAdjacencyMatrixSparse(dfg::LightDFG; solvable::Int=0)
395395
@warn "Deprecated function, please use getBiadjacencyMatrixSparse as this will be removed in v0.6.1"
396-
return getBiadjacencyMatrixSparse(dfg, solvable)
396+
return getBiadjacencyMatrixSparse(dfg, solvable=solvable)
397397
end
398398

399399
# this would be an incidence matrix

src/entities/DFGFactor.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mutable struct DFGFactor{T, S} <: AbstractDFGFactor
4747
timestamp::DateTime
4848
"""Factor tags, e.g [:FACTOR].
4949
Accessors: `getTags`, `addTags!`, and `deleteTags!`"""
50-
tags::Vector{Symbol}
50+
tags::Set{Symbol}#Vector{Symbol} #TODO I propose we use a set since tags can't be repeated.
5151
"""Solver data.
5252
Accessors: `getSolverData`, `setSolverData!`"""
5353
solverData::GenericFunctionNodeData{T, S}
@@ -69,8 +69,8 @@ $(SIGNATURES)
6969
Construct a DFG factor given a label.
7070
"""
7171
#TODO _internalId?
72-
DFGFactor{T, S}(label::Symbol, _internalId::Int64=0, timestamp::DateTime=now()) where {T, S}
73-
= DFGFactor(label, timestamp, Symbol[], GenericFunctionNodeData{T, S}(), 0, DFGNodeParams(0, _internalId), Symbol[])
72+
DFGFactor{T, S}(label::Symbol, internalId::Int64=0, timestamp::DateTime=now()) where {T, S} =
73+
DFGFactor(label, timestamp, Symbol[], GenericFunctionNodeData{T, S}(), 0, DFGNodeParams(0, internalId), Symbol[])
7474

7575
DFGFactor(label::Symbol;
7676
timestamp::DateTime=now(),

src/entities/DFGVariable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct DFGVariable{T<:InferenceVariable} <: AbstractDFGVariable
2020
timestamp::DateTime
2121
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
2222
Accessors: `getTags`, `addTags!`, and `deleteTags!`"""
23-
tags::Vector{Symbol}
23+
tags::tags::Set{Symbol}#Vector{Symbol} #TODO I propose we use a set since tags can't be repeated.
2424
"""Dictionary of estimates keyed by solverDataDict keys
2525
Accessors: `addEstimate!`, `updateEstimate!`, and `deleteEstimate!`"""
2626
ppeDict::Dict{Symbol, <: AbstractPointParametricEst}

src/sandbox.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
function copyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false; copyGraphMetadata::Bool=false)
3+
# Split into variables and factors
4+
sourceVariables = map(vId->getVariable(sourceDFG, vId), intersect(getVariableIds(sourceDFG), variableFactorLabels))
5+
sourceFactors = map(fId->getFactor(sourceDFG, fId), intersect(getFactorIds(sourceDFG), variableFactorLabels))
6+
if length(sourceVariables) + length(sourceFactors) != length(variableFactorLabels)
7+
rem = symdiff(map(v->v.label, sourceVariables), variableFactorLabels)
8+
rem = symdiff(map(f->f.label, sourceFactors), variableFactorLabels)
9+
error("Cannot copy because cannot find the following nodes in the source graph: $rem")
10+
end
11+
12+
# Now we have to add all variables first,
13+
for variable in sourceVariables
14+
if !exists(destDFG, variable)
15+
addVariable!(destDFG, variable)
16+
end
17+
end
18+
# And then all factors to the destDFG.
19+
for factor in sourceFactors
20+
# Get the original factor variables (we need them to create it)
21+
sourceFactorVariableIds = getNeighbors(sourceDFG, factor)
22+
# Find the labels and associated variables in our new subgraph
23+
factVariableIds = Symbol[]
24+
for variable in sourceFactorVariableIds
25+
if exists(destDFG, variable)
26+
push!(factVariableIds, variable)
27+
end
28+
end
29+
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
30+
if includeOrphanFactors || length(factVariableIds) == length(sourceFactorVariableIds)
31+
if !exists(destDFG, factor)
32+
addFactor!(destDFG, factVariableIds, factor)
33+
end
34+
end
35+
end
36+
37+
if copyGraphMetadata
38+
setUserData(destDFG, getUserData(sourceDFG))
39+
setRobotData(destDFG, getRobotData(sourceDFG))
40+
setSessionData(destDFG, getSessionData(sourceDFG))
41+
end
42+
return nothing
43+
end
44+
45+
function deepcopyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false; copyGraphMetadata::Bool=false)
46+
sourceDFGcopy = deepcopy(sourceDFG)
47+
deepcopyGraph!(destDFG, sourceDFGcopy, union(ls(sourceDFG), lsf(sourceDFG)), includeOrphanFactors, copyGraphMetadata=copyGraphMetadata)
48+
end
49+
50+
function deepcopyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG)
51+
deepcopyGraph!(destDFG, sourceDFG, union(ls(sourceDFG), lsf(sourceDFG)), includeOrphanFactors, copyGraphMetadata=copyGraphMetadata)
52+
end
53+
54+
function deepcopyGraph(::Type{T}, sourceDFG::AbstractDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false; copyGraphMetadata::Bool=false) where T <: AbstractDFG
55+
destDFG = T(getConstructionData(sourceDFG))
56+
deepcopyGraph!(destDFG, sourceDFG, variableFactorLabels, includeOrphanFactors, copyGraphMetadata=copyGraphMetadata)
57+
return destDFG
58+
end
59+
60+
function deepcopyGraph(::Type{T}, sourceDFG::AbstractDFG) where T <: AbstractDFG
61+
destDFG = T(getConstructionData(sourceDFG))
62+
return destDFG
63+
end
64+
65+
Base.convert(::Type{T}, fg::AbstractDFG) where T <: AbstractDFG = deepcopyGraph(T, fg)

src/services/AbstractDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ isSolvable
710710
"""
711711
function getSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default)::Int
712712
# Variable
713-
var isa DFGVariable && return haskey(solverDataDict(var), solveKey) ? solverDataDict(var)[solveKey].solveInProgress : 0
713+
var isa DFGVariable && return haskey(getSolverDataDict(var), solveKey) ? getSolverDataDict(var)[solveKey].solveInProgress : 0
714714
# Factor
715715
return solverData(var).solveInProgress
716716
end

test/interfaceTests.jl

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# global testDFGAPI = GraphsDFG
1+
#
2+
global testDFGAPI = LightDFG
23

34
dfg = testDFGAPI{NoSolverParams}()
45

@@ -21,8 +22,8 @@ st2 = TestInferenceVariable2()
2122
solverData(v1).softtype = deepcopy(st1)
2223
solverData(v2).softtype = deepcopy(st2)
2324

24-
# set v2 solvable
25-
setSolvable!(v2, 1)
25+
# set v1 to solvable=0
26+
setSolvable!(v1, 0)
2627
# set v1 and f1 solveInProgress
2728
solverData(v1).solveInProgress = 1
2829
solverData(f1).solveInProgress = 1
@@ -114,13 +115,14 @@ end
114115
# Gets
115116
@testset "Gets, Sets, and Accessors" begin
116117
global dfg,v1,v2,f1
118+
#TODO compare variable and factor
117119
@test getVariable(dfg, v1.label) == v1
118120
@test getVariable(dfg, v2.label) != v1
119121
@test getFactor(dfg, f1.label) == f1
120122
f2 = deepcopy(f1)
121123
f2.label = :something
122124
@test f2 != f1
123-
@test_throws Exception getVariable(dfg, :nope)
125+
@test getVariable(dfg, :nope) == nothing
124126
@test_throws Exception getVariable(dfg, "nope")
125127
@test_throws Exception getFactor(dfg, :nope)
126128
@test_throws Exception getFactor(dfg, "nope")
@@ -145,6 +147,7 @@ end
145147

146148
@test getTimestamp(v1) == v1.timestamp
147149
testTimestamp = now()
150+
#TODO set timestamp immutable
148151
@test setTimestamp!(v1, testTimestamp) == testTimestamp
149152
@test getTimestamp(v1) == testTimestamp
150153

@@ -158,9 +161,10 @@ end
158161
@test solverData(v1) === v1.solverDataDict[:default]
159162
@test getData(v1) === v1.solverDataDict[:default]
160163
@test solverData(v1, :default) === v1.solverDataDict[:default]
161-
@test solverDataDict(v1) == v1.solverDataDict
162-
@test internalId(v1) == v1._internalId
164+
@test getSolverDataDict(v1) == v1.solverDataDict
165+
@test getInternalId(v1) == v1._internalId
163166

167+
#TODO I don't know what is supposed to happen to softtype
164168
@test getSofttype(v1) == st1
165169
@test getSofttype(v2) == st2
166170
@test getSofttype(v1) == st1
@@ -170,12 +174,12 @@ end
170174
@test setTags!(v1, testTags) == testTags
171175
@test getTags(v1) == testTags
172176

173-
@test solverData(f1) == f1.data
177+
@test solverData(f1) == f1.solverData
174178
# Deprecated functions
175-
@test solverData(f1) == f1.data
176-
@test getData(f1) == f1.data
179+
@test solverData(f1) == f1.solverData
180+
# REMOVED? @test getData(f1) == f1.data
177181
# Internal function
178-
@test internalId(f1) == f1._internalId
182+
@test getInternalId(f1) == f1._dfgNodeParams._internalId
179183

180184
@test getSolverParams(dfg) != nothing
181185
@test setSolverParams(dfg, getSolverParams(dfg)) == getSolverParams(dfg)
@@ -188,8 +192,11 @@ end
188192
@test isSolvable(v1) == 0
189193
@test isSolvable(v2) == 1
190194
@test isSolvable(f1) == 0
191-
@test isSolveInProgress(v1) == 1
192-
@test isSolveInProgress(f1) == 1
195+
@test getSolvable(v1) == 0
196+
197+
#TODO isSolveInProgress was not deprecated
198+
@test getSolveInProgress(v1) == 1
199+
@test getSolveInProgress(f1) == 1
193200
# setSolvable, getSolvable, and variants
194201
v1 = getVariable(dfg, v1.label)
195202
f1 = getFactor(dfg, f1.label)
@@ -280,7 +287,8 @@ end
280287
mergeUpdateVariableSolverData!(dfg, newvar)
281288

282289
#For now spot check
283-
@test solverDataDict(newvar) == solverDataDict(var)
290+
#TODO solverDataDict() not deprecated
291+
@test getSolverDataDict(newvar) == getSolverDataDict(var)
284292
@test getVariablePPEs(newvar) == getVariablePPEs(var)
285293
@test getMaxPPE(getVariablePPEs(newvar)[:default]) == getVariablePPEs(newvar)[:default].max
286294
@test getMeanPPE(getVariablePPEs(newvar)[:default]) == getVariablePPEs(newvar)[:default].mean
@@ -318,7 +326,8 @@ end
318326
@test symdiff(adjMat[1, :], [nothing, :a, :b, :orphan]) == Symbol[]
319327
@test symdiff(adjMat[2, :], [:f1, :f1, :f1, nothing]) == Symbol[]
320328
#sparse
321-
adjMat, v_ll, f_ll = getIncidenceMatrixSparse(dfg)
329+
#TODO this silly name thing has gone on too long
330+
adjMat, v_ll, f_ll = DistributedFactorGraphs.getIncidenceMatrix(dfg)
322331
@test size(adjMat) == (1,3)
323332

324333
# Checking the elements of adjacency, its not sorted so need indexing function
@@ -360,8 +369,9 @@ numNodes = 10
360369
dfg = testDFGAPI{NoSolverParams}()
361370
verts = map(n -> DFGVariable(Symbol("x$n"), TestInferenceVariable1()), 1:numNodes)
362371
#change ready and solveInProgress for x7,x8 for improved tests on x7x8f1
363-
verts[7].solvable = 1
364-
372+
#NOTE because defaults changed
373+
verts[8]._dfgNodeParams.solvable = 0
374+
verts[9]._dfgNodeParams.solvable = 0
365375
# Can't change the softtypes now.
366376
# #force softytypes to first 2 vertices.
367377
# verts[1].solverDataDict[:default].softtype = deepcopy(st1)
@@ -370,6 +380,8 @@ verts[7].solvable = 1
370380
map(v -> addVariable!(dfg, v), verts)
371381
map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol("x$(n)x$(n+1)f1"))), 1:(numNodes-1))
372382

383+
getFactor(dfg, :x7x8f1)._dfgNodeParams.solvable = 0
384+
373385
@testset "Getting Neighbors" begin
374386
global dfg,verts
375387
# Trivial test to validate that intersect([], []) returns order of first parameter
@@ -433,6 +445,7 @@ end
433445
end
434446
end
435447

448+
#TODO Summaries and Summary Graphs
436449
@testset "Summaries and Summary Graphs" begin
437450
factorFields = fieldnames(DFGFactorSummary)
438451
variableFields = fieldnames(DFGVariableSummary)
@@ -471,7 +484,7 @@ end
471484
addVariable!(dotdfg, v1)
472485
addVariable!(dotdfg, v2)
473486
addFactor!(dotdfg, [v1, v2], f1)
474-
487+
#TODO hardcoded will have different results so test LightGraphs seperately
475488
@test toDot(dotdfg) == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"f1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
476489
@test toDotFile(dotdfg, "something.dot") == nothing
477490
Base.rm("something.dot")

0 commit comments

Comments
 (0)