Skip to content

Commit f2f4141

Browse files
committed
Fixing tests with simple factors, and changing solver update call to be mergeUpdateVariableSolverData!.
1 parent e44de0b commit f2f4141

File tree

9 files changed

+118
-101
lines changed

9 files changed

+118
-101
lines changed

src/CloudGraphsDFG/CloudGraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export getAddHistory, getDescription, getLabelDict
1818
export addVariable!, addFactor!
1919
export ls, lsf, getVariables, getFactors, getVariableIds, getFactorIds
2020
export getVariable, getFactor
21-
export updateVariable!, updateFactor!, updateVariableSolverData!
21+
export updateVariable!, updateFactor!, mergeUpdateVariableSolverData!
2222
export deleteVariable!, deleteFactor!
2323
export getAdjacencyMatrix
2424
export getNeighbors

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,17 @@ end
318318
$(SIGNATURES)
319319
Update solver and estimate data for a variable (variable can be from another graph).
320320
"""
321-
function updateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
321+
function mergeUpdateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
322322
if !exists(dfg, sourceVariable)
323323
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
324324
end
325-
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sourceVariable.label)
326-
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "estimateDict", JSON2.write(sourceVariable.estimateDict))
327-
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "solverDataDict", JSON2.write(Dict(keys(sourceVariable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(sourceVariable.solverDataDict)))))
325+
var = getVariable(dfg, sourceVariable.label)
326+
newEsts = merge!(var.estimateDict, deepcopy(sourceVariable.estimateDict))
327+
newSolveData = merge!(var.solverDataDict, sourceVariable.solverDataDict)
328+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, var._internalId, "estimateDict",
329+
JSON2.write(newEsts))
330+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, var._internalId, "solverDataDict",
331+
JSON2.write(Dict(keys(newSolveData) .=> map(vnd -> pack(dfg, vnd), values(newSolveData)))))
328332
return sourceVariable
329333
end
330334

src/DistributedFactorGraphs.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export pushUserData!, pushRobotData!, pushSessionData!, popUserData!, popRobotDa
3030

3131
# Services/AbstractDFG Exports
3232
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
33-
export updateGraphSolverData!
33+
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
3434

3535
# Solver (IIF) Exports
3636
export VariableNodeData, PackedVariableNodeData, VariableEstimate
@@ -50,7 +50,8 @@ export saveDFG, loadDFG
5050
export getSummary, getSummaryGraph
5151

5252
# Comparisons
53-
export compareField,
53+
export
54+
compareField,
5455
compareFields,
5556
compareAll,
5657
compareAllSpecial,
@@ -85,14 +86,17 @@ using .SymbolDFGs
8586
include("LightDFG/LightDFG.jl")
8687
@reexport using .LightDFGs
8788

89+
#supported in Memory fg types
90+
const InMemoryDFGTypes = Union{GraphsDFG, LightDFG}
91+
export InMemoryDFGTypes
92+
8893
function __init__()
8994
@info "Looking for @require modules"
90-
#FIXME still can't figure @require out
91-
# @require Neo4j="d2adbeaf-5838-5367-8a2f-e46d570981db" begin
92-
# @info "Including CloudGraphsDFG"
93-
# # Include the Cloudgraphs API
94-
# include("CloudGraphsDFG/CloudGraphsDFG.jl")
95-
# end
95+
@require Neo4j="d2adbeaf-5838-5367-8a2f-e46d570981db" begin
96+
@info "Including CloudGraphsDFG"
97+
# Include the Cloudgraphs API
98+
include("CloudGraphsDFG/CloudGraphsDFG.jl")
99+
end
96100

97101
@require GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" begin
98102
@info "Including Plots"
@@ -102,10 +106,6 @@ function __init__()
102106

103107
end
104108

105-
#FIXME still can't figure @require out
106-
# Include the Cloudgraphs API
107-
include("CloudGraphsDFG/CloudGraphsDFG.jl")
108-
109109
# To be moved as necessary.
110110
include("Common.jl")
111111

src/services/AbstractDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ end
415415

416416
"""
417417
$(SIGNATURES)
418-
Update solver and estimate data for a variable (variable can be from another graph).
418+
Merges and updates solver and estimate data for a variable (variable can be from another graph).
419419
Note: Makes a copy of the estimates and solver data so that there is no coupling
420420
between graphs.
421421
"""
422-
function updateVariableSolverData!(dfg::AbstractDFG, sourceVariable::AbstractDFGVariable)::AbstractDFGVariable
422+
function mergeUpdateVariableSolverData!(dfg::AbstractDFG, sourceVariable::AbstractDFGVariable)::AbstractDFGVariable
423423
if !exists(dfg, sourceVariable)
424424
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
425425
end
@@ -436,11 +436,11 @@ end
436436
Common function to update all solver data and estimates from one graph to another.
437437
This should be used to push local solve data back into a cloud graph, for example.
438438
"""
439-
function updateGraphSolverData!(sourceDFG::G, destDFG::H, varSyms::Vector{Symbol})::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
439+
function mergeUpdateGraphSolverData!(sourceDFG::G, destDFG::H, varSyms::Vector{Symbol})::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
440440
# Update all variables in the destination
441441
# (For now... we may change this soon)
442442
for variableId in varSyms
443-
updateVariableSolverData!(destDFG, getVariable(sourceDFG, variableId))
443+
mergeUpdateVariableSolverData!(destDFG, getVariable(sourceDFG, variableId))
444444
end
445445
end
446446

