Skip to content

Commit 3d90bf7

Browse files
committed
WIP
1 parent 1ff276e commit 3d90bf7

File tree

3 files changed

+242
-60
lines changed

3 files changed

+242
-60
lines changed

src/services/DFGVariable.jl

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,62 @@ function compare(a::VariableNodeData, b::VariableNodeData)
9292
TP = TP && a.eliminated == b.eliminated
9393
TP = TP && a.BayesNetVertID == b.BayesNetVertID
9494
TP = TP && a.separator == b.separator
95+
TP = TP && a.initialized == b.initialized
9596
TP = TP && abs(a.inferdim - b.inferdim) < 1e-14
9697
TP = TP && a.ismargin == b.ismargin
97-
TP = TP && a.softtype == b.softtype
98+
TP = TP && a.dontmargin == b.dontmargin
99+
TP = TP && typeof(a.softtype) == typeof(b.softtype) # Can't do equals, need to check type.
98100
return TP
99101
end
100102

103+
"""
104+
$(SIGNATURES)
105+
Equality check for VariableNodeData.
106+
"""
101107
function ==(a::VariableNodeData,b::VariableNodeData, nt::Symbol=:var)
102108
return DistributedFactorGraphs.compare(a,b)
103109
end
104110

111+
"""
112+
$(SIGNATURES)
113+
Equality check for VariableEstimate.
114+
"""
115+
function ==(a::VariableEstimate, b::VariableEstimate)::Bool
116+
a.solverKey != b.solverKey && return false
117+
a.type != b.type && return false
118+
a.estimate != b.estimate && return false
119+
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && return false
120+
return true
121+
end
122+
123+
"""
124+
$(SIGNATURES)
125+
Equality check for DFGVariable.
126+
"""
127+
function ==(a::DFGVariable, b::DFGVariable)::Bool
128+
a.label != b.label && return false
129+
a.timestamp != b.timestamp && return false
130+
a.tags != b.tags && return false
131+
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && return false
132+
for k in keys(a.estimateDict)
133+
a.estimateDict[k] != b.estimateDict[k] && return false
134+
end
135+
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != [] && return false
136+
for k in keys(a.solverDataDict)
137+
a.solverDataDict[k] != b.solverDataDict[k] && return false
138+
end
139+
a.smallData != b.smallData && return false
140+
a.bigData != b.bigData && return false
141+
a.ready != b.ready && return false
142+
a.backendset != b.backendset && return false
143+
a._internalId != b._internalId && return false
144+
return true
145+
end
146+
147+
"""
148+
$(SIGNATURES)
149+
Convert a DFGVariable to a DFGVariableSummary.
150+
"""
105151
function convert(::Type{DFGVariableSummary}, v::DFGVariable)
106152
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.estimateDict), v._internalId)
107153
end

test/runtests.jl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ using Pkg
1212

1313
# Instantiate the APIs that you would like to test here
1414
# Can do duplicates with different parameters.
15-
apis = [
16-
GraphsDFG{NoSolverParams}(),
17-
LightDFG{NoSolverParams}(),
18-
DistributedFactorGraphs.MetaGraphsDFG{NoSolverParams}(),
19-
DistributedFactorGraphs.SymbolDFG{NoSolverParams}()
20-
]
21-
for api in apis
22-
@testset "Testing Driver: $(typeof(api))" begin
23-
@info "Testing Driver: $(api)"
24-
global dfg = deepcopy(api)
25-
include("interfaceTests.jl")
26-
end
27-
end
15+
# apis = [
16+
# GraphsDFG{NoSolverParams}(),
17+
# LightDFG{NoSolverParams}(),
18+
# DistributedFactorGraphs.MetaGraphsDFG{NoSolverParams}(),
19+
# DistributedFactorGraphs.SymbolDFG{NoSolverParams}()
20+
# ]
21+
# for api in apis
22+
# @testset "Testing Driver: $(typeof(api))" begin
23+
# @info "Testing Driver: $(api)"
24+
# global dfg = deepcopy(api)
25+
# include("interfaceTests.jl")
26+
# end
27+
# end
2828

2929
if haskey(Pkg.installed(), "IncrementalInference")
3030
@info "------------------------------------------------------------------------"
@@ -34,17 +34,17 @@ if haskey(Pkg.installed(), "IncrementalInference")
3434
using IncrementalInference
3535

3636
apis = [
37-
GraphsDFG{NoSolverParams}(),
38-
LightDFG{NoSolverParams}(),
37+
# GraphsDFG{NoSolverParams}(),
38+
# LightDFG{NoSolverParams}(),
3939
# MetaGraphsDFG{NoSolverParams}(),
4040
# SymbolDFG{NoSolverParams}(),
41-
# CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
42-
# "testUser", "testRobot", "testSession",
43-
# nothing,
44-
# nothing,
45-
# IncrementalInference.decodePackedType,
46-
# IncrementalInference.rebuildFactorMetadata!,
47-
# solverParams=SolverParams())
41+
CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
42+
"testUser", "testRobot", "testSession",
43+
nothing,
44+
nothing,
45+
IncrementalInference.decodePackedType,
46+
IncrementalInference.rebuildFactorMetadata!,
47+
solverParams=SolverParams())
4848
]
4949
for api in apis
5050
@testset "Testing Driver: $(typeof(api))" begin
@@ -58,18 +58,18 @@ else
5858
end
5959

