Skip to content

Commit 735e8ec

Browse files
authored
Merge pull request #105 from JuliaRobotics/feature/serializationand0_4
Feature/serializationand0 4
2 parents 306090f + 15f7237 commit 735e8ec

File tree

13 files changed

+266
-199
lines changed

13 files changed

+266
-199
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,6 +1,5 @@
11
export sortVarNested
22
export isPrior, lsfPriors
3-
export getData
43
export getVariableType, getSofttype
54
export getFactorType, getfnctype
65
export lsTypes, lsfTypes
@@ -89,14 +88,6 @@ function sortVarNested(vars::Vector{Symbol})::Vector{Symbol}
8988
return retvars
9089
end
9190

92-
"""
93-
$SIGNATURES
94-
95-
Retrieve data structure stored in a node.
96-
"""
97-
getData(v::DFGFactor)::GenericFunctionNodeData = v.data
98-
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
99-
10091
"""
10192
$SIGNATURES
10293

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ end
4949

5050
label(f::F) where F <: DFGFactor = f.label
5151
data(f::F) where F <: DFGFactor = f.data
52-
id(f::F) where F <: DFGFactor = f._internalId
52+
internalId(f::F) where F <: DFGFactor = f._internalId
5353

5454
# Simply for convenience - don't export
5555
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
5656
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)
5757
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
5858
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)
59+
60+
"""
61+
$SIGNATURES
62+
63+
Retrieve data structure stored in a node.
64+
"""
65+
getData(v::DFGFactor)::GenericFunctionNodeData = v.data

src/entities/DFGVariable.jl

Lines changed: 8 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,11 @@ 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
106107
solverData(v::DFGVariable, key::Symbol=:default) = haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
108+
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
107109
setSolverData(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
108110
solverDataDict(v::DFGVariable) = v.solverDataDict
109-
id(v::DFGVariable) = v._internalId
111+
internalId(v::DFGVariable) = v._internalId
110112
# Todo: Complete this.
111113
smallData(v::DFGVariable) = v.smallData
112114
bigData(v::DFGVariable) = v.bigData

0 commit comments

Comments
 (0)