Skip to content

Commit e205815

Browse files
authored
Update tests and more maintanance (#1169)
* Update tests to factortype macros and test mixing Compute and DFG * Temporary test agains ApproxManifoldProducts develop branch
1 parent 762cb01 commit e205815

File tree

3 files changed

+58
-96
lines changed

3 files changed

+58
-96
lines changed

test/interfaceTests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,30 @@ end
219219
end
220220
end
221221

222+
@testset "Mixing Compute and DFG graph nodes" begin
223+
com_fg = testDFGAPI()
224+
pac_fg = testDFGAPI{NoSolverParams, VariableDFG, FactorDFG}()
225+
226+
v = addVariable!(com_fg, var1)
227+
@test v == var1
228+
pv = addVariable!(pac_fg, v)
229+
@test packVariable(v) == pv
230+
231+
pv = addVariable!(pac_fg, var2)
232+
@test unpackVariable(pv) == var2
233+
v = addVariable!(com_fg, pv)
234+
@test v == var2
235+
236+
f = addFactor!(com_fg, fac0)
237+
@test f == fac0
238+
pf = addFactor!(pac_fg, f)
239+
@test packFactor(f) == pf
240+
241+
pf = addFactor!(pac_fg, fac1)
242+
@test unpackFactor(pf) == fac1
243+
f = addFactor!(com_fg, pf)
244+
@test f == fac1
245+
end
222246
#=
223247
fg = fg1
224248
v1 = var1

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ end
6363
if get(ENV, "IIF_TEST", "true") == "true"
6464

6565
# Switch to our upstream test branch.
66+
#FIXME This is a temporary fix to use the develop branch of AMP.
67+
Pkg.add(PackageSpec(; name = "ApproxManifoldProducts", rev = "develop"))
6668
#FIXME This is a temporary fix to use the develop branch of IIF.
6769
# Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "upstream/dfg_integration_test"))
6870
# Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "develop"))

test/testBlocks.jl

Lines changed: 32 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using DistributedFactorGraphs
22
using Test
33
using Dates
4-
using Manifolds
4+
using LieGroups
5+
using LieGroups: TranslationGroup
6+
# using Manifolds
57

68
using DistributedFactorGraphs:
79
LabelExistsError,
@@ -13,61 +15,32 @@ using DistributedFactorGraphs:
1315
import Base: convert
1416
# import DistributedFactorGraphs: getData, addData!, updateData!, deleteData!
1517

16-
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(1))) = (:Euclid,)
17-
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(2))) = (:Euclid, :Euclid)
18+
# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(1))) = (:Euclid,)
19+
# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(2))) = (:Euclid, :Euclid)
1820

19-
@defVariable TestVariableType1 Euclidean(1) [0.0;]
20-
DFG.@defStateTypeN TestVariableType{N} Euclidean(N) zeros(N)
21+
# define a few varaible to use
22+
@defVariable TestVariableType1 TranslationGroup(1) [0.0;]
23+
DFG.@defStateTypeN TestVariableType{N} TranslationGroup(N) zeros(N)
2124
const TestVariableType2 = TestVariableType{2}
2225

23-
struct TestFunctorInferenceType1 <: AbstractRelative end
24-
struct TestFunctorInferenceType2 <: AbstractRelative end
26+
# define a few factor types to use
27+
DFG.@defObservationType TestFunctorInferenceType1 RelativeObservation TranslationGroup(1)
28+
DFG.@defObservationType TestFunctorInferenceType2 RelativeObservation TranslationGroup(1)
29+
DFG.@defObservationType TestAbstractPrior PriorObservation TranslationGroup(1)
2530

26-
struct TestAbstractPrior <: PriorObservation end
27-
# struct TestAbstractRelativeFactor <: AbstractRelativeRoots end
28-
struct TestAbstractRelativeFactorMinimize <: RelativeObservation end
31+
TestFunctorInferenceType1() = TestFunctorInferenceType1(nothing)
32+
TestFunctorInferenceType2() = TestFunctorInferenceType2(nothing)
33+
TestAbstractPrior() = TestAbstractPrior(nothing)
2934

30-
Base.@kwdef struct PackedTestFunctorInferenceType1 <: AbstractPackedObservation
31-
s::String = ""
32-
end
33-
# PackedTestFunctorInferenceType1() = PackedTestFunctorInferenceType1("")
34-
35-
function Base.convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)
36-
# @info "convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)"
37-
return PackedTestFunctorInferenceType1()
38-
end
39-
40-
function DFG.reconstFactorData(
41-
dfg::AbstractDFG,
42-
vo::AbstractVector,
43-
::Type{TestFunctorInferenceType1},
44-
d::PackedTestFunctorInferenceType1,
45-
::String,
46-
)
47-
error("obsolete, TODO remove")
48-
return TestFunctorInferenceType1()
49-
end
50-
51-
# overly simplified test requires both reconstitute and convert
52-
function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)
53-
# @info "convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)"
54-
return TestFunctorInferenceType1()
55-
end
56-
57-
Base.@kwdef struct PackedTestAbstractPrior <: AbstractPackedObservation
58-
s::String = ""
59-
end
60-
# PackedTestAbstractPrior() = PackedTestAbstractPrior("")
61-
62-
function Base.convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)
63-
# @info "convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)"
64-
return PackedTestAbstractPrior()
35+
struct PackedNothingDistribution <: AbstractPackedBelief
36+
_type::Symbol
37+
function PackedNothingDistribution(; _type::String = "PackedNothingDistribution")
38+
return new(Symbol(_type))
39+
end
6540
end
6641

