Skip to content

Commit dbc4ec7

Browse files
committed
WIP on fixing CGDFG
1 parent b110db9 commit dbc4ec7

File tree

3 files changed

+88
-177
lines changed

3 files changed

+88
-177
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=n
670670
end
671671
neighbors = _getLabelsFromCyphonQuery(dfg.neo4jInstance, query)
672672
# If factor, need to do variable ordering
673-
if T == DFGFactor
674-
order = intersect(node._variableOrderSymbols, map(v->v.dfgNode.label, neighbors))
673+
if T <: DFGFactor
674+
neighbors = intersect(node._variableOrderSymbols, neighbors)
675675
end
676676
return neighbors
677677
end
@@ -693,8 +693,9 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
693693
neighbors = _getLabelsFromCyphonQuery(dfg.neo4jInstance, query)
694694
# If factor, need to do variable ordering
695695
if _getNodeType(dfg, label) == :FACTOR
696+
# TODO: Implement shortcut for this.
696697
factor = getFactor(dfg, label)
697-
order = intersect(factor._variableOrderSymbols, neighbors)
698+
neighbors = intersect(factor._variableOrderSymbols, neighbors)
698699
end
699700
return neighbors
700701
end

test/iifInterfaceTests.jl

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -248,55 +248,55 @@ end
248248
end
249249

250250

251-
# # Now make a complex graph for connectivity tests
252-
# numNodes = 10
253-
# #the deletions in last test should have cleared out the fg
254-
# # dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
255-
# # if typeof(dfg) <: CloudGraphsDFG
256-
# # clearSession!!(dfg)
257-
# # end
258-
#
259-
# #change ready and backendset for x7,x8 for improved tests on x7x8f1
260-
# verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
261-
# #TODO fix this to use accessors
262-
# verts[7].ready = 1
263-
# # verts[7].backendset = 0
264-
# verts[8].ready = 0
265-
# verts[8].backendset = 1
266-
# #call update to set it on cloud
267-
# updateVariable!(dfg, verts[7])
268-
# updateVariable!(dfg, verts[8])
269-
#
270-
# facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
271-
#
272-
# @testset "Getting Neighbors" begin
273-
# global dfg,verts
274-
# # Trivial test to validate that intersect([], []) returns order of first parameter
275-
# @test intersect([:x3, :x2, :x1], [:x1, :x2]) == [:x2, :x1]
276-
# # Get neighbors tests
277-
# @test getNeighbors(dfg, verts[1]) == [:x1x2f1]
278-
# neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
279-
# @test neighbors == [:x1, :x2]
280-
# # Testing aliases
281-
# @test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
282-
# @test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
283-
#
284-
# # ready and backendset
285-
# @test getNeighbors(dfg, :x5, ready=1) == Symbol[]
286-
# #TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
287-
# @test symdiff(getNeighbors(dfg, :x5, ready=0), [:x4x5f1,:x5x6f1]) == []
288-
# @test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
289-
# @test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
290-
# @test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
291-
# @test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
292-
# @test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
293-
# @test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
294-
# @test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
295-
# @test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
296-
# @test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]
297-
# @test getNeighbors(dfg, verts[1], backendset=1) == Symbol[]
298-
#
251+
# Now make a complex graph for connectivity tests
252+
numNodes = 10
253+
#the deletions in last test should have cleared out the fg
254+
# dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
255+
# if typeof(dfg) <: CloudGraphsDFG
256+
# clearSession!!(dfg)
299257
# end
258+
259+
#change ready and backendset for x7,x8 for improved tests on x7x8f1
260+
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
261+
#TODO fix this to use accessors
262+
verts[7].ready = 1
263+
# verts[7].backendset = 0
264+
verts[8].ready = 0
265+
verts[8].backendset = 1
266+
#call update to set it on cloud
267+
updateVariable!(dfg, verts[7])
268+
updateVariable!(dfg, verts[8])
269+
270+
facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
271+
272+
@testset "Getting Neighbors" begin
273+
global dfg,verts
274+
# Trivial test to validate that intersect([], []) returns order of first parameter
275+
@test intersect([:x3, :x2, :x1], [:x1, :x2]) == [:x2, :x1]
276+
# Get neighbors tests
277+
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
278+
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
279+
@test neighbors == [:x1, :x2]
280+
# Testing aliases
281+
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
282+
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
283+
284+
# ready and backendset
285+
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
286+
#TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
287+
@test symdiff(getNeighbors(dfg, :x5, ready=0), [:x4x5f1,:x5x6f1]) == []
288+
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
289+
@test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
290+
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
291+
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
292+
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
293+
@test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
294+
@test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
295+
@test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
296+
@test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]
297+
@test getNeighbors(dfg, verts[1], backendset=1) == Symbol[]
298+
299+
end
300300
#
301301
# @testset "Getting Subgraphs" begin
302302
# # Subgraphs

