Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 test/interfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@ end
end
end

@testset "Mixing Compute and DFG graph nodes" begin
com_fg = testDFGAPI()
pac_fg = testDFGAPI{NoSolverParams, VariableDFG, FactorDFG}()

v = addVariable!(com_fg, var1)
@test v == var1
pv = addVariable!(pac_fg, v)
@test packVariable(v) == pv

pv = addVariable!(pac_fg, var2)
@test unpackVariable(pv) == var2
v = addVariable!(com_fg, pv)
@test v == var2

f = addFactor!(com_fg, fac0)
@test f == fac0
pf = addFactor!(pac_fg, f)
@test packFactor(f) == pf

pf = addFactor!(pac_fg, fac1)
@test unpackFactor(pf) == fac1
f = addFactor!(com_fg, pf)
@test f == fac1
end
#=
fg = fg1
v1 = var1
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ end
if get(ENV, "IIF_TEST", "true") == "true"

# Switch to our upstream test branch.
#FIXME This is a temporary fix to use the develop branch of AMP.
Pkg.add(PackageSpec(; name = "ApproxManifoldProducts", rev = "develop"))
#FIXME This is a temporary fix to use the develop branch of IIF.
# Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "upstream/dfg_integration_test"))
# Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "develop"))
Expand Down
128 changes: 32 additions & 96 deletions test/testBlocks.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using DistributedFactorGraphs
using Test
using Dates
using Manifolds
using LieGroups
using LieGroups: TranslationGroup
# using Manifolds

using DistributedFactorGraphs:
LabelExistsError,
Expand All @@ -13,61 +15,32 @@ using DistributedFactorGraphs:
import Base: convert
# import DistributedFactorGraphs: getData, addData!, updateData!, deleteData!

Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(1))) = (:Euclid,)
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(2))) = (:Euclid, :Euclid)
# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(1))) = (:Euclid,)
# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(2))) = (:Euclid, :Euclid)

@defVariable TestVariableType1 Euclidean(1) [0.0;]
DFG.@defStateTypeN TestVariableType{N} Euclidean(N) zeros(N)
# define a few varaible to use
@defVariable TestVariableType1 TranslationGroup(1) [0.0;]
DFG.@defStateTypeN TestVariableType{N} TranslationGroup(N) zeros(N)
const TestVariableType2 = TestVariableType{2}

struct TestFunctorInferenceType1 <: AbstractRelative end
struct TestFunctorInferenceType2 <: AbstractRelative end
# define a few factor types to use
DFG.@defObservationType TestFunctorInferenceType1 RelativeObservation TranslationGroup(1)
DFG.@defObservationType TestFunctorInferenceType2 RelativeObservation TranslationGroup(1)
DFG.@defObservationType TestAbstractPrior PriorObservation TranslationGroup(1)

struct TestAbstractPrior <: PriorObservation end
# struct TestAbstractRelativeFactor <: AbstractRelativeRoots end
struct TestAbstractRelativeFactorMinimize <: RelativeObservation end
TestFunctorInferenceType1() = TestFunctorInferenceType1(nothing)
TestFunctorInferenceType2() = TestFunctorInferenceType2(nothing)
TestAbstractPrior() = TestAbstractPrior(nothing)

Base.@kwdef struct PackedTestFunctorInferenceType1 <: AbstractPackedObservation
s::String = ""
end
# PackedTestFunctorInferenceType1() = PackedTestFunctorInferenceType1("")

function Base.convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)
# @info "convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)"
return PackedTestFunctorInferenceType1()
end

function DFG.reconstFactorData(
dfg::AbstractDFG,
vo::AbstractVector,
::Type{TestFunctorInferenceType1},
d::PackedTestFunctorInferenceType1,
::String,
)
error("obsolete, TODO remove")
return TestFunctorInferenceType1()
end

# overly simplified test requires both reconstitute and convert
function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)
# @info "convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)"
return TestFunctorInferenceType1()
end

