Skip to content

Commit f5cc726

Browse files
committed
Add _getDuplicatedEmptyDFG to all drivers, instantiating drivers in runTests.jl to simply things
1 parent 5575ace commit f5cc726

File tree

7 files changed

+61
-25
lines changed

7 files changed

+61
-25
lines changed

src/LightDFG/LightDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import ...DistributedFactorGraphs: setSolverParams,
3434
getSubgraphAroundNode,
3535
getSubgraph,
3636
getAdjacencyMatrix,
37-
getAdjacencyMatrixSparse
37+
getAdjacencyMatrixSparse,
38+
_getDuplicatedEmptyDFG
3839

3940
include("FactorGraphs/FactorGraphs.jl")
4041
using .FactorGraphs

src/LightDFG/services/LightDFG.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,15 @@ function getAdjacencyMatrixSparse(dfg::LightDFG)::Tuple{LightGraphs.SparseMatrix
426426
adjvf = adj[factIndex, varIndex]
427427
return adjvf, varLabels, factLabels
428428
end
429+
430+
"""
431+
$(SIGNATURES)
432+
Gets an empty and unique CloudGraphsDFG derived from an existing DFG.
433+
"""
434+
function _getDuplicatedEmptyDFG(dfg::LightDFG{P,V,F})::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
435+
newDfg = LightDFG{P,V,F}(;
436+
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
437+
params=deepcopy(dfg.solverParams))
438+
newDfg.description ="(Copy of) $(dfg.description)"
439+
return newDfg
440+
end

src/MetaGraphsDFG/services/MetaGraphsDFG.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,15 @@ function _toDotFile(dfg::MetaGraphsDFG, fileName::String="/tmp/dfg.dot")::Nothin
564564
end
565565
return nothing
566566
end
567+
568+
"""
569+
$(SIGNATURES)
570+
Gets an empty and unique CloudGraphsDFG derived from an existing DFG.
571+
"""
572+
function _getDuplicatedEmptyDFG(dfg::MetaGraphsDFG{P})::MetaGraphsDFG where {P <: AbstractParams}
573+
newDfg = MetaGraphsDFG{P}(;
574+
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
575+
params=deepcopy(dfg.solverParams))
576+
newDfg.description ="(Copy of) $(dfg.description)"
577+
return newDfg
578+
end

src/SymbolDFG/SymbolDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import ...DistributedFactorGraphs: setSolverParams,
3434
getSubgraphAroundNode,
3535
getSubgraph,
3636
getAdjacencyMatrix,
37-
getAdjacencyMatrixSparse
37+
getAdjacencyMatrixSparse,
38+
_getDuplicatedEmptyDFG
3839

3940
include("SymbolFactorGraphs/SymbolFactorGraphs.jl")
4041
using .SymbolFactorGraphs

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,15 @@ function toDotFile(dfg::SymbolDFG, fileName::String="/tmp/dfg.dot")::Nothing
518518
return nothing
519519
end
520520
=#
521+
522+
"""
523+
$(SIGNATURES)
524+
Gets an empty and unique CloudGraphsDFG derived from an existing DFG.
525+
"""
526+
function _getDuplicatedEmptyDFG(dfg::SymbolDFG{T,V,F})::SymbolDFG where {T <: AbstractParams, V <: DFGNode, F <:DFGNode}
527+
newDfg = SymbolDFG{T, V, F}(;
528+
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
529+
params=deepcopy(dfg.solverParams))
530+
newDfg.description ="(Copy of) $(dfg.description)"
531+
return newDfg
532+
end

test/iifInterfaceTests.jl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,8 @@
55
# using Test
66
# testDFGAPI = CloudGraphsDFG
77

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())
16-
17-
18-
dfg = testDFGAPI{SolverParams}()
8+
if typeof(dfg) == CloudGraphsDFG
199
clearRobot!!(dfg)
20-
else
21-
dfg = testDFGAPI{NoSolverParams}()
2210
end
2311

2412

@@ -44,8 +32,8 @@ end
4432

4533
@testset "Adding Removing Nodes" begin
4634
#TODO should errors vs updates be consistant between DFG types
47-
if testDFGAPI != CloudGraphsDFG
48-
dfg2 = testDFGAPI{NoSolverParams}()
35+
if typeof(dfg) != CloudGraphsDFG
36+
dfg2 = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
4937
v1 = DFGVariable(:a)
5038
v2 = DFGVariable(:b)
5139
v3 = DFGVariable(:c)
@@ -66,7 +54,7 @@ end
6654
@test deleteFactor!(dfg2, f2) == f2
6755
@test lsf(dfg2) == [:abf1]
6856
else
69-
dfg2 = testDFGAPI{SolverParams}()
57+
dfg2 = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
7058
v1 = DFGVariable(:a)
7159
v2 = DFGVariable(:b)
7260
v3 = DFGVariable(:c)
@@ -254,11 +242,9 @@ end
254242
# Now make a complex graph for connectivity tests
255243
numNodes = 10
256244

257-
if testDFGAPI == CloudGraphsDFG
258-
dfg = testDFGAPI{SolverParams}()
259-
clearRobot!!(dfg)
260-
else
261-
dfg = testDFGAPI{NoSolverParams}()
245+
dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
246+
if typeof(dfg) == CloudGraphsDFG
247+
clearSession!!(dfg)
262248
end
263249

264250
#change ready and backendset for x7,x8 for improved tests on x7x8f1

test/runtests.jl

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

7-
apis = [GraphsDFG, MetaGraphsDFG, SymbolDFG, LightDFG, CloudGraphsDFG]
7+
apis = [
8+
GraphsDFG{NoSolverParams}(),
9+
LightDFG{NoSolverParams}(),
10+
MetaGraphsDFG{NoSolverParams}(),
11+
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+
]
820
for api in apis
921
@testset "Testing Driver: $(api)" begin
1022
@info "Testing Driver: $(api)"
11-
global testDFGAPI = api
23+
global dfg = api
1224
include("iifInterfaceTests.jl")
1325
end
1426
end

0 commit comments

Comments
 (0)