Skip to content

Commit ef36fd2

Browse files
committed
Merge branch 'feature/IIFTest2' into jt/develop
2 parents 41ecee3 + 219124d commit ef36fd2

File tree

5 files changed

+118
-100
lines changed

5 files changed

+118
-100
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ MetaGraphs = "≥ 0.6.4"
2525
Reexport = "≥ 0.2"
2626
Requires = "≥ 0.5"
2727
julia = "0.7, 1"
28+
IncrementalInference = "0.7.7"
2829

2930
[extras]
3031
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ Add a DFGVariable to a DFG.
158158
"""
159159
function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::Bool
160160
if exists(dfg, variable)
161-
@warn "Variable '$(variable.label)' already exists in the graph, so updating it."
162-
updateVariable!(dfg, variable)
163-
return true
161+
error("Variable '$(variable.label)' already exists in the factor graph")
164162
end
165163
props = Dict{String, Any}()
166164
props["label"] = string(variable.label)
@@ -192,9 +190,7 @@ Add a DFGFactor to a DFG.
192190
"""
193191
function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor::DFGFactor)::Bool
194192
if exists(dfg, factor)
195-
@warn "Factor '$(factor.label)' already exist in the graph, so updating it."
196-
updateFactor!(dfg, variables, factor)
197-
return true
193+
error("Factor '$(factor.label)' already exists in the factor graph")
198194
end
199195

200196
# Update the variable ordering
@@ -363,9 +359,7 @@ Update a complete DFGVariable in the DFG.
363359
"""
364360
function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariable
365361
if !exists(dfg, variable)
366-
@warn "Variable '$(variable.label)' doesn't exist in the graph, so adding it."
367-
addVariable!(dfg, variable)
368-
return variable
362+
error("Variable label '$(variable.label)' does not exist in the factor graph")
369363
end
370364
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, variable.label)
371365
# Update the node ID
@@ -409,9 +403,7 @@ Update a complete DFGFactor in the DFG.
409403
"""
410404
function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
411405
if !exists(dfg, factor)
412-
@warn "Factor '$(factor.label)' doesn't exist in the graph, so adding it."
413-
addFactor!(dfg, factor)
414-
return factor
406+
error("Factor label '$(factor.label)' does not exist in the factor graph")
415407
end
416408
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, factor.label)
417409
# Update the _internalId
@@ -552,9 +544,15 @@ deleteFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!
552544
List the DFGVariables in the DFG.
553545
Optionally specify a label regular expression to retrieves a subset of the variables.
554546
"""
555-
function getVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable}
547+
function getVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable}
556548
variableIds = getVariableIds(dfg, regexFilter)
557-
return map(vId->getVariable(dfg, vId), variableIds)
549+
# TODO: Optimize to use tags in query here!
550+
variables = map(vId->getVariable(dfg, vId), variableIds)
551+
if length(tags) > 0
552+
mask = map(v -> length(intersect(v.tags, tags)) > 0, variables )
553+
return variables[mask]
554+
end
555+
return variables
558556
end
559557

560558
"""

src/services/AbstractDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ function isInitialized(var::DFGVariable; key::Symbol=:default)::Bool
525525
end
526526
end
527527

528-
function isInitialized(dfg::G, label::Symbol; key::Symbol=:default)::Bool where G <: AbstractDFG
528+
function isInitialized(dfg::AbstractDFG, label::Symbol; key::Symbol=:default)::Bool
529529
return isInitialized(getVariable(dfg, label), key=key)
530530
end
531531

test/iifInterfaceTests.jl

Lines changed: 87 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,106 +3,108 @@
33
# using DistributedFactorGraphs
44
# using IncrementalInference
55
# using Test
6-
# testDFGAPI = CloudGraphsDFG
7-
8-
if testDFGAPI == CloudGraphsDFG
9-
DistributedFactorGraphs.CloudGraphsDFG{SolverParams}() = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
10-
"testUser", "testRobot", "testSession",
11-
nothing,
12-
nothing,
13-
IncrementalInference.decodePackedType,
14-
IncrementalInference.rebuildFactorMetadata!,
15-
solverParams=SolverParams())
6+
# dfg = apis[1]
167

