Skip to content

Commit

Permalink
Merge pull request #105 from JuliaRobotics/feature/serializationand0_4
Browse files Browse the repository at this point in the history
Feature/serializationand0 4
  • Loading branch information
GearsAD authored Sep 26, 2019
2 parents 306090f + 15f7237 commit 735e8ec
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 199 deletions.
2 changes: 1 addition & 1 deletion src/CloudGraphsDFG/CloudGraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export getAddHistory, getDescription, getLabelDict
export addVariable!, addFactor!
export ls, lsf, getVariables, getFactors, getVariableIds, getFactorIds
export getVariable, getFactor
export updateVariable!, updateFactor!
export updateVariable!, updateFactor!, updateVariableSolverData!
export deleteVariable!, deleteFactor!
export getAdjacencyMatrix
export getNeighbors
Expand Down
16 changes: 15 additions & 1 deletion src/CloudGraphsDFG/services/CloudGraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
# props["label"] = Symbol(variable.label)
timestamp = DateTime(props["timestamp"])
tags = JSON2.read(props["tags"], Vector{Symbol})
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, VariableEstimate})
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
smallData = nothing
smallData = JSON2.read(props["smallData"], Dict{String, String})

Expand Down Expand Up @@ -389,6 +389,20 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
return variable
end

"""
$(SIGNATURES)
Update solver and estimate data for a variable (variable can be from another graph).
"""
function updateVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)::DFGVariable
if !exists(dfg, sourceVariable)
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
end
nodeId = _tryGetNeoNodeIdFromNodeLabel(dfg.neo4jInstance, dfg.userId, dfg.robotId, dfg.sessionId, sourceVariable.label)
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "estimateDict", JSON2.write(sourceVariable.estimateDict))
Neo4j.setnodeproperty(dfg.neo4jInstance.graph, nodeId, "solverDataDict", JSON2.write(Dict(keys(sourceVariable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(sourceVariable.solverDataDict)))))
return sourceVariable
end

"""
$(SIGNATURES)
Update a complete DFGFactor in the DFG.
Expand Down
9 changes: 0 additions & 9 deletions src/Common.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export sortVarNested
export isPrior, lsfPriors
export getData
export getVariableType, getSofttype
export getFactorType, getfnctype
export lsTypes, lsfTypes
Expand Down Expand Up @@ -89,14 +88,6 @@ function sortVarNested(vars::Vector{Symbol})::Vector{Symbol}
return retvars
end

"""
$SIGNATURES
Retrieve data structure stored in a node.
"""
getData(v::DFGFactor)::GenericFunctionNodeData = v.data
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]

"""
$SIGNATURES
Expand Down
10 changes: 6 additions & 4 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariab
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize

export DFGVariable
export label, timestamp, tags, estimates, estimate, solverData, solverDataDict, id, smallData, bigData
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, internalId, smallData, bigData
export setSolverData
export label, data, id

# Services/AbstractDFG Exports
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
export updateGraphSolverData!

# Solver (IIF) Exports
export VariableNodeData, PackedVariableNodeData, VariableEstimate
export GenericFunctionNodeData#, FunctionNodeData
Expand Down Expand Up @@ -72,9 +76,7 @@ function __init__()

end


# not sure where to put
# To be moved as necessary.
include("Common.jl")
include("NeedsAHome.jl")

end
7 changes: 2 additions & 5 deletions src/FileDFG/services/FileDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function _unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable wh
label = Symbol(packedProps["label"])
timestamp = DateTime(packedProps["timestamp"])
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, VariableEstimate})
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
smallData = nothing
smallData = JSON2.read(packedProps["smallData"], Dict{String, String})

Expand Down Expand Up @@ -137,10 +137,7 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
end
end

function loadDFG(folder::String,
iifModule,
dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
#
function loadDFG(folder::String, iifModule, dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
variables = DFGVariable[]
factors = DFGFactor[]
varFolder = "$folder/variables"
Expand Down
2 changes: 1 addition & 1 deletion src/GraphsDFG/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export getAddHistory, getDescription, getLabelDict
export addVariable!, addFactor!
export ls, lsf, getVariables, getFactors, getVariableIds, getFactorIds
export getVariable, getFactor
export updateVariable!, updateFactor!
export updateVariable!, updateFactor!, updateVariableSolverData!
export deleteVariable!, deleteFactor!
export getAdjacencyMatrix
export getNeighbors
Expand Down
74 changes: 0 additions & 74 deletions src/NeedsAHome.jl

This file was deleted.

9 changes: 8 additions & 1 deletion src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ end

label(f::F) where F <: DFGFactor = f.label
data(f::F) where F <: DFGFactor = f.data
id(f::F) where F <: DFGFactor = f._internalId
internalId(f::F) where F <: DFGFactor = f._internalId

# Simply for convenience - don't export
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
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)
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
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)

"""
$SIGNATURES
Retrieve data structure stored in a node.
"""
getData(v::DFGFactor)::GenericFunctionNodeData = v.data
14 changes: 8 additions & 6 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ mutable struct PackedVariableNodeData
end

struct VariableEstimate
estimate::Vector{Float64}
solverKey::Symbol
type::Symbol
key::Symbol
estimate::Vector{Float64}
lastUpdatedTimestamp::DateTime
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}, lastUpdatedTimestamp::DateTime=now()) = new(solverKey, type, estimate, lastUpdatedTimestamp)
end

"""
Expand All @@ -85,14 +87,14 @@ mutable struct DFGVariable <: DFGNode
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, VariableEstimate}
estimateDict::Dict{Symbol, Dict{Symbol, VariableEstimate}}
solverDataDict::Dict{Symbol, VariableNodeData}
smallData::Dict{String, String}
bigData::Any
ready::Int
backendset::Int
_internalId::Int64
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
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)
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, 0)
end

Expand All @@ -102,11 +104,11 @@ timestamp(v::DFGVariable) = v.timestamp
tags(v::DFGVariable) = v.tags
estimates(v::DFGVariable) = v.estimateDict
estimate(v::DFGVariable, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
#solverData(v::DFGVariable) = haskey(v.solverDataDict, :default) ? v.solverDataDict[:default] : nothing
solverData(v::DFGVariable, key::Symbol=:default) = haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
setSolverData(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
solverDataDict(v::DFGVariable) = v.solverDataDict
id(v::DFGVariable) = v._internalId
internalId(v::DFGVariable) = v._internalId
# Todo: Complete this.
smallData(v::DFGVariable) = v.smallData
bigData(v::DFGVariable) = v.bigData
Loading

0 comments on commit 735e8ec

Please sign in to comment.