Skip to content

Commit 3ed1833

Browse files
authored
Merge pull request #390 from JuliaRobotics/maint/20Q2/varfacCRUD
CGDFG and GraphsDFG fix for #375 and `factor.data` usage
2 parents 1b207ea + a3f213d commit 3ed1833

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})::DFGVari
221221
if typeof(label) == String
222222
label = Symbol(label)
223223
end
224-
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, label)
224+
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, label, nodeType="VARIABLE")
225225
if nodeId == nothing
226226
error("Unable to retrieve the ID for variable '$label'. Please check your connection to the database and that the variable exists.")
227227
end
@@ -240,7 +240,7 @@ function getFactor(dfg::CloudGraphsDFG, label::Union{Symbol, String})::DFGFactor
240240
if typeof(label) == String
241241
label = Symbol(label)
242242
end
243-
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, label)
243+
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, label, nodeType="FACTOR")
244244
if nodeId == nothing
245245
error("Unable to retrieve the ID for factor '$label'. Please check your connection to the database and that the factor exists.")
246246
end

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,15 @@ end
160160
$(SIGNATURES)
161161
Try get a Neo4j node ID from a node label.
162162
"""
163-
function _tryGetNeoNodeIdFromNodeLabel(neo4jInstance::Neo4jInstance, userId::String, robotId::String, sessionId::String, nodeLabel::Symbol)::Union{Nothing, Int}
163+
function _tryGetNeoNodeIdFromNodeLabel(neo4jInstance::Neo4jInstance, userId::String, robotId::String, sessionId::String, nodeLabel::Symbol; nodeType::Union{Nothing, String}=nothing)::Union{Nothing, Int}
164164
@debug "Looking up symbolic node ID where n.label = '$nodeLabel'..."
165-
nodes = _getNeoNodesFromCyphonQuery(neo4jInstance, "(node:$userId:$robotId:$sessionId) where exists(node.label) and node.label = \"$(string(nodeLabel))\"")
166-
if(length(nodes) != 1)
165+
if nodeType == nothing
166+
nodes = _getNeoNodesFromCyphonQuery(neo4jInstance, "(node:$userId:$robotId:$sessionId) where exists(node.label) and node.label = \"$(string(nodeLabel))\"")
167+
else
168+
nodes = _getNeoNodesFromCyphonQuery(neo4jInstance, "(node:$nodeType:$userId:$robotId:$sessionId) where exists(node.label) and node.label = \"$(string(nodeLabel))\"")
169+
end
170+
171+
if length(nodes) != 1
167172
return nothing
168173
end
169174
nodeId = nodes[1].id

src/Deprecated.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ Base.getproperty(x::DFGFactor,f::Symbol) = begin
3838
elseif f == :_internalId
3939
getfield(x,:_dfgNodeParams)._internalId
4040
elseif f == :data
41-
42-
if !(@isdefined getFactorDataWarnOnce)
43-
@warn "get: data field is deprecated, use getSolverData. Further warnings are suppressed"
44-
global getFactorDataWarnOnce = true
45-
end
46-
41+
Base.depwarn("DFGFactor get: data field is deprecated, use getSolverData", :getproperty)
4742
getfield(x, :solverData)
4843
else
4944
getfield(x,f)
@@ -57,12 +52,7 @@ Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
5752
elseif f == :_internalId
5853
getfield(x,:_dfgNodeParams)._internalId = val
5954
elseif f == :data
60-
61-
if !(@isdefined setFactorDataWarnOnce)
62-
@warn "set: data field is deprecated, use ...TODO? Further warnings are suppressed"
63-
global setFactorDataWarnOnce = true
64-
end
65-
55+
Base.depwarn("DFGFactor set: data field is deprecated, use getSolverData", :getproperty)
6656
setfield!(x,:solverData, val)
6757
else
6858
setfield!(x,f,val)

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ function getVariable(dfg::GraphsDFG, label::Union{Symbol, String})::DFGVariable
121121
if !haskey(dfg.labelDict, label)
122122
error("Variable label '$(label)' does not exist in the factor graph")
123123
end
124-
return dfg.g.vertices[dfg.labelDict[label]].dfgNode
124+
node = dfg.g.vertices[dfg.labelDict[label]].dfgNode
125+
!isa(node, AbstractDFGVariable) && error("Node with label '$(label)' is not a variable")
126+
return node
125127
end
126128

127129
function getFactor(dfg::GraphsDFG, factorId::Int64)::DFGFactor
@@ -140,7 +142,9 @@ function getFactor(dfg::GraphsDFG, label::Union{Symbol, String})::DFGFactor
140142
if !haskey(dfg.labelDict, label)
141143
error("Factor label '$(label)' does not exist in the factor graph")
142144
end
143-
return dfg.g.vertices[dfg.labelDict[label]].dfgNode
145+
node = dfg.g.vertices[dfg.labelDict[label]].dfgNode
146+
!isa(node, AbstractDFGFactor) && error("Node with label '$(label)' is not a factor")
147+
return node
144148
end
145149

146150
function updateVariable!(dfg::GraphsDFG, variable::DFGVariable)::DFGVariable

src/services/Serialization.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
9898
props["timestamp"] = string(f.timestamp)
9999
props["tags"] = JSON2.write(f.tags)
100100
# Pack the node data
101-
fnctype = f.data.fnc.usrfnc!
101+
fnctype = getSolverData(f).fnc.usrfnc!
102102
try
103103
packtype = getfield(_getmodule(fnctype), Symbol("Packed$(_getname(fnctype))"))
104-
packed = convert(PackedFunctionNodeData{packtype}, f.data)
104+
packed = convert(PackedFunctionNodeData{packtype}, getSolverData(f))
105105
props["data"] = JSON2.write(packed)
106106
catch ex
107107
io = IOBuffer()
@@ -149,7 +149,8 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G
149149
factor = DFGFactor{typeof(fullFactor.fnc), Symbol}(Symbol(label), 0, timestamp)
150150

151151
union!(factor.tags, tags)
152-
factor.data = fullFactor #TODO setSolverData!(factor, fullFactor)
152+
# factor.data = fullFactor #TODO
153+
setSolverData!(factor, fullFactor)
153154
factor._variableOrderSymbols = _variableOrderSymbols
154155
setSolvable!(factor, solvable)
155156

test/testBlocks.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ struct TestFunctorSingleton <: FunctorSingleton end
2424
struct TestFunctorPairwise <: FunctorPairwise end
2525
struct TestFunctorPairwiseMinimize <: FunctorPairwiseMinimize end
2626

27+
struct PackedTestFunctorInferenceType1 end
28+
Base.convert(::Type{GenericFunctionNodeData{PackedTestFunctorInferenceType1,AbstractString}}, d) = d
29+
2730
struct TestCCW{T} <: ConvolutionObject where {T<:FunctorInferenceType}
2831
usrfnc!::T
2932
end
@@ -338,7 +341,7 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
338341
#deletions
339342
@test getVariable(fg, :c) === deleteVariable!(fg, v3)
340343
@test_throws ErrorException deleteVariable!(fg, v3)
341-
@test setdiff(ls(fg),[:a,:b]) == []
344+
@test issetequal(ls(fg),[:a,:b])
342345
@test getFactor(fg, :bcf1) === deleteFactor!(fg, f2)
343346
@test_throws ErrorException deleteFactor!(fg, f2)
344347
@test lsf(fg) == [:abf1]
@@ -356,14 +359,14 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
356359
@test_logs (:warn, r"supported for type DFGVariable") getVariable(fg, :a, :missingfoo)
357360
end
358361

359-
@test getFactor(fg, :abf1) === f1
362+
@test getFactor(fg, :abf1) == f1
360363

361364
@test_throws ErrorException getVariable(fg, :c)
362365
@test_throws ErrorException getFactor(fg, :bcf1)
363366

364367
#test issue #375
365-
@test_skip @test_throws ErrorException getVariable(fg, :abf1)
366-
@test_skip @test_throws ErrorException getFactor(fg, :a)
368+
@test_throws ErrorException getVariable(fg, :abf1)
369+
@test_throws ErrorException getFactor(fg, :a)
367370

368371
# Existence
369372
@test exists(fg, :a)

0 commit comments

Comments
 (0)