6060
# Test that we don't export LightDFG and MetaGraphsDFG
61-
@testset "Deprecated Drivers Test" begin
62-
@test_throws UndefVarError SymbolDFG{NoSolverParams}()
63-
@test_throws UndefVarError MetaGraphsDFG{NoSolverParams}()
64-
end
65-
66-
# Test special cases
67-
68-
@testset "Plotting Tests" begin
69-
include("plottingTest.jl")
70-
end
71-
72-
@testset "SummaryDFG test" begin
73-
@info "Testing LightDFG Variable and Factor Subtypes"
74-
include("LightDFGSummaryTypes.jl")
75-
end
61+
# @testset "Deprecated Drivers Test" begin
62+
# @test_throws UndefVarError SymbolDFG{NoSolverParams}()
63+
# @test_throws UndefVarError MetaGraphsDFG{NoSolverParams}()
64+
# end
65+
#
66+
# # Test special cases
67+
#
68+
# @testset "Plotting Tests" begin
69+
# include("plottingTest.jl")
70+
# end
71+
#
72+
# @testset "SummaryDFG test" begin
73+
# @info "Testing LightDFG Variable and Factor Subtypes"
74+
# include("LightDFGSummaryTypes.jl")
75+
# end

test/sandbox.jl

Lines changed: 158 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,160 @@
1-
using Revise
1+
# using Revise
2+
using Neo4j
23
using DistributedFactorGraphs
4+
using IncrementalInference
5+
using Test
36

