Skip to content

Commit 83c76be

Browse files
committed
Updates moving around code and deprecating functions
2 parents 7f720b4 + 735e8ec commit 83c76be

File tree

13 files changed

+315
-201
lines changed

13 files changed

+315
-201
lines changed

src/CloudGraphsDFG/CloudGraphsDFG.jl

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

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
255255
# props["label"] = Symbol(variable.label)
256256
timestamp = DateTime(props["timestamp"])
257257
tags = JSON2.read(props["tags"], Vector{Symbol})
258-
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, VariableEstimate})
258+
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
259259
smallData = nothing
260260
smallData = JSON2.read(props["smallData"], Dict{String, String})
261261

@@ -389,6 +389,20 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
389389
return variable
390390
end
391391

392+
"""
393+
$(SIGNATURES)
394+
Update solver and estimate data for a variable (variable can be from another graph).
395+
"""
396+
function updateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
397+
if !exists(dfg, sourceVariable)
398+
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
399+
end
400+
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sourceVariable.label)
401+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "estimateDict", JSON2.write(sourceVariable.estimateDict))
402+
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "solverDataDict", JSON2.write(Dict(keys(sourceVariable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(sourceVariable.solverDataDict)))))
403+
return sourceVariable
404+
end
405+
392406
"""
393407
$(SIGNATURES)
394408
Update a complete DFGFactor in the DFG.

src/Common.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
export sortVarNested, sortDFG
33
export isPrior, lsfPriors
4-
export getData
54
export getVariableType, getSofttype
65
export getFactorType, getfnctype
76
export lsTypes, lsfTypes
@@ -108,14 +107,6 @@ ls, lsf
108107
"""
109108
sortDFG(vars::Vector{Symbol})::Vector{Symbol} = sortVarNested(vars)
110109