src/services/CompareUtils.jl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
function compareField(Allc, Bllc, syms)::Bool
3+
(!isdefined(Allc, syms) && !isdefined(Bllc, syms)) && return true
4+
!isdefined(Allc, syms) && return false
5+
!isdefined(Bllc, syms) && return false
36
return eval(:($Allc.$syms == $Bllc.$syms))
47
end
58

@@ -101,6 +104,9 @@ function compareAll(Al::T, Bl::T; show::Bool=true, skip::Vector{Symbol}=Symbol[]
101104
for field in fieldnames(T)
102105
field in skip && continue
103106
@debug(" Checking field: $field")
107+
(!isdefined(Al, field) && !isdefined(Al, field)) && return true
108+
!isdefined(Al, field) && return false
109+
!isdefined(Bl, field) && return false
104110
Ad = eval(:($Al.$field))
105111
Bd = eval(:($Bl.$field))
106112
!compareAll(Ad, Bd, show=show, skip=skip) && return false
@@ -126,8 +132,8 @@ function compareVariable(A::DFGVariable,
126132
union!(skiplist, skip)
127133
TP = TP && compareAll(A.solverDataDict, B.solverDataDict, skip=skiplist, show=show)
128134

129-
Ad = getData(A)
130-
Bd = getData(B)
135+
Ad = solverData(A)
136+
Bd = solverData(B)
131137

132138
# TP = TP && compareAll(A.attributes, B.attributes, skip=[:softtype;], show=show)
133139
varskiplist = union(varskiplist, [:softtype;:_internalId])
@@ -161,23 +167,22 @@ function compareFactor(A::DFGFactor,
161167
skipsamples::Bool=true,
162168
skipcompute::Bool=true )
163169
#
164-
@info show
165170
TP = compareAll(A, B, skip=union([:attributes;:data;:_variableOrderSymbols;:_internalId],skip), show=show)
166171
# TP = TP & compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
167-
TP = TP & compareAllSpecial(getData(A), getData(B), skip=union([:fnc;:_internalId], skip), show=show)
168-
TP = TP & compareAllSpecial(getData(A).fnc, getData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel], skip), show=show)
169-
TP = TP & (skipsamples || compareAll(getData(A).fnc.measurement, getData(B).fnc.measurement, show=show, skip=skip))
170-
TP = TP & (skipcompute || compareAll(getData(A).fnc.params, getData(B).fnc.params, show=show, skip=skip))
171-
TP = TP & (skipcompute || compareAll(getData(A).fnc.varidx, getData(B).fnc.varidx, show=show, skip=skip))
172+
TP = TP & compareAllSpecial(solverData(A), solverData(B), skip=union([:fnc;:_internalId], skip), show=show)
173+
TP = TP & compareAllSpecial(solverData(A).fnc, solverData(B).fnc, skip=union([:cpt;:measurement;:params;:varidx;:threadmodel], skip), show=show)
174+
TP = TP & (skipsamples || compareAll(solverData(A).fnc.measurement, solverData(B).fnc.measurement, show=show, skip=skip))
175+
TP = TP & (skipcompute || compareAll(solverData(A).fnc.params, solverData(B).fnc.params, show=show, skip=skip))
176+
TP = TP & (skipcompute || compareAll(solverData(A).fnc.varidx, solverData(B).fnc.varidx, show=show, skip=skip))
172177

173178
return TP
174179
end
175-
# Ad = getData(A)
176-
# Bd = getData(B)
180+
# Ad = solverData(A)
181+
# Bd = solverData(B)
177182
# TP = compareAll(A, B, skip=[:attributes;:data], show=show)
178183
# TP &= compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
179-
# TP &= compareAllSpecial(getData(A).fnc, getData(B).fnc, skip=[:cpt;], show=show)
180-
# TP &= compareAll(getData(A).fnc.cpt, getData(B).fnc.cpt, show=show)
184+
# TP &= compareAllSpecial(solverData(A).fnc, solverData(B).fnc, skip=[:cpt;], show=show)
185+
# TP &= compareAll(solverData(A).fnc.cpt, solverData(B).fnc.cpt, show=show)
181186