67-
function Base.convert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior)
68-
# @info "onvert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior)"
69-
return TestAbstractPrior()
70-
end
42+
DFG.packDistribution(::Nothing) = PackedNothingDistribution()
43+
DFG.unpackDistribution(::PackedNothingDistribution) = nothing
7144

7245
struct TestCCW{T <: AbstractObservation} <: FactorCache
7346
usrfnc!::T
@@ -77,46 +50,6 @@ TestCCW{T}() where {T} = TestCCW(T())
7750

7851
Base.:(==)(a::TestCCW, b::TestCCW) = a.usrfnc! == b.usrfnc!
7952

80-
# DFG.rebuildFactorCache!(dfg::AbstractDFG{NoSolverParams}, fac::FactorCompute) = fac
81-
82-
function DFG.reconstFactorData(
83-
dfg::AbstractDFG,
84-
vo::AbstractVector,
85-
::Type{<:DFG.FunctionNodeData{TestCCW{F}}},
86-
d::DFG.PackedFunctionNodeData{<:AbstractPackedObservation},
87-
) where {F <: DFG.AbstractObservation}
88-
error("obsolete, TODO remove")
89-
nF = convert(F, d.fnc)
90-
return DFG.FunctionNodeData(
91-
d.eliminated,
92-
d.potentialused,
93-
d.edgeIDs,
94-
TestCCW(nF),
95-
d.multihypo,
96-
d.certainhypo,
97-
d.nullhypo,
98-
d.solveInProgress,
99-
d.inflation,
100-
)
101-
end
102-
103-
function Base.convert(
104-
::Type{DFG.PackedFunctionNodeData{P}},
105-
d::DFG.FunctionNodeData{<:FactorCache},
106-
) where {P <: AbstractPackedObservation}
107-
return DFG.PackedFunctionNodeData(
108-
d.eliminated,
109-
d.potentialused,
110-
d.edgeIDs,
111-
convert(P, d.fnc.usrfnc!),
112-
d.multihypo,
113-
d.certainhypo,
114-
d.nullhypo,
115-
d.solveInProgress,
116-
d.inflation,
117-
)
118-
end
119-
12053
##
12154
# global testDFGAPI = GraphsDFG
12255
# T = testDFGAPI
@@ -357,7 +290,7 @@ function DFGVariableSCA()
357290
#variableType functions
358291
testvar = TestVariableType1()
359292
@test getDimension(testvar) == 1
360-
@test getManifold(testvar) == Euclidean(1)
293+
@test getManifold(testvar) == TranslationGroup(1)
361294

362295
# #TODO sort out
363296
# getPPEs
@@ -410,8 +343,8 @@ function DFGFactorSCA()
410343
@test setSolvable!(f1, 1) == 1
411344

412345
#TODO These 2 function are equivelent
413-
@test typeof(getFactorType(f1)) == TestFunctorInferenceType1
414-
@test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1
346+
@test typeof(getFactorType(f1)) == TestFunctorInferenceType1{Nothing}
347+
@test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1{Nothing}
415348

416349
#TODO here for now, don't recommend usage.
417350
testTags = [:tag1, :tag2]
@@ -1148,12 +1081,15 @@ function testGroup!(fg, v1, v2, f0, f1)
11481081
@test isPrior(fg, :af1) # if f1 is prior
11491082
@test lsfPriors(fg) == [:af1]
11501083

1151-
@test issetequal([TestFunctorInferenceType1, TestAbstractPrior], DFG.lsfTypes(fg))
1084+
@test issetequal(
1085+
[TestFunctorInferenceType1{Nothing}, TestAbstractPrior{Nothing}],
1086+
DFG.lsfTypes(fg),
1087+
)
11521088

11531089
facTypesDict = DFG.lsfTypesDict(fg)
11541090
@test issetequal(collect(keys(facTypesDict)), DFG.lsfTypes(fg))
1155-
@test issetequal(facTypesDict[TestFunctorInferenceType1], [:abf1])
1156-
@test issetequal(facTypesDict[TestAbstractPrior], [:af1])
1091+
@test issetequal(facTypesDict[TestFunctorInferenceType1{Nothing}], [:abf1])
1092+
@test issetequal(facTypesDict[TestAbstractPrior{Nothing}], [:af1])
11571093

11581094
@test ls(fg, TestFunctorInferenceType1) == [:abf1]
11591095
@test lsf(fg, TestAbstractPrior) == [:af1]
@@ -1672,7 +1608,7 @@ function ProducingDotFiles(
16721608
@test DFG.toDot(dotdfg) ==
16731609
"graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
16741610
end
1675-
@test DFG.toDotFile(dotdfg, "something.dot") == nothing
1611+
@test DFG.toDotFile(dotdfg, "something.dot") === nothing
16761612
return Base.rm("something.dot")
16771613
end
16781614

0 commit comments

Comments
 (0)