111-
"""
112-
$SIGNATURES
113-
114-
Retrieve data structure stored in a node.
115-
"""
116-
getData(v::DFGFactor)::GenericFunctionNodeData = v.data
117-
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
118-
119110
"""
120111
$SIGNATURES
121112

src/DistributedFactorGraphs.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariab
2525
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
2626

2727
export DFGVariable
28-
export label, timestamp, tags, estimates, estimate, solverData, solverDataDict, id, smallData, bigData
28+
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, internalId, smallData, bigData
2929
export setSolverData
3030
export label, data, id
3131

32+
# Services/AbstractDFG Exports
33+
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
34+
export updateGraphSolverData!
35+
3236
# Solver (IIF) Exports
3337
export VariableNodeData, PackedVariableNodeData, VariableEstimate
3438
export GenericFunctionNodeData#, FunctionNodeData
@@ -72,9 +76,7 @@ function __init__()
7276

7377
end
7478

75-
76-
# not sure where to put
79+
# To be moved as necessary.
7780
include("Common.jl")
78-
include("NeedsAHome.jl")
7981

8082
end

src/FileDFG/services/FileDFG.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function _unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable wh
1616
label = Symbol(packedProps["label"])
1717
timestamp = DateTime(packedProps["timestamp"])
1818
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
19-
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, VariableEstimate})
19+
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
2020
smallData = nothing
2121
smallData = JSON2.read(packedProps["smallData"], Dict{String, String})
2222

@@ -137,10 +137,7 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
137137
end
138138
end
139139

140-
function loadDFG(folder::String,
141-
iifModule,
142-
dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
143-
#
140+
function loadDFG(folder::String, iifModule, dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
144141
variables = DFGVariable[]
145142
factors = DFGFactor[]
146143
varFolder = "$folder/variables"

src/GraphsDFG/GraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export getAddHistory, getDescription, getLabelDict
1313
export addVariable!, addFactor!
1414
export ls, lsf, getVariables, getFactors, getVariableIds, getFactorIds
1515
export getVariable, getFactor
16-
export updateVariable!, updateFactor!
16+
export updateVariable!, updateFactor!, updateVariableSolverData!
1717
export deleteVariable!, deleteFactor!
1818
export getAdjacencyMatrix
1919
export getNeighbors

src/NeedsAHome.jl

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/entities/DFGFactor.jl

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Originally from IncrementalInference
32

43
abstract type InferenceType end
@@ -48,11 +47,44 @@ mutable struct DFGFactor{T, S} <: DFGNode
4847
end
4948

5049
label(f::F) where F <: DFGFactor = f.label
51-
data(f::F) where F <: DFGFactor = f.data
52-
id(f::F) where F <: DFGFactor = f._internalId
50+
"""
51+
$SIGNATURES
52+
53+
Retrieve solver data structure stored in a factor.
54+
"""
55+
function solverData(f::F) where F <: DFGFactor
56+
return f.data
57+
end
58+
"""
59+
$SIGNATURES
60+
61+
Retrieve solver data structure stored in a factor.
62+
"""
63+
function data(f::DFGFactor)::GenericFunctionNodeData
64+
@warn "data() is deprecated, please use solverData()"
65+
return f.data
66+
end
67+
"""
68+
$SIGNATURES
69+
70+
Retrieve solver data structure stored in a factor.
71+
"""
72+
function getData(f::DFGFactor)::GenericFunctionNodeData
73+
@warn "getData is deprecated, please use solverData()"
74+
return f.data
75+
end
76+
77+
internalId(f::F) where F <: DFGFactor = f._internalId
5378

5479
# Simply for convenience - don't export
5580
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
5681
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8)
5782
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
5883
FunctionNodeData(x1, x2, x3, x4, x5::Symbol, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T <: Union{FunctorInferenceType, ConvolutionObject}}= GenericFunctionNodeData{T, Symbol}(x1, x2, x3, x4, x5, x6, x7, x8)
84+
85+
"""
86+
$SIGNATURES
87+
88+
Retrieve data structure stored in a node.
89+
"""
90+
getData(v::DFGFactor)::GenericFunctionNodeData = v.data

src/entities/DFGVariable.jl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ mutable struct PackedVariableNodeData
7272
end
7373

7474
struct VariableEstimate
75-
estimate::Vector{Float64}
75+
solverKey::Symbol
7676
type::Symbol
77-
key::Symbol
77+
estimate::Vector{Float64}
78+
lastUpdatedTimestamp::DateTime
79+
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}, lastUpdatedTimestamp::DateTime=now()) = new(solverKey, type, estimate, lastUpdatedTimestamp)
7880
end
7981

8082
"""
@@ -85,14 +87,14 @@ mutable struct DFGVariable <: DFGNode
8587
label::Symbol
8688
timestamp::DateTime
8789
tags::Vector{Symbol}
88-
estimateDict::Dict{Symbol, VariableEstimate}
90+
estimateDict::Dict{Symbol, Dict{Symbol, VariableEstimate}}
8991
solverDataDict::Dict{Symbol, VariableNodeData}
9092
smallData::Dict{String, String}
9193
bigData::Any
9294
ready::Int
9395
backendset::Int
9496
_internalId::Int64
95-
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
97+
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
9698
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, 0)
9799
end
98100

@@ -102,11 +104,29 @@ timestamp(v::DFGVariable) = v.timestamp
102104
tags(v::DFGVariable) = v.tags
103105
estimates(v::DFGVariable) = v.estimateDict
104106
estimate(v::DFGVariable, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
105-
#solverData(v::DFGVariable) = haskey(v.solverDataDict, :default) ? v.solverDataDict[:default] : nothing
107+
"""
108+
$SIGNATURES
109+
110+
Retrieve solver data structure stored in a variable.
111+
"""
106112
solverData(v::DFGVariable, key::Symbol=:default) = haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
113+
"""
114+
$SIGNATURES
115+
116+
Retrieve data structure stored in a variable.
117+
"""
118+
function getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData
119+
@warn "getData is deprecated, please use solverData()"
120+
return v.solverDataDict[solveKey]
121+
end
122+
"""
123+
$SIGNATURES
124+
125+
Set solver data structure stored in a variable.
126+
"""
107127
setSolverData(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
108128
solverDataDict(v::DFGVariable) = v.solverDataDict
109-
id(v::DFGVariable) = v._internalId
129+
internalId(v::DFGVariable) = v._internalId
110130
# Todo: Complete this.
111131
smallData(v::DFGVariable) = v.smallData
112132
bigData(v::DFGVariable) = v.bigData

0 commit comments

Comments
 (0)