182187

183188
"""

src/services/DFGFactor.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,4 @@ Equality check for DFGFactor.
7979
"""
8080
function ==(a::DFGFactor, b::DFGFactor)::Bool
8181
return compareFactor(a, b)
82-
a.label != b.label && @debug("label is not equal")==nothing && return false
83-
a.tags != b.tags && @debug("tags is not equal")==nothing && return false
84-
a.data != b.data && @debug("data is not equal")==nothing && return false
85-
a.ready != b.ready && @debug("ready is not equal")==nothing && return false
86-
a.backendset != b.backendset && @debug("backendset is not equal")==nothing && return false
87-
a._internalId != b._internalId && @debug("_internalId is not equal")==nothing && return false
88-
a._variableOrderSymbols != b._variableOrderSymbols && @debug("_variableOrderSymbols is not equal")==nothing && return false
89-
return true
9082
end

test/LightDFGSummaryTypes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ end
129129
:mean => VariableEstimate(:default, :mean, [50.0]),
130130
:modefit => VariableEstimate(:default, :modefit, [75.0]))
131131
#update
132-
updateVariableSolverData!(dfg, newvar)
132+
mergeUpdateVariableSolverData!(dfg, newvar)
133133
#TODO maybe implement ==; @test newvar==var
134134
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
135135
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
@@ -150,7 +150,7 @@ end
150150
:ppe => VariableEstimate(:default, :ppe, [7.0]))
151151

152152
# Persist to the original variable.
153-
updateVariableSolverData!(dfg, newvar)
153+
mergeUpdateVariableSolverData!(dfg, newvar)
154154
# At this point newvar will have only :second, and var should have both (it is the reference)
155155
@test symdiff(collect(keys(estimates(var))), [:default, :second]) == Symbol[]
156156
@test symdiff(collect(keys(estimates(newvar))), [:second]) == Symbol[]

test/iifInterfaceTests.jl

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# using GraphPlot
22
# using Neo4j
3-
# using DistributedFactorGraphs
3+
using DistributedFactorGraphs
44
# using IncrementalInference
55
# using Test
66
# dfg = apis[2]
@@ -174,60 +174,65 @@ end
174174
@test !isInitialized(v2, key=:second)
175175

176176
# Session, robot, and user small data tests
177-
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
178-
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")
179-
smallSessionData = Dict{Symbol, String}(:a => "44", :b => "Hello")
180-
setUserData(dfg, deepcopy(smallUserData))
181-
setRobotData(dfg, deepcopy(smallRobotData))
182-
setSessionData(dfg, deepcopy(smallSessionData))
183-
@test getUserData(dfg) == smallUserData
184-
@test getRobotData(dfg) == smallRobotData
185-
@test getSessionData(dfg) == smallSessionData
186-
177+
# NOTE: CloudGraphDFG isnt supporting this yet.
178+
if !(typeof(dfg) <: CloudGraphsDFG)
179+
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
180+
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")
181+
smallSessionData = Dict{Symbol, String}(:a => "44", :b => "Hello")
182+
setUserData(dfg, deepcopy(smallUserData))
183+
setRobotData(dfg, deepcopy(smallRobotData))
184+
setSessionData(dfg, deepcopy(smallSessionData))
185+
@test getUserData(dfg) == smallUserData
186+
@test getRobotData(dfg) == smallRobotData
187+
@test getSessionData(dfg) == smallSessionData
188+
end
187189
end
188190

