Skip to content

Commit 45911f8

Browse files
authored
[BugFix] Copy into graph changed variable order (#337)
* Copy into graph changed variable order * add test and @error on orphans as orphans needs tlc * iif tests also, hate that test are stil not completely consolidated
1 parent e2b993b commit 45911f8

File tree

6 files changed

+56
-26
lines changed

6 files changed

+56
-26
lines changed

attic/sandbox.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function copyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactor
3232
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
3333
if includeOrphanFactors || length(factVariableIds) == length(sourceFactorVariableIds)
3434
if !exists(destDFG, factor)
35-
addFactor!(destDFG, factVariableIds, factor)
35+
addFactor!(destDFG, factor)
3636
end
3737
end
3838
end

src/LightDFG/services/LightDFG.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ function getNeighbors(dfg::LightDFG, label::Symbol; solvable::Int=0)::Vector{Sym
255255
end
256256

257257
function _copyIntoGraph!(sourceDFG::LightDFG{<:AbstractParams, V, F}, destDFG::LightDFG{<:AbstractParams, V, F}, ns::Vector{Int}, includeOrphanFactors::Bool=false)::Nothing where {V <: AbstractDFGVariable, F <: AbstractDFGFactor}
258+
259+
includeOrphanFactors && (@error "Adding orphaned factors is not supported")
260+
258261
#kan ek die in bulk copy, soos graph en dan nuwe map maak
259262
# Add all variables first,
260263
labels = [sourceDFG.g.labels[i] for i in ns]
@@ -283,7 +286,7 @@ function _copyIntoGraph!(sourceDFG::LightDFG{<:AbstractParams, V, F}, destDFG::L
283286

284287
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
285288
if includeOrphanFactors || length(factVariables) == length(neigh_labels)
286-
exists(destDFG, f.label) ? (@warn "_copyIntoGraph $(f.label) exists, ignoring pending error behaviour decision") : addFactor!(destDFG, factVariables, deepcopy(f))
289+
exists(destDFG, f.label) ? (@warn "_copyIntoGraph $(f.label) exists, ignoring pending error behaviour decision") : addFactor!(destDFG, deepcopy(f))
287290
end
288291
end
289292
end

src/services/AbstractDFG.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,8 @@ NOTE: copyGraphMetadata not supported yet.
855855
"""
856856
function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false; copyGraphMetadata::Bool=false)::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
857857
# Split into variables and factors
858+
includeOrphanFactors && (@error "Adding orphaned factors is not supported")
859+
858860
sourceVariables = map(vId->getVariable(sourceDFG, vId), intersect(listVariables(sourceDFG), variableFactorLabels))
859861
sourceFactors = map(fId->getFactor(sourceDFG, fId), intersect(listFactors(sourceDFG), variableFactorLabels))
860862
if length(sourceVariables) + length(sourceFactors) != length(variableFactorLabels)
@@ -883,7 +885,7 @@ function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{
883885
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
884886
if includeOrphanFactors || length(factVariableIds) == length(sourceFactorVariableIds)
885887
if !exists(destDFG, factor)
886-
addFactor!(destDFG, factVariableIds, deepcopy(factor))
888+
addFactor!(destDFG, deepcopy(factor))
887889
end
888890
end
889891
end

test/iifInterfaceTests.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,23 +434,25 @@ end
434434
# Only returns x1 and x2
435435
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
436436
# Test include orphan factorsVoid
437-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
438-
@test symdiff([:x1, :x1x2f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
439-
# Test adding to the dfg
440-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
441-
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
442-
#
437+
@test_broken begin
438+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
439+
@test symdiff([:x1, :x1x2f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
440+
# Test adding to the dfg
441+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
442+
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
443+
end
443444
dfgSubgraph = getSubgraph(dfg,[:x1, :x2, :x1x2f1])
444445
# Only returns x1 and x2
445446
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
446447

447-
# DFG issue #201 Test include orphan factors with filtering - should only return x7 with solvable=1
448-
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=0)
449-
@test symdiff([:x7, :x8, :x7x8f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
450-
# Filter - always returns the node you start at but filters around that.
451-
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=1)
452-
@test symdiff([:x7x8f1, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
453-
448+
@test_broken begin
449+
# DFG issue #201 Test include orphan factors with filtering - should only return x7 with solvable=1
450+
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=0)
451+
@test symdiff([:x7, :x8, :x7x8f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
452+
# Filter - always returns the node you start at but filters around that.
453+
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=1)
454+
@test symdiff([:x7x8f1, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
455+
end
454456
# DFG issue #95 - confirming that getSubgraphAroundNode retains order
455457
# REF: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/95
456458
for fId in listVariables(dfg)

test/interfaceTests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ end
8282
@testset "Connectivity Test" begin
8383
ConnectivityTest(testDFGAPI)
8484
end
85+
86+
87+
@testset "Copy Functions" begin
88+
89+
fg = testDFGAPI()
90+
addVariable!(fg, DFGVariable(:a, TestSofttype1()))
91+
addVariable!(fg, DFGVariable(:b, TestSofttype1()))
92+
addVariable!(fg, DFGVariable(:c, TestSofttype1()))
93+
addFactor!(fg, DFGFactor(:f1, [:a,:b,:c], GenericFunctionNodeData{TestFunctorInferenceType1, Symbol}()))
94+
95+
fgcopy = testDFGAPI()
96+
DFG._copyIntoGraph!(fg, fgcopy, union(ls(fg), lsf(fg)))
97+
98+
@test getVariableOrder(fg,:f1) == getVariableOrder(fgcopy,:f1)
99+
100+
101+
end

test/testBlocks.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,18 +944,21 @@ function GettingNeighbors(testDFGAPI; VARTYPE=DFGVariable, FACTYPE=DFGFactor)
944944
end
945945

946946
function GettingSubgraphs(testDFGAPI; VARTYPE=DFGVariable, FACTYPE=DFGFactor)
947+
947948
# "Getting Subgraphs"
948949
dfg, verts, facs = connectivityTestGraph(testDFGAPI, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
949950
# Subgraphs
950951
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2)
951952
# Only returns x1 and x2
952953
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
953954
# Test include orphan factors
954-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
955-
@test symdiff([:x1, :x1x2f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
956-
# Test adding to the dfg
957-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
958-
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
955+
@test_broken begin
956+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
957+
@test symdiff([:x1, :x1x2f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
958+
# Test adding to the dfg
959+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
960+
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
961+
end
959962
#
960963
dfgSubgraph = getSubgraph(dfg,[:x1, :x2, :x1x2f1])
961964
# Only returns x1 and x2
@@ -964,11 +967,13 @@ function GettingSubgraphs(testDFGAPI; VARTYPE=DFGVariable, FACTYPE=DFGFactor)
964967
#TODO if not a LightDFG with and summary or skeleton
965968
if VARTYPE == DFGVariable
966969
# DFG issue #201 Test include orphan factors with filtering - should only return x7 with solvable=1
967-
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=0)
968-
@test symdiff([:x7, :x8, :x7x8f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
969-
# Filter - always returns the node you start at but filters around that.
970-
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=1)
971-
@test symdiff([:x7x8f1, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
970+
@test_broken begin
971+
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=0)
972+
@test symdiff([:x7, :x8, :x7x8f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
973+
# Filter - always returns the node you start at but filters around that.
974+
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=1)
975+
@test symdiff([:x7x8f1, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
976+
end
972977
# Test for distance = 2, should return orphans
973978
setSolvable!(dfg, :x8x9f1, 0)
974979
dfgSubgraph = getSubgraphAroundNode(dfg, getVariable(dfg, :x8), 2, true, solvable=1)
@@ -985,6 +990,7 @@ function GettingSubgraphs(testDFGAPI; VARTYPE=DFGVariable, FACTYPE=DFGFactor)
985990
@test fact._variableOrderSymbols == getFactor(dfg, fact.label)._variableOrderSymbols
986991
end
987992
end
993+
988994
end
989995

990996
#TODO Summaries and Summary Graphs

0 commit comments

Comments
 (0)