8+
global dfg,v1,v2,f1
179

18-
dfg = testDFGAPI{SolverParams}()
10+
if typeof(dfg) <: CloudGraphsDFG
11+
@warn "TEST: Nuking all data for robot $(dfg.robotId)!"
1912
clearRobot!!(dfg)
20-
else
21-
dfg = testDFGAPI{NoSolverParams}()
2213
end
2314

24-
25-
v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
26-
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
27-
f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )
28-
# f1 = addFactor!(fg,[:x0], Prior( pd ) )
29-
30-
# @testset "Creating Graphs" begin
31-
global dfg,v1,v2,f1
32-
33-
@test_throws Exception addFactor!(dfg, DFGFactor{Int, :Symbol}("f2"), [v1, DFGVariable("Nope")])
34-
# end
15+
# Building simple graph...
16+
@testset "Building a simple Graph" begin
17+
global dfg,v1,v2,f1
18+
# Use IIF to add the variables and factors
19+
v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
20+
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
21+
f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )
22+
# f1 = addFactor!(fg,[:x0], Prior( pd ) )
23+
# @test_throws Exception addFactor!(dfg, DFGFactor{Int, :Symbol}("f2"), [v1, DFGVariable("Nope")])
24+
end
3525

3626
#test before anything changes
3727
@testset "Producing Dot Files" begin
38-
39-
@test toDot(dfg) == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"box\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"ellipse\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"box\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
28+
global dfg
29+
todotstr = toDot(dfg)
30+
#TODO consider using a regex, but for now test both orders
31+
todota = todotstr == "graph graphname {\n2 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
32+
todotb = todotstr == "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"
33+
@test (todota || todotb)
4034
@test toDotFile(dfg, "something.dot") == nothing
4135
Base.rm("something.dot")
42-
4336
end
4437