test/sandbox.jl

Lines changed: 36 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -16,130 +16,40 @@ dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
1616
IncrementalInference.rebuildFactorMetadata!,
1717
solverParams=SolverParams())
1818
clearRobot!!(dfg)
19-
v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
20-
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
21-
v3 = addVariable!(dfg, :c, ContinuousScalar, labels = [:LANDMARK])
22-
v4 = addVariable!(dfg, :d, ContinuousScalar, labels = [:LANDMARK])
23-
f1 = addFactor!(dfg, [:a; :b, :c, :d], LinearConditional(Normal(50.0,2.0)) )
24-
v1 == deepcopy(v1)
25-
v1_back == getVariable(dfg, :a)
26-
getNeighbors(f1)
27-
f1._variableOrderSymbols
2819

29-
T = typeof(dfg)
30-
if T <: CloudGraphsDFG
31-
dfg2 = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
32-
"testUser", "testRobot", "testSession2",
33-
nothing,
34-
nothing,
35-
IncrementalInference.decodePackedType,
36-
IncrementalInference.rebuildFactorMetadata!,
37-
solverParams=SolverParams())
38-
else
39-
dfg2 = T()
40-
end
41-
iiffg = initfg()
42-
v1 = deepcopy(addVariable!(iiffg, :a, ContinuousScalar))
43-
v2 = deepcopy(addVariable!(iiffg, :b, ContinuousScalar))
44-
v3 = deepcopy(addVariable!(iiffg, :c, ContinuousScalar))
45-
f1 = deepcopy(addFactor!(iiffg, [:a; :b], LinearConditional(Normal(50.0,2.0)) ))
46-
f2 = deepcopy(addFactor!(iiffg, [:b; :c], LinearConditional(Normal(10.0,1.0)) ))
47-
48-
# @testset "Creating Graphs" begin
49-
@test addVariable!(dfg2, v1)
50-
@test addVariable!(dfg2, v2)
51-
@test_throws ErrorException updateVariable!(dfg2, v3)
52-
@test addVariable!(dfg2, v3)
53-
@test_throws ErrorException addVariable!(dfg2, v3)
54-
@test addFactor!(dfg2, [v1, v2], f1)
55-
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
56-
@test_throws ErrorException updateFactor!(dfg2, f2)
57-
@test addFactor!(dfg2, [:b, :c], f2)
58-
59-
dv3 = deleteVariable!(dfg2, v3)
60-
#TODO write compare if we want to compare complete one, for now just label
61-
# @test dv3 == v3
62-
@test dv3.label == v3.label
63-
@test_throws ErrorException deleteVariable!(dfg2, v3)
64-
65-
@test symdiff(ls(dfg2),[:a,:b]) == []
66-
df2 = deleteFactor!(dfg2, f2)
67-
#TODO write compare if we want to compare complete one, for now just label
68-
# @test df2 == f2
69-
@test df2.label == f2.label
70-
@test_throws ErrorException deleteFactor!(dfg2, f2)
71-
72-
@test lsf(dfg2) == [:abf1]
73-
74-
@test length(ls(dfg)) == 2
75-
@test length(lsf(dfg)) == 1 # Unless we add the prior!
76-
@test symdiff([:a, :b], getVariableIds(dfg)) == []
77-
@test getFactorIds(dfg) == [:abf1] # Unless we add the prior!
78-
#
79-
@test lsf(dfg, :a) == [f1.label]
80-
# Tags
81-
@test ls(dfg, tags=[:POSE]) == [:a]
82-
@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == []
83-
# Regexes
84-
@test ls(dfg, r"a") == [v1.label]
85-
# TODO: Check that this regular expression works on everything else!
86-
# it works with the .
87-
# REF: https://stackoverflow.com/questions/23834692/using-regular-expression-in-neo4j
88-
@test lsf(dfg, r"abf.*") == [f1.label]
89-
90-
# Accessors
91-
@test getAddHistory(dfg) == [:a, :b] #, :abf1
92-
@test getDescription(dfg) != nothing
93-
@test getLabelDict(dfg) != nothing
94-
# Existence
95-
@test exists(dfg, :a) == true
96-
@test exists(dfg, v1) == true
97-
@test exists(dfg, :nope) == false
98-
# Sorting of results
99-
# TODO - this function needs to be cleaned up
100-
unsorted = [:x1_3;:x1_6;:l1;:april1] #this will not work for :x1x2f1
101-
@test sortDFG(unsorted) == sortVarNested(unsorted)
102-
@test_skip sortDFG([:x1x2f1, :x1l1f1]) == [:x1l1f1, :x1x2f1]
103-
104-
@test getVariable(dfg, v1.label) == v1
105-
@test getFactor(dfg, f1.label) == f1
106-
@test_throws Exception getVariable(dfg, :nope)
107-
@test_throws Exception getVariable(dfg, "nope")
108-
@test_throws Exception getFactor(dfg, :nope)
109-
@test_throws Exception getFactor(dfg, "nope")
110-
111-
# Sets
112-
v1Prime = deepcopy(v1)
113-
@test updateVariable!(dfg, v1Prime) != v1
114-
f1Prime = deepcopy(f1)
115-
@test updateFactor!(dfg, f1Prime) != f1
116-
117-
# Accessors
118-
@test label(v1) == v1.label
119-
@test tags(v1) == v1.tags
120-
@test timestamp(v1) == v1.timestamp
121-
@test estimates(v1) == v1.estimateDict
122-
@test DistributedFactorGraphs.estimate(v1, :notfound) == nothing
123-
@test solverData(v1) === v1.solverDataDict[:default]
124-
@test getData(v1) === v1.solverDataDict[:default]
125-
@test solverData(v1, :default) === v1.solverDataDict[:default]
126-
@test solverDataDict(v1) == v1.solverDataDict
127-
@test internalId(v1) == v1._internalId
128-
129-
@test label(f1) == f1.label
130-
@test tags(f1) == f1.tags
131-
@test solverData(f1) == f1.data
132-
# Deprecated functions
133-
@test data(f1) == f1.data
134-
@test getData(f1) == f1.data
135-
# Internal function
136-
@test internalId(f1) == f1._internalId
137-
138-
@test getSolverParams(dfg) != nothing
139-
@test setSolverParams(dfg, getSolverParams(dfg)) == getSolverParams(dfg)
140-
141-
#solver data is initialized
142-
@test !isInitialized(dfg, :a)
143-
@test !isInitialized(v2)
144-
145-
@test !isInitialized(v2, key=:second)
20+
numNodes = 10
21+
#change ready and backendset for x7,x8 for improved tests on x7x8f1
22+
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
23+
#TODO fix this to use accessors
24+
verts[7].ready = 1
25+
# verts[7].backendset = 0
26+
verts[8].ready = 0
27+
verts[8].backendset = 1
28+
#call update to set it on cloud
29+
updateVariable!(dfg, verts[7])
30+
updateVariable!(dfg, verts[8])
31+
32+
facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
33+
34+
# Get neighbors tests
35+
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
36+
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
37+
@test neighbors == [:x1, :x2]
38+
# Testing aliases
39+
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
40+
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
41+
42+
# ready and backendset
43+
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
44+
#TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
45+
@test symdiff(getNeighbors(dfg, :x5, ready=0), [:x4x5f1,:x5x6f1]) == []
46+
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
47+
@test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
48+
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
49+
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
50+
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
51+
@test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
52+
@test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
53+
@test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
54+
@test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]
55+
@test getNeighbors(dfg, verts[1], backendset=1) == Symbol[]

0 commit comments

Comments
 (0)