4-
dfg = GraphsDFG{NoSolverParams}()
5-
v1 = DFGVariable(:a)
6-
v2 = DFGVariable(:b)
7-
v3 = DFGVariable(:c)
8-
f1 = DFGFactor{Int, :Symbol}(:f1)
9-
f2 = DFGFactor{Int, :Symbol}(:f2)
10-
addVariable!(dfg, v1)
11-
addVariable!(dfg, v2)
12-
addVariable!(dfg, v3)
13-
addFactor!(dfg, [v1, v2], f1)
14-
addFactor!(dfg, [:b, :c], f2)
15-
dfg
16-
dfg.g.inclist
17-
fieldnames(typeof(dfg.g))
18-
dfg.g.vertices
19-
summ = getSummary(dfg)
20-
summaryGraph = getSummaryGraph(dfg)
21-
ls(summaryGraph)
22-
lsf(summaryGraph)
23-
getVariable(summaryGraph, :a)
24-
getFactor(summaryGraph, :f1)
7+
dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
8+
"testUser", "testRobot", "testSession",
9+
nothing,
10+
nothing,
11+
IncrementalInference.decodePackedType,
12+
IncrementalInference.rebuildFactorMetadata!,
13+
solverParams=SolverParams())
14+
clearRobot!!(dfg)
15+
v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
16+
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
17+
f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )
18+
v1 == deepcopy(v1)
19+
20+
function al(a, b)
21+
a.label != b.label && return false
22+
a.timestamp != b.timestamp && return false
23+
a.tags != b.tags && return false
24+
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && return false
25+
for k in keys(a.estimateDict)
26+
a.estimateDict[k] != b.estimateDict[k] && return false
27+
end
28+
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != Set(Symbol[]) && return false
29+
for k in keys(a.solverDataDict)
30+
a.solverDataDict[k] != b.solverDataDict[k] && return false
31+
end
32+
return true
33+
end
34+
al(a, b)
35+
a = v1
36+
b = deepcopy(v1)
37+
38+
a.smallData != b.smallData && return false
39+
a.bigData != b.bigData && return false
40+
a.ready != b.ready && return false
41+
a.backendset != b.backendset && return false
42+
a._internalId != b._internalId && return false
43+
44+
T = typeof(dfg)
45+
if T <: CloudGraphsDFG
46+
dfg2 = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
47+
"testUser", "testRobot", "testSession2",
48+
nothing,
49+
nothing,
50+
IncrementalInference.decodePackedType,
51+
IncrementalInference.rebuildFactorMetadata!,
52+
solverParams=SolverParams())
53+
else
54+
dfg2 = T()
55+
end
56+
iiffg = initfg()
57+
v1 = deepcopy(addVariable!(iiffg, :a, ContinuousScalar))
58+
v2 = deepcopy(addVariable!(iiffg, :b, ContinuousScalar))
59+
v3 = deepcopy(addVariable!(iiffg, :c, ContinuousScalar))
60+
f1 = deepcopy(addFactor!(iiffg, [:a; :b], LinearConditional(Normal(50.0,2.0)) ))
61+
f2 = deepcopy(addFactor!(iiffg, [:b; :c], LinearConditional(Normal(10.0,1.0)) ))
62+
63+
# @testset "Creating Graphs" begin
64+
@test addVariable!(dfg2, v1)
65+
@test addVariable!(dfg2, v2)
66+
@test_throws ErrorException updateVariable!(dfg2, v3)
67+
@test addVariable!(dfg2, v3)
68+
@test_throws ErrorException addVariable!(dfg2, v3)
69+
@test addFactor!(dfg2, [v1, v2], f1)
70+
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
71+
@test_throws ErrorException updateFactor!(dfg2, f2)
72+
@test addFactor!(dfg2, [:b, :c], f2)
73+
74+
dv3 = deleteVariable!(dfg2, v3)
75+
#TODO write compare if we want to compare complete one, for now just label
76+
# @test dv3 == v3
77+
@test dv3.label == v3.label
78+
@test_throws ErrorException deleteVariable!(dfg2, v3)
79+
80+
@test symdiff(ls(dfg2),[:a,:b]) == []
81+
df2 = deleteFactor!(dfg2, f2)
82+
#TODO write compare if we want to compare complete one, for now just label
83+
# @test df2 == f2
84+
@test df2.label == f2.label
85+
@test_throws ErrorException deleteFactor!(dfg2, f2)
86+
87+
@test lsf(dfg2) == [:abf1]
88+
89+
@test length(ls(dfg)) == 2
90+
@test length(lsf(dfg)) == 1 # Unless we add the prior!
91+
@test symdiff([:a, :b], getVariableIds(dfg)) == []
92+
@test getFactorIds(dfg) == [:abf1] # Unless we add the prior!
93+
#
94+
@test lsf(dfg, :a) == [f1.label]
95+
# Tags
96+
@test ls(dfg, tags=[:POSE]) == [:a]
97+
@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == []
98+
# Regexes
99+
@test ls(dfg, r"a") == [v1.label]
100+
# TODO: Check that this regular expression works on everything else!
101+
# it works with the .
102+
# REF: https://stackoverflow.com/questions/23834692/using-regular-expression-in-neo4j
103+
@test lsf(dfg, r"abf.*") == [f1.label]
104+
105+
# Accessors
106+
@test getAddHistory(dfg) == [:a, :b] #, :abf1
107+
@test getDescription(dfg) != nothing
108+
@test getLabelDict(dfg) != nothing
109+
# Existence
110+
@test exists(dfg, :a) == true
111+
@test exists(dfg, v1) == true
112+
@test exists(dfg, :nope) == false
113+
# Sorting of results
114+
# TODO - this function needs to be cleaned up
115+
unsorted = [:x1_3;:x1_6;:l1;:april1] #this will not work for :x1x2f1
116+
@test sortDFG(unsorted) == sortVarNested(unsorted)
117+
@test_skip sortDFG([:x1x2f1, :x1l1f1]) == [:x1l1f1, :x1x2f1]
118+
119+
@test getVariable(dfg, v1.label) == v1
120+
@test getFactor(dfg, f1.label) == f1
121+
@test_throws Exception getVariable(dfg, :nope)
122+
@test_throws Exception getVariable(dfg, "nope")
123+
@test_throws Exception getFactor(dfg, :nope)
124+
@test_throws Exception getFactor(dfg, "nope")
125+
126+
# Sets
127+
v1Prime = deepcopy(v1)
128+
@test updateVariable!(dfg, v1Prime) != v1
129+
f1Prime = deepcopy(f1)
130+
@test updateFactor!(dfg, f1Prime) != f1
131+
132+
# Accessors
133+
@test label(v1) == v1.label
134+
@test tags(v1) == v1.tags
135+
@test timestamp(v1) == v1.timestamp
136+
@test estimates(v1) == v1.estimateDict
137+
@test DistributedFactorGraphs.estimate(v1, :notfound) == nothing
138+
@test solverData(v1) === v1.solverDataDict[:default]
139+
@test getData(v1) === v1.solverDataDict[:default]
140+
@test solverData(v1, :default) === v1.solverDataDict[:default]
141+
@test solverDataDict(v1) == v1.solverDataDict
142+
@test internalId(v1) == v1._internalId
143+
144+
@test label(f1) == f1.label
145+
@test tags(f1) == f1.tags
146+
@test solverData(f1) == f1.data
147+
# Deprecated functions
148+
@test data(f1) == f1.data
149+
@test getData(f1) == f1.data
150+
# Internal function
151+
@test internalId(f1) == f1._internalId
152+
153+
@test getSolverParams(dfg) != nothing
154+
@test setSolverParams(dfg, getSolverParams(dfg)) == getSolverParams(dfg)
155+
156+
#solver data is initialized
157+
@test !isInitialized(dfg, :a)
158+
@test !isInitialized(v2)
159+
160+
@test !isInitialized(v2, key=:second)

0 commit comments

Comments
 (0)