45-
@testset "Adding Removing Nodes" begin
46-
#TODO should errors vs updates be consistant between DFG types
47-
if testDFGAPI != CloudGraphsDFG
48-
dfg2 = testDFGAPI{NoSolverParams}()
49-
v1 = DFGVariable(:a)
50-
v2 = DFGVariable(:b)
51-
v3 = DFGVariable(:c)
52-
f1 = DFGFactor{ContinuousScalar, :Symbol}(:abf1)
53-
f2 = DFGFactor{ContinuousScalar, :Symbol}(:f2)
54-
# @testset "Creating Graphs" begin
55-
@test addVariable!(dfg2, v1)
56-
@test addVariable!(dfg2, v2)
57-
@test_throws ErrorException updateVariable!(dfg2, v3)
58-
@test addVariable!(dfg2, v3)
59-
@test_throws ErrorException addVariable!(dfg2, v3)
60-
@test addFactor!(dfg2, [v1, v2], f1)
61-
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
62-
@test_throws ErrorException updateFactor!(dfg2, f2)
63-
@test addFactor!(dfg2, [:b, :c], f2)
64-
@test deleteVariable!(dfg2, v3) == v3
65-
@test symdiff(ls(dfg2),[:a,:b]) == []
66-
@test deleteFactor!(dfg2, f2) == f2
67-
@test lsf(dfg2) == [:abf1]
38+
@testset "Testing CRUD, return and Failures from a GraphsDFG" begin
39+
global dfg
40+
# fg to copy to
41+
# creating a whole new graph with the same labels
42+
T = typeof(dfg)
43+
if T <: CloudGraphsDFG
44+
dfg2 = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
45+
"testUser", "testRobot", "testSession2",
46+
nothing,
47+
nothing,
48+
IncrementalInference.decodePackedType,
49+
IncrementalInference.rebuildFactorMetadata!,
50+
solverParams=SolverParams())
6851
else
69-
dfg2 = testDFGAPI{SolverParams}()
70-
v1 = DFGVariable(:a)
71-
v2 = DFGVariable(:b)
72-
v3 = DFGVariable(:c)
73-
f1 = DFGFactor{ContinuousScalar, :Symbol}(:abf1)
74-
f2 = DFGFactor{ContinuousScalar, :Symbol}(:f2)
75-
76-
@test addVariable!(dfg2, v1)
77-
@test addVariable!(dfg2, v2)
78-
@test_throws ErrorException updateVariable!(dfg2, v3)
79-
@test addVariable!(dfg2, v3)
80-
@test_skip @test_throws ErrorException addVariable!(dfg2, v3)
81-
@test_skip addFactor!(dfg2, [v1, v2], f1)
82-
@test_skip @test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
83-
@test_skip @test_throws ErrorException updateFactor!(dfg2, f2)
84-
@test_skip addFactor!(dfg2, [:b, :c], f2)
85-
@test deleteVariable!(dfg2, v3) == v3 #FIXME ? one returns nothing other ""
86-
@test symdiff(ls(dfg2),[:a,:b]) == []
87-
@test_skip deleteFactor!(dfg2, f2) == f2
88-
@test_skip lsf(dfg2) == [:abf1]
52+
dfg2 = T()
8953
end
54+
55+
iiffg = initfg()
56+
v1 = deepcopy(addVariable!(iiffg, :a, ContinuousScalar))
57+
v2 = deepcopy(addVariable!(iiffg, :b, ContinuousScalar))
58+
v3 = deepcopy(addVariable!(iiffg, :c, ContinuousScalar))
59+
f1 = deepcopy(addFactor!(iiffg, [:a; :b], LinearConditional(Normal(50.0,2.0)) ))
60+
f2 = deepcopy(addFactor!(iiffg, [:b; :c], LinearConditional(Normal(10.0,1.0)) ))
61+
62+
# @testset "Creating Graphs" begin
63+
@test addVariable!(dfg2, v1)
64+
@test addVariable!(dfg2, v2)
65+
@test_throws ErrorException updateVariable!(dfg2, v3)
66+
@test addVariable!(dfg2, v3)
67+
@test_throws ErrorException addVariable!(dfg2, v3)
68+
@test addFactor!(dfg2, [v1, v2], f1)
69+
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
70+
@test_throws ErrorException updateFactor!(dfg2, f2)
71+
@test addFactor!(dfg2, [:b, :c], f2)
72+
73+
dv3 = deleteVariable!(dfg2, v3)
74+
#TODO write compare if we want to compare complete one, for now just label
75+
# @test dv3 == v3
76+
@test dv3.label == v3.label
77+
@test_throws ErrorException deleteVariable!(dfg2, v3)
78+
79+
@test symdiff(ls(dfg2),[:a,:b]) == []
80+
df2 = deleteFactor!(dfg2, f2)
81+
#TODO write compare if we want to compare complete one, for now just label
82+
# @test df2 == f2
83+
@test df2.label == f2.label
84+
@test_throws ErrorException deleteFactor!(dfg2, f2)
85+
86+
@test lsf(dfg2) == [:abf1]
87+
9088
end
9189

