Skip to content

Commit ef2327a

Browse files
committed
sorry, called you back home after your night out in town
but its running and not no errors only some fails.
1 parent dda4b52 commit ef2327a

File tree

3 files changed

+108
-81
lines changed

3 files changed

+108
-81
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Add a DFGFactor to a DFG.
190190
"""
191191
function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor::DFGFactor)::Bool
192192
if exists(dfg, factor)
193-
error("Factor '$(variable.label)' already exists in the factor graph")
193+
error("Factor '$(factor.label)' already exists in the factor graph")
194194
end
195195

196196
# Update the variable ordering
@@ -544,9 +544,15 @@ deleteFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!
544544
List the DFGVariables in the DFG.
545545
Optionally specify a label regular expression to retrieves a subset of the variables.
546546
"""
547-
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}
548548
variableIds = getVariableIds(dfg, regexFilter)
549-
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
550556
end
551557

552558
"""

test/iifInterfaceTests.jl

Lines changed: 88 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,108 @@
33
# using DistributedFactorGraphs
44
# using IncrementalInference
55
# using Test
6-
# testDFGAPI = CloudGraphsDFG
6+
# dfg = apis[1]
77

8-
if typeof(dfg) == CloudGraphsDFG
8+
global dfg,v1,v2,f1
9+
10+
if typeof(dfg) <: CloudGraphsDFG
11+
@warn "TEST: Nuking all data for robot $(dfg.robotId)!"
912
clearRobot!!(dfg)
1013
end
1114

12-
13-
v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
14-
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
15-
f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )
16-
# f1 = addFactor!(fg,[:x0], Prior( pd ) )
17-
18-
# @testset "Creating Graphs" begin
19-
global dfg,v1,v2,f1
20-
21-
@test_throws Exception addFactor!(dfg, DFGFactor{Int, :Symbol}("f2"), [v1, DFGVariable("Nope")])
22-
# 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
2325

2426
#test before anything changes
2527
@testset "Producing Dot Files" begin
26-
27-
@test toDot(dfg) == "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"
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)
2834
@test toDotFile(dfg, "something.dot") == nothing
2935
Base.rm("something.dot")
30-
3136
end
3237

33-
@testset "Adding Removing Nodes" begin
34-
#TODO should errors vs updates be consistant between DFG types
35-
if typeof(dfg) != CloudGraphsDFG
36-
dfg2 = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
37-
v1 = DFGVariable(:a)
38-
v2 = DFGVariable(:b)
39-
v3 = DFGVariable(:c)
40-
f1 = DFGFactor{ContinuousScalar, :Symbol}(:abf1)
41-
f2 = DFGFactor{ContinuousScalar, :Symbol}(:f2)
42-
# @testset "Creating Graphs" begin
43-
@test addVariable!(dfg2, v1)
44-
@test addVariable!(dfg2, v2)
45-
@test_throws ErrorException updateVariable!(dfg2, v3)
46-
@test addVariable!(dfg2, v3)
47-
@test_throws ErrorException addVariable!(dfg2, v3)
48-
@test addFactor!(dfg2, [v1, v2], f1)
49-
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
50-
@test_throws ErrorException updateFactor!(dfg2, f2)
51-
@test addFactor!(dfg2, [:b, :c], f2)
52-
@test deleteVariable!(dfg2, v3) == v3
53-
@test symdiff(ls(dfg2),[:a,:b]) == []
54-
@test deleteFactor!(dfg2, f2) == f2
55-
@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())
5651
else
57-
dfg2 = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
58-
v1 = DFGVariable(:a)
59-
v2 = DFGVariable(:b)
60-
v3 = DFGVariable(:c)
61-
f1 = DFGFactor{ContinuousScalar, :Symbol}(:abf1)
62-
f2 = DFGFactor{ContinuousScalar, :Symbol}(:f2)
63-
64-
@test addVariable!(dfg2, v1)
65-
@test addVariable!(dfg2, v2)
66-
@test_throws ErrorException updateVariable!(dfg2, v3)
67-
@test addVariable!(dfg2, v3)
68-
@test_skip @test_throws ErrorException addVariable!(dfg2, v3)
69-
@test_skip addFactor!(dfg2, [v1, v2], f1)
70-
@test_skip @test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
71-
@test_skip @test_throws ErrorException updateFactor!(dfg2, f2)
72-
@test_skip addFactor!(dfg2, [:b, :c], f2)
73-
@test deleteVariable!(dfg2, v3) == v3 #FIXME ? one returns nothing other ""
74-
@test symdiff(ls(dfg2),[:a,:b]) == []
75-
@test_skip deleteFactor!(dfg2, f2) == f2
76-
@test_skip lsf(dfg2) == [:abf1]
52+
dfg2 = T()
7753
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+
7888
end
7989

8090
@testset "Listing Nodes" begin
8191
global dfg,v1,v2,f1
8292
@test length(ls(dfg)) == 2
83-
@test length(lsf(dfg)) == 1
93+
@test length(lsf(dfg)) == 1 # Unless we add the prior!
8494
@test symdiff([:a, :b], getVariableIds(dfg)) == []
85-
@test getFactorIds(dfg) == [:abf1]
95+
@test getFactorIds(dfg) == [:abf1] # Unless we add the prior!
8696
#
8797
@test lsf(dfg, :a) == [f1.label]
8898
# Tags
8999
@test ls(dfg, tags=[:POSE]) == [:a]
90100
@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == []
91101
# Regexes
92102
@test ls(dfg, r"a") == [v1.label]
93-
@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+
94108
# Accessors
95109
@test getAddHistory(dfg) == [:a, :b] #, :abf1
96110
@test getDescription(dfg) != nothing
@@ -109,6 +123,7 @@ end
109123
# Gets
110124
@testset "Gets, Sets, and Accessors" begin
111125
global dfg,v1,v2,f1
126+
#TODO write compare for variable and factor it looks to be the same
112127
@test getVariable(dfg, v1.label) == v1
113128
@test getFactor(dfg, f1.label) == f1
114129
@test_throws Exception getVariable(dfg, :nope)
@@ -241,11 +256,11 @@ end
241256

242257
# Now make a complex graph for connectivity tests
243258
numNodes = 10
244-
245-
dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
246-
if typeof(dfg) == CloudGraphsDFG
247-
clearSession!!(dfg)
248-
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
249264

250265
#change ready and backendset for x7,x8 for improved tests on x7x8f1
251266
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
@@ -254,6 +269,9 @@ verts[7].ready = 1
254269
# verts[7].backendset = 0
255270
verts[8].ready = 0
256271
verts[8].backendset = 1
272+
#call update to set it on cloud
273+
updateVariable!(dfg, verts[7])
274+
updateVariable!(dfg, verts[8])
257275

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

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

274292
# ready and backendset
275293
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
276-
@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]) == []
277296
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
278-
@test getNeighbors(dfg, :x5, backendset=0) == [:x4x5f1,:x5x6f1]
297+
@test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
279298
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
280299
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
281300
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]

test/runtests.jl

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

7+
# Instantiate the APIs that you would like to test here
8+
# Can do duplicates with different parameters.
79
apis = [
810
GraphsDFG{NoSolverParams}(),
911
LightDFG{NoSolverParams}(),
1012
MetaGraphsDFG{NoSolverParams}(),
1113
SymbolDFG{NoSolverParams}(),
12-
# CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
13-
# "testUser", "testRobot", "testSession",
14-
# nothing,
15-
# nothing,
16-
# IncrementalInference.decodePackedType,
17-
# IncrementalInference.rebuildFactorMetadata!,
18-
# solverParams=SolverParams())
19-
]
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+
]
2022
for api in apis
21-
@testset "Testing Driver: $(api)" begin
23+
@testset "Testing Driver: $(typeof(api))" begin
2224
@info "Testing Driver: $(api)"
2325
global dfg = api
2426
include("iifInterfaceTests.jl")

0 commit comments

Comments
 (0)