Skip to content

Commit 0be2005

Browse files
authored
Merge pull request #207 from JuliaRobotics/twig/4Q19/wipsolvablegraphs_tests
Updated with test changes and new IIF branch
2 parents 19e5da5 + 35a6106 commit 0be2005

File tree

14 files changed

+63
-102
lines changed

14 files changed

+63
-102
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::Bool
9898
props["estimateDict"] = JSON2.write(variable.estimateDict)
9999
props["solverDataDict"] = JSON2.write(Dict(keys(variable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(variable.solverDataDict))))
100100
props["smallData"] = JSON2.write(variable.smallData)
101-
props["ready"] = variable.ready
102-
props["backendset"] = variable.backendset
101+
props["ready"] = variable.solvable
102+
props["backendset"] = variable.solveInProgress
103103
# Don't handle big data at the moment.
104104

105105
neo4jNode = Neo4j.createnode(dfg.neo4jInstance.graph, props);
@@ -143,8 +143,8 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor:
143143
# Include the type
144144
props["fnctype"] = String(_getname(fnctype))
145145
props["_variableOrderSymbols"] = JSON2.write(factor._variableOrderSymbols)
146-
props["backendset"] = factor.backendset
147-
props["ready"] = factor.ready
146+
props["backendset"] = factor.solveInProgress
147+
props["ready"] = factor.solvable
148148
# Don't handle big data at the moment.
149149

150150
neo4jNode = Neo4j.createnode(dfg.neo4jInstance.graph, props);
@@ -201,8 +201,8 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
201201
variable.estimateDict = estimateDict
202202
variable.solverDataDict = solverData
203203
variable.smallData = smallData
204-
variable.ready = props["ready"]
205-
variable.backendset = props["backendset"]
204+
variable.solvable = props["ready"]
205+
variable.solveInProgress = props["backendset"]
206206

207207
# Add to cache
208208
push!(dfg.variableCache, variable.label=>variable)
@@ -256,8 +256,8 @@ function getFactor(dfg::CloudGraphsDFG, factorId::Int64)::DFGFactor
256256
factor.tags = tags
257257
factor.data = fullFactor
258258
factor._variableOrderSymbols = _variableOrderSymbols
259-
factor.ready = ready
260-
factor.backendset = backendset
259+
factor.solvable = ready
260+
factor.solveInProgress = backendset
261261

262262
# Lastly, rebuild the metadata
263263
factor = dfg.rebuildFactorMetadata!(dfg, factor)
@@ -310,8 +310,8 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
310310
props["estimateDict"] = JSON2.write(variable.estimateDict)
311311
props["solverDataDict"] = JSON2.write(Dict(keys(variable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(variable.solverDataDict))))
312312
props["smallData"] = JSON2.write(variable.smallData)
313-
props["ready"] = variable.ready
314-
props["backendset"] = variable.backendset
313+
props["ready"] = variable.solvable
314+
props["backendset"] = variable.solveInProgress
315315
# Don't handle big data at the moment.
316316

317317
Neo4j.updatenodeproperties(neo4jNode, props)
@@ -361,8 +361,8 @@ function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
361361
# Include the type
362362
props["fnctype"] = String(_getname(fnctype))
363363
props["_variableOrderSymbols"] = JSON2.write(factor._variableOrderSymbols)
364-
props["backendset"] = factor.backendset
365-
props["ready"] = factor.ready
364+
props["backendset"] = factor.solveInProgress
365+
props["ready"] = factor.solvable
366366
# Don't handle big data at the moment.
367367

368368
Neo4j.updatenodeproperties(neo4jNode, props)
@@ -374,7 +374,7 @@ end
374374