189191
@testset "BigData" begin
190-
oid = zeros(UInt8,12); oid[12] = 0x01
191-
de1 = MongodbBigDataEntry(:key1, NTuple{12,UInt8}(oid))
192-
193-
oid = zeros(UInt8,12); oid[12] = 0x02
194-
de2 = MongodbBigDataEntry(:key2, NTuple{12,UInt8}(oid))
195-
196-
oid = zeros(UInt8,12); oid[12] = 0x03
197-
de2_update = MongodbBigDataEntry(:key2, NTuple{12,UInt8}(oid))
198-
199-
#add
200-
v1 = getVariable(dfg, :a)
201-
@test addBigDataEntry!(v1, de1)
202-
@test addBigDataEntry!(dfg, :a, de2)
203-
@test addBigDataEntry!(v1, de1)
204-
205-
#get
206-
@test deepcopy(de1) == getBigDataEntry(v1, :key1)
207-
@test deepcopy(de2) == getBigDataEntry(dfg, :a, :key2)
208-
@test_throws Any getBigDataEntry(v2, :key1)
209-
@test_throws Any getBigDataEntry(dfg, :b, :key1)
210-
211-
#update
212-
@test updateBigDataEntry!(dfg, :a, de2_update)
213-
@test deepcopy(de2_update) == getBigDataEntry(dfg, :a, :key2)
214-
@test !updateBigDataEntry!(dfg, :b, de2_update)
215-
216-
#list
217-
entries = getBigDataEntries(dfg, :a)
218-
@test length(entries) == 2
219-
@test symdiff(map(e->e.key, entries), [:key1, :key2]) == Symbol[]
220-
@test length(getBigDataEntries(dfg, :b)) == 0
221-
222-
@test symdiff(getBigDataKeys(dfg, :a), [:key1, :key2]) == Symbol[]
223-
@test getBigDataKeys(dfg, :b) == Symbol[]
224-
225-
#delete
226-
@test deepcopy(de1) == deleteBigDataEntry!(v1, :key1)
227-
@test getBigDataKeys(v1) == Symbol[:key2]
228-
#delete from dfg
229-
@test deepcopy(de2_update) == deleteBigDataEntry!(dfg, :a, :key2)
230-
@test getBigDataKeys(v1) == Symbol[]
192+
# NOTE: CloudGraphDFG isnt supporting this yet.
193+
if !(typeof(dfg) <: CloudGraphsDFG)
194+
oid = zeros(UInt8,12); oid[12] = 0x01
195+
de1 = MongodbBigDataEntry(:key1, NTuple{12,UInt8}(oid))
196+
197+
oid = zeros(UInt8,12); oid[12] = 0x02
198+
de2 = MongodbBigDataEntry(:key2, NTuple{12,UInt8}(oid))
199+
200+
oid = zeros(UInt8,12); oid[12] = 0x03
201+
de2_update = MongodbBigDataEntry(:key2, NTuple{12,UInt8}(oid))
202+
203+
#add
204+
v1 = getVariable(dfg, :a)
205+
@test addBigDataEntry!(v1, de1)
206+
@test addBigDataEntry!(dfg, :a, de2)
207+
@test addBigDataEntry!(v1, de1)
208+
209+
#get
210+
@test deepcopy(de1) == getBigDataEntry(v1, :key1)
211+
@test deepcopy(de2) == getBigDataEntry(dfg, :a, :key2)
212+
@test_throws Any getBigDataEntry(v2, :key1)
213+
@test_throws Any getBigDataEntry(dfg, :b, :key1)
214+
215+
#update
216+
@test updateBigDataEntry!(dfg, :a, de2_update)
217+
@test deepcopy(de2_update) == getBigDataEntry(dfg, :a, :key2)
218+
@test !updateBigDataEntry!(dfg, :b, de2_update)
219+
220+
#list
221+
entries = getBigDataEntries(dfg, :a)
222+
@test length(entries) == 2
223+
@test symdiff(map(e->e.key, entries), [:key1, :key2]) == Symbol[]
224+
@test length(getBigDataEntries(dfg, :b)) == 0
225+
226+
@test symdiff(getBigDataKeys(dfg, :a), [:key1, :key2]) == Symbol[]
227+
@test getBigDataKeys(dfg, :b) == Symbol[]
228+
229+
#delete
230+
@test deepcopy(de1) == deleteBigDataEntry!(v1, :key1)
231+
@test getBigDataKeys(v1) == Symbol[:key2]
232+
#delete from dfg
233+
@test deepcopy(de2_update) == deleteBigDataEntry!(dfg, :a, :key2)
234+
@test getBigDataKeys(v1) == Symbol[]
235+
end
231236
end
232237

233238
@testset "Updating Nodes and Estimates" begin
@@ -241,7 +246,7 @@ end
241246
:mean => VariableEstimate(:default, :mean, [50.0]),
242247
:modefit => VariableEstimate(:default, :modefit, [75.0]))
243248
#update
244-
updateVariableSolverData!(dfg, newvar)
249+
mergeUpdateVariableSolverData!(dfg, newvar)
245250

246251
#Check if variable is updated
247252
var = getVariable(dfg, :a)
@@ -256,7 +261,7 @@ end
256261
# Confirm they're different
257262
@test estimates(newvar) != estimates(var)
258263
# Persist it.
259-
updateVariableSolverData!(dfg, newvar)
264+
mergeUpdateVariableSolverData!(dfg, newvar)
260265
# Get the latest
261266
var = getVariable(dfg, :a)
262267
@test symdiff(collect(keys(estimates(var))), [:default, :second]) == Symbol[]
@@ -270,7 +275,7 @@ end
270275
#confirm delete
271276
@test symdiff(collect(keys(estimates(newvar))), [:second]) == Symbol[]
272277
# Persist it.
273-
updateVariableSolverData!(dfg, newvar)
278+
mergeUpdateVariableSolverData!(dfg, newvar)
274279

275280
# Get the latest and confirm they're the same, :second
276281
var = getVariable(dfg, :a)

0 commit comments

Comments
 (0)