Base.@kwdef struct PackedTestAbstractPrior <: AbstractPackedObservation
s::String = ""
end
# PackedTestAbstractPrior() = PackedTestAbstractPrior("")

function Base.convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)
# @info "convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)"
return PackedTestAbstractPrior()
struct PackedNothingDistribution <: AbstractPackedBelief
_type::Symbol
function PackedNothingDistribution(; _type::String = "PackedNothingDistribution")
return new(Symbol(_type))
end
end

function Base.convert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior)
# @info "onvert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior)"
return TestAbstractPrior()
end
DFG.packDistribution(::Nothing) = PackedNothingDistribution()
DFG.unpackDistribution(::PackedNothingDistribution) = nothing

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

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

# DFG.rebuildFactorCache!(dfg::AbstractDFG{NoSolverParams}, fac::FactorCompute) = fac

function DFG.reconstFactorData(
dfg::AbstractDFG,
vo::AbstractVector,
::Type{<:DFG.FunctionNodeData{TestCCW{F}}},
d::DFG.PackedFunctionNodeData{<:AbstractPackedObservation},
) where {F <: DFG.AbstractObservation}
error("obsolete, TODO remove")
nF = convert(F, d.fnc)
return DFG.FunctionNodeData(
d.eliminated,
d.potentialused,
d.edgeIDs,
TestCCW(nF),
d.multihypo,
d.certainhypo,
d.nullhypo,
d.solveInProgress,
d.inflation,
)
end

function Base.convert(
::Type{DFG.PackedFunctionNodeData{P}},
d::DFG.FunctionNodeData{<:FactorCache},
) where {P <: AbstractPackedObservation}
return DFG.PackedFunctionNodeData(
d.eliminated,
d.potentialused,
d.edgeIDs,
convert(P, d.fnc.usrfnc!),
d.multihypo,
d.certainhypo,
d.nullhypo,
d.solveInProgress,
d.inflation,
)
end

##
# global testDFGAPI = GraphsDFG
# T = testDFGAPI
Expand Down Expand Up @@ -357,7 +290,7 @@ function DFGVariableSCA()
#variableType functions
testvar = TestVariableType1()
@test getDimension(testvar) == 1
@test getManifold(testvar) == Euclidean(1)
@test getManifold(testvar) == TranslationGroup(1)

# #TODO sort out
# getPPEs
Expand Down Expand Up @@ -410,8 +343,8 @@ function DFGFactorSCA()
@test setSolvable!(f1, 1) == 1

#TODO These 2 function are equivelent
@test typeof(getFactorType(f1)) == TestFunctorInferenceType1
@test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1
@test typeof(getFactorType(f1)) == TestFunctorInferenceType1{Nothing}
@test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1{Nothing}

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

@test issetequal([TestFunctorInferenceType1, TestAbstractPrior], DFG.lsfTypes(fg))
@test issetequal(
[TestFunctorInferenceType1{Nothing}, TestAbstractPrior{Nothing}],
DFG.lsfTypes(fg),
)

facTypesDict = DFG.lsfTypesDict(fg)
@test issetequal(collect(keys(facTypesDict)), DFG.lsfTypes(fg))
@test issetequal(facTypesDict[TestFunctorInferenceType1], [:abf1])
@test issetequal(facTypesDict[TestAbstractPrior], [:af1])
@test issetequal(facTypesDict[TestFunctorInferenceType1{Nothing}], [:abf1])
@test issetequal(facTypesDict[TestAbstractPrior{Nothing}], [:af1])

@test ls(fg, TestFunctorInferenceType1) == [:abf1]
@test lsf(fg, TestAbstractPrior) == [:af1]
Expand Down Expand Up @@ -1672,7 +1608,7 @@ function ProducingDotFiles(
@test DFG.toDot(dotdfg) ==
"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"
end
@test DFG.toDotFile(dotdfg, "something.dot") == nothing
@test DFG.toDotFile(dotdfg, "something.dot") === nothing
return Base.rm("something.dot")
end

Expand Down
Loading