375375
"""
376376
$(SIGNATURES)
377-
Update a complete DFGFactor in the DFG and update it's relationships.
377+
Update a complete DFGFactor in the DFG and update its relationships.
378378
"""
379379
function updateFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor::DFGFactor)::DFGFactor
380380
# Update the body
@@ -597,7 +597,7 @@ function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=n
597597
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))--(node) where (node:VARIABLE or node:FACTOR) "
598598
if ready != nothing || backendset != nothing
599599
if ready != nothing
600-
query = query * " and node.ready = $(ready)"
600+
query = query * " and node.ready >= $(ready)"
601601
end
602602
if backendset != nothing
603603
query = query * " and node.backendset = $(backendset)"
@@ -620,7 +620,7 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
620620
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(label))--(node) where (node:VARIABLE or node:FACTOR) "
621621
if ready != nothing || backendset != nothing
622622
if ready != nothing
623-
query = query * " and node.ready = $(ready)"
623+
query = query * " and node.ready >= $(ready)"
624624
end
625625
if backendset != nothing
626626
query = query * " and node.backendset = $(backendset)"

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ function getNeighbors(dfg::GraphsDFG, node::T; ready::Union{Nothing, Int}=nothin
288288
vert = dfg.g.vertices[dfg.labelDict[node.label]]
289289
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
290290
# Additional filtering
291-
neighbors = ready != nothing ? filter(v -> v.dfgNode.ready == ready, neighbors) : neighbors
292-
neighbors = backendset != nothing ? filter(v -> v.dfgNode.backendset == backendset, neighbors) : neighbors
291+
neighbors = ready != nothing ? filter(v -> isSolvable(v.dfgNode) >= ready, neighbors) : neighbors
292+
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
293293
# Variable sorting (order is important)
294294
if node isa DFGFactor
295295
order = intersect(node._variableOrderSymbols, map(v->v.dfgNode.label, neighbors))
@@ -309,8 +309,8 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=
309309
vert = dfg.g.vertices[dfg.labelDict[label]]
310310
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
311311
# Additional filtering
312-
neighbors = ready != nothing ? filter(v -> v.dfgNode.ready == ready, neighbors) : neighbors
313-
neighbors = backendset != nothing ? filter(v -> v.dfgNode.backendset == backendset, neighbors) : neighbors
312+
neighbors = ready != nothing ? filter(v -> isSolvable(v.dfgNode) >= ready, neighbors) : neighbors
313+
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
314314
# Variable sorting when using a factor (function order is important)
315315
if vert.dfgNode isa DFGFactor
316316
vert.dfgNode._variableOrderSymbols
@@ -321,41 +321,6 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=
321321
return map(n -> n.dfgNode.label, neighbors)
322322
end
323323

324-
# function _copyIntoGraph!(sourceDFG::GraphsDFG, destDFG::GraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false)::Nothing
325-
# # Split into variables and factors
326-
# verts = map(id -> sourceDFG.g.vertices[sourceDFG.labelDict[id]], variableFactorLabels)
327-
# sourceVariables = filter(n -> n.dfgNode isa DFGVariable, verts)
328-
# sourceFactors = filter(n -> n.dfgNode isa DFGFactor, verts)
329-
#
330-
# # Now we have to add all variables first,
331-
# for variable in sourceVariables
332-
# if !haskey(destDFG.labelDict, variable.dfgNode.label)
333-
# addVariable!(destDFG, deepcopy(variable.dfgNode))
334-
# end
335-
# end
336-
# # And then all factors to the destDFG.
337-
# for factor in sourceFactors
338-
# if !haskey(destDFG.labelDict, factor.dfgNode.label)
339-
# # Get the original factor variables (we need them to create it)
340-
# neighVarIds = getNeighbors(sourceDFG, factor.dfgNode.label) #OLD: in_neighbors(factor, sourceDFG.g)
341-
# # Find the labels and associated neighVarIds in our new subgraph
342-
# factVariables = DFGVariable[]
343-
# for neighVarId in neighVarIds
344-
# if haskey(destDFG.labelDict, neighVarId)
345-
# push!(factVariables, getVariable(destDFG, neighVarId))
346-
# #otherwise ignore
347-
# end
348-
# end
349-
#
350-
# # Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
351-
# if includeOrphanFactors || length(factVariables) == length(neighVarIds)
352-
# addFactor!(destDFG, factVariables, deepcopy(factor.dfgNode))
353-
# end
354-
# end
355-
# end
356-
# return nothing
357-
# end
358-
359324
"""
360325
$(SIGNATURES)
361326
Retrieve a deep subgraph copy around a given variable or factor.

src/LightDFG/services/LightDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,17 @@ end
273273

274274
function _isready(dfg::LightDFG, label::Symbol, ready::Int)::Bool
275275

276-
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].ready == ready)
277-
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].ready == ready)
276+
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready)
277+
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready)
278278

279279
#TODO should this be a breaking error?
280280
@error "Node not in factor or variable"
281281
return false
282282
end
283283

284284
function _isbackendset(dfg::LightDFG, label::Symbol, backendset::Int)::Bool
285-
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].backendset == backendset)
286-
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].backendset == backendset)
285+
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solveInProgress == backendset)
286+
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solveInProgress == backendset)
287287

288288
#TODO should this be a breaking error?
289289
@error "Node not a factor or variable"

src/MetaGraphsDFG/services/MetaGraphsDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ hasOrphans(dfg::MetaGraphsDFG)::Bool = !isFullyConnected(dfg)
318318

319319
function _isready(dfg::MetaGraphsDFG, idx::Int, ready::Int)::Bool
320320
p = props(dfg.g, idx)
321-
haskey(p, :variable) && (return p[:variable].ready == ready)
322-
haskey(p, :factor) && (return p[:factor].ready == ready)
321+
haskey(p, :variable) && (return p[:variable].solvable >= ready)
322+
haskey(p, :factor) && (return p[:factor].solvable >= ready)
323323

324324
#TODO should this be an error?
325325
@warn "Node not a factor or variable"
@@ -328,8 +328,8 @@ end
328328

329329
function _isbackendset(dfg::MetaGraphsDFG, idx::Int, backendset::Int)::Bool
330330
p = props(dfg.g, idx)
331-
haskey(p, :variable) && (return p[:variable].backendset == backendset)
332-
haskey(p, :factor) && (return p[:factor].backendset == backendset)
331+
haskey(p, :variable) && (return p[:variable].solveInProgress == backendset)
332+
haskey(p, :factor) && (return p[:factor].solveInProgress == backendset)
333333

334334
#TODO should this be an error?
335335
@warn "Node not a factor or variable"

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ hasOrphans(dfg::SymbolDFG)::Bool = !isFullyConnected(dfg)
275275

276276
function _isready(dfg::SymbolDFG, label::Symbol, ready::Int)::Bool
277277

278-
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].ready == ready)
279-
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].ready == ready)
278+
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready)
279+
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready)
280280

281281
#TODO should this be a breaking error?
282282
@error "Node not in factor or variable"
283283
return false
284284
end
285285

286286
function _isbackendset(dfg::SymbolDFG, label::Symbol, backendset::Int)::Bool
287-
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].backendset == backendset)
288-
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].backendset == backendset)
287+
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solveInProgress == backendset)
288+
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solveInProgress == backendset)
289289

290290
#TODO should this be a breaking error?
291291
@error "Node not a factor or variable"

src/entities/DFGFactor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ mutable struct DFGFactor{T, S} <: AbstractDFGFactor
3838
label::Symbol
3939
tags::Vector{Symbol}
4040
data::GenericFunctionNodeData{T, S}
41-
ready::Int
42-
backendset::Int
41+
solvable::Int
42+
solveInProgress::Int
4343
_internalId::Int64
4444
_variableOrderSymbols::Vector{Symbol}
4545
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, 0, Symbol[])

src/entities/DFGVariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ mutable struct DFGVariable <: AbstractDFGVariable
114114
solverDataDict::Dict{Symbol, VariableNodeData}
115115
smallData::Dict{String, String}
116116
bigData::Dict{Symbol, AbstractBigDataEntry}
117-
ready::Int
118-
backendset::Int
117+
solvable::Int
118+
solveInProgress::Int
119119
_internalId::Int64
120120
end
121121

src/services/AbstractDFG.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,11 @@ end
332332
333333
Variables or factors may or may not be 'solvable', depending on a user definition. Useful for ensuring atomic transactions.
334334
335-
DevNotes:
336-
- Will be renamed to `var.solvable` -- see DFG #201
337-
338335
Related
339336
340337
isSolveInProgress
341338
"""
342-
isSolvable(var::Union{DFGVariable, DFGFactor}) = var.ready
339+
isSolvable(var::Union{DFGVariable, DFGFactor}) = var.solvable
343340

344341
"""
345342
$SIGNATURES
@@ -353,7 +350,7 @@ Related
353350
354351
isSolvable
355352
"""
356-
isSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default) = var.backendset
353+
isSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default) = var.solveInProgress
357354