9290
@testset "Listing Nodes" begin
9391
global dfg,v1,v2,f1
9492
@test length(ls(dfg)) == 2
95-
@test length(lsf(dfg)) == 1
93+
@test length(lsf(dfg)) == 1 # Unless we add the prior!
9694
@test symdiff([:a, :b], getVariableIds(dfg)) == []
97-
@test getFactorIds(dfg) == [:abf1]
95+
@test getFactorIds(dfg) == [:abf1] # Unless we add the prior!
9896
#
9997
@test lsf(dfg, :a) == [f1.label]
10098
# Tags
10199
@test ls(dfg, tags=[:POSE]) == [:a]
102100
@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == []
103101
# Regexes
104102
@test ls(dfg, r"a") == [v1.label]
105-
@test lsf(dfg, r"f*") == [f1.label]
103+
# TODO: Check that this regular expression works on everything else!
104+
# it works with the .
105+
# REF: https://stackoverflow.com/questions/23834692/using-regular-expression-in-neo4j
106+
@test lsf(dfg, r"abf.*") == [f1.label]
107+
106108
# Accessors
107109
@test getAddHistory(dfg) == [:a, :b] #, :abf1
108110
@test getDescription(dfg) != nothing
@@ -121,6 +123,7 @@ end
121123
# Gets
122124
@testset "Gets, Sets, and Accessors" begin
123125
global dfg,v1,v2,f1
126+
#TODO write compare for variable and factor it looks to be the same
124127
@test getVariable(dfg, v1.label) == v1
125128
@test getFactor(dfg, f1.label) == f1
126129
@test_throws Exception getVariable(dfg, :nope)
@@ -253,13 +256,11 @@ end
253256

254257
# Now make a complex graph for connectivity tests
255258
numNodes = 10
256-
257-
if testDFGAPI == CloudGraphsDFG
258-
dfg = testDFGAPI{SolverParams}()
259-
clearRobot!!(dfg)
260-
else
261-
dfg = testDFGAPI{NoSolverParams}()
262-
end
259+
#the deletions in last test should have cleared out the fg
260+
# dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
261+
# if typeof(dfg) <: CloudGraphsDFG
262+
# clearSession!!(dfg)
263+
# end
263264

264265
#change ready and backendset for x7,x8 for improved tests on x7x8f1
265266
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
@@ -268,6 +269,9 @@ verts[7].ready = 1
268269
# verts[7].backendset = 0
269270
verts[8].ready = 0
270271
verts[8].backendset = 1
272+
#call update to set it on cloud
273+
updateVariable!(dfg, verts[7])
274+
updateVariable!(dfg, verts[8])
271275

272276
facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
273277

@@ -287,9 +291,10 @@ facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Norma
287291

288292
# ready and backendset
289293
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
290-
@test getNeighbors(dfg, :x5, ready=0) == [:x4x5f1,:x5x6f1]
294+
#TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
295+
@test symdiff(getNeighbors(dfg, :x5, ready=0), [:x4x5f1,:x5x6f1]) == []
291296
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
292-
@test getNeighbors(dfg, :x5, backendset=0) == [:x4x5f1,:x5x6f1]
297+
@test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
293298
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
294299
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
295300
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]

test/runtests.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ using Neo4j
44
using DistributedFactorGraphs
55
using IncrementalInference
66

7-
apis = [GraphsDFG, MetaGraphsDFG, SymbolDFG, LightDFG, CloudGraphsDFG]
7+
# Instantiate the APIs that you would like to test here
8+
# Can do duplicates with different parameters.
9+
apis = [
10+
GraphsDFG{NoSolverParams}(),
11+
LightDFG{NoSolverParams}(),
12+
MetaGraphsDFG{NoSolverParams}(),
13+
SymbolDFG{NoSolverParams}(),
14+
CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
15+
"testUser", "testRobot", "testSession",
16+
nothing,
17+
nothing,
18+
IncrementalInference.decodePackedType,
19+
IncrementalInference.rebuildFactorMetadata!,
20+
solverParams=SolverParams())
21+
]
822
for api in apis
9-
@testset "Testing Driver: $(api)" begin
23+
@testset "Testing Driver: $(typeof(api))" begin
1024
@info "Testing Driver: $(api)"
11-
global testDFGAPI = api
25+
global dfg = api
1226
include("iifInterfaceTests.jl")
1327
end
1428
end

0 commit comments

Comments
 (0)