358355
"""
359356
$(SIGNATURES)

src/services/DFGFactor.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
2525
# Include the type
2626
props["fnctype"] = String(_getname(fnctype))
2727
props["_variableOrderSymbols"] = JSON2.write(f._variableOrderSymbols)
28-
props["backendset"] = f.backendset
29-
props["ready"] = f.ready
28+
props["solveInProgress"] = f.solveInProgress
29+
props["solvable"] = f.solvable
3030

3131
return props
3232
end
@@ -54,16 +54,16 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}, iifModule)::DFGFac
5454

5555
# Include the type
5656
_variableOrderSymbols = JSON2.read(packedProps["_variableOrderSymbols"], Vector{Symbol})
57-
backendset = packedProps["backendset"]
58-
ready = packedProps["ready"]
57+
solveInProgress = packedProps["solveInProgress"]
58+
solvable = packedProps["solvable"]
5959

6060
# Rebuild DFGVariable
6161
factor = DFGFactor{typeof(fullFactor.fnc), Symbol}(Symbol(label))
6262
factor.tags = tags
6363
factor.data = fullFactor
6464
factor._variableOrderSymbols = _variableOrderSymbols
65-
factor.ready = ready
66-
factor.backendset = backendset
65+
factor.solvable = solvable
66+
factor.solveInProgress = solveInProgress
6767

6868
# GUARANTEED never to bite us in the ass in the future...
6969
# ... TODO: refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350

src/services/DFGVariable.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
88
props["estimateDict"] = JSON2.write(v.estimateDict)
99
props["solverDataDict"] = JSON2.write(Dict(keys(v.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(v.solverDataDict))))
1010
props["smallData"] = JSON2.write(v.smallData)
11-
props["ready"] = v.ready
12-
props["backendset"] = v.backendset
11+
props["solvable"] = v.solvable
12+
props["solveInProgress"] = v.solveInProgress
1313
return props
1414
end
1515

@@ -32,8 +32,8 @@ function unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable whe
3232
variable.estimateDict = estimateDict
3333
variable.solverDataDict = solverData
3434
variable.smallData = smallData
35-
variable.ready = packedProps["ready"]
36-
variable.backendset = packedProps["backendset"]
35+
variable.solvable = packedProps["solvable"]
36+
variable.solveInProgress = packedProps["solveInProgress"]
3737

3838
return variable
3939
end

0 commit comments

Comments
 (0)