Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more functions for SDK and deprecate some smalldata functions #1107

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/GraphData.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ itself, large entries will slow the graph down, so if data should exceed a
few bytes/kb, it should rather be saved in bigData.


- [`getSmallData`](@ref)
- [`setSmallData!`](@ref)
- [`getMetadata`](@ref)
- [`setMetadata!`](@ref)


Example:

```julia
setSmallData!(x0, Dict("entry"=>"entry value"))
getSmallData(x0)
setMetadata!(x0, Dict("entry"=>"entry value"))
getMetadata(x0)
```

#### Big Data
Expand Down
6 changes: 4 additions & 2 deletions src/DataBlobs/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ end
# label
# id

getLabel(entry::BlobEntry) = entry.label
getId(entry::BlobEntry) = entry.id
getHash(entry::BlobEntry) = hex2bytes(entry.hash)
getTimestamp(entry::BlobEntry) = entry.timestamp

Expand Down Expand Up @@ -173,6 +171,10 @@ function addBlobEntry!(dfg::AbstractDFG, vLbl::Symbol, entry::BlobEntry;)
return addBlobEntry!(getVariable(dfg, vLbl), entry)
end

function addBlobEntries!(dfg::AbstractDFG, vLbl::Symbol, entries::Vector{BlobEntry})
return addBlobEntry!.(dfg, vLbl, entries)
end

"""
$(SIGNATURES)
Update data entry
Expand Down
11 changes: 11 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export DFGSummary
DFGSummary(args) = error("DFGSummary is deprecated")
@deprecate getSummary(dfg::AbstractDFG) getSummaryGraph(dfg)

##------------------------------------------------------------------------------
## smallData
##------------------------------------------------------------------------------
@deprecate getSmallData(args...) getMetadata(args...)
@deprecate setSmallData!(args...) setMetadata!(args...)
@deprecate addSmallData!(args...) addMetadata!(args...)
@deprecate updateSmallData!(args...) updateMetadata!(args...)
@deprecate deleteSmallData!(args...) deleteMetadata!(args...)
@deprecate listSmallData(args...) listMetadata(args...)
@deprecate emptySmallData!(args...) emptyMetadata!(args...)

## ================================================================================
## Deprecated in v0.24
##=================================================================================
Expand Down
29 changes: 21 additions & 8 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ export getDimension, getManifold, getPointType
export getPointIdentity, getPoint, getCoordinates

# Small Data CRUD
export SmallDataTypes,
getSmallData,
addSmallData!,
updateSmallData!,
deleteSmallData!,
listSmallData,
emptySmallData!
export getSmallData, setSmallData!
export SmallDataTypes
export getMetadata,
setMetadata!,
addMetadata!,
updateMetadata!,
deleteMetadata!,
listMetadata,
emptyMetadata!

# CRUD & SET
export getVariableSolverData,
Expand Down Expand Up @@ -239,6 +239,7 @@ export getBlobEntriesVariables
# aliases
export addBlob!
export packBlob, unpackBlob
export @format_str

##------------------------------------------------------------------------------
# Factors
Expand Down Expand Up @@ -326,6 +327,18 @@ export getData, addData!, updateData!, deleteData!

export plotDFG

## TODO maybe move to DFG
# addAgent!
# listAgents
# addGraph!
# deleteGraph!
# listGraphs
# getAgents
# getModel
# getModels
# addModel!
# getGraphs

##==============================================================================
## Files Includes
##==============================================================================
Expand Down
3 changes: 0 additions & 3 deletions src/entities/Agent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@
metadata::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
blobEntries::OrderedDict{Symbol, BlobEntry} = OrderedDict{Symbol, BlobEntry}()
end

getLabel(a::Agent) = a.label
getMetadata(a::Agent) = a.metadata
2 changes: 1 addition & 1 deletion src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Base.@kwdef struct DFGFactor{T, N} <: AbstractDFGFactor
Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)"""
solvable::Base.RefValue{Int}
"""Dictionary of small data associated with this variable.
Accessors: [`getSmallData`](@ref), [`setSmallData!`](@ref)"""
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
smallData::Dict{Symbol, SmallDataTypes}
# Inner constructor
function DFGFactor{T}(
Expand Down
18 changes: 17 additions & 1 deletion src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ StructTypes.StructType(::Type{Variable}) = StructTypes.UnorderedStruct()
StructTypes.idproperty(::Type{Variable}) = :id
StructTypes.omitempties(::Type{Variable}) = (:id,)

function getMetadata(v::Variable)
return JSON3.read(base64decode(v.metadata), Dict{Symbol, SmallDataTypes})
end

function setMetadata!(v::Variable, metadata::Dict{Symbol, SmallDataTypes})
return error("FIXME: Metadata is not currently mutable in a Variable")
# v.metadata = base64encode(JSON3.write(metadata))
end

##------------------------------------------------------------------------------
## DFGVariable lv2
##------------------------------------------------------------------------------
Expand Down Expand Up @@ -297,7 +306,7 @@ Base.@kwdef struct DFGVariable{T <: InferenceVariable, P, N} <: AbstractDFGVaria
solverDataDict::Dict{Symbol, VariableNodeData{T, P, N}} =
Dict{Symbol, VariableNodeData{T, P, N}}()
"""Dictionary of small data associated with this variable.
Accessors: [`getSmallData`](@ref), [`setSmallData!`](@ref)"""
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
"""Dictionary of large data associated with this variable.
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`updateBlobEntry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
Expand Down Expand Up @@ -352,6 +361,13 @@ Base.setproperty!(x::DFGVariable, f::Symbol, val) = begin
end
end

getMetadata(v::DFGVariable) = v.smallData

function setMetadata!(v::DFGVariable, metadata::Dict{Symbol, SmallDataTypes})
v.smallData !== metadata && empty!(v.smallData)
return merge!(v.smallData, metadata)
end

##------------------------------------------------------------------------------
## DFGVariableSummary lv1
##------------------------------------------------------------------------------
Expand Down
86 changes: 67 additions & 19 deletions src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ Base.Broadcast.broadcastable(dfg::AbstractDFG) = Ref(dfg)
##------------------------------------------------------------------------------
## Getters
##------------------------------------------------------------------------------
"""
$(SIGNATURES)
Get the id of the node.
"""
getId(node) = node.id

"""
$(SIGNATURES)
Get the label of the node.
"""
getLabel(node) = node.label

"""
$SIGNATURES

Get the metadata of the node.
"""
getMetadata(node) = node.metadata

"""
$(SIGNATURES)
Convenience function to get all the metadata of a DFG
Expand Down Expand Up @@ -120,6 +139,15 @@ function getTypeDFGFactors end
##------------------------------------------------------------------------------
## Setters
##------------------------------------------------------------------------------
"""
$SIGNATURES
Set the metadata of the node.
"""
function setMetadata!(node, metadata::Dict{Symbol, SmallDataTypes})
# with set old data should be removed, but care is taken to make sure its not the same object
node.metadata !== metadata && empty!(node.metadata)
return merge!(node.metadata, metadata)
end

"""
$(SIGNATURES)
Expand All @@ -140,24 +168,6 @@ end
"""
$SIGNATURES

Get the metadata of the node.
"""
getMetadata(node) = node.metadata

"""
$SIGNATURES

Set the metadata of the node.
"""
function setMetadata!(node, metadata::Dict{Symbol, SmallDataTypes})
# with set old data should be removed, but care is taken to make sure its not the same object
node.metadata !== metadata && empty!(node.metadata)
return merge!(node.metadata, metadata)
end

"""
$SIGNATURES

Get the metadata from the agent in the AbstractDFG.
"""
getAgentMetadata(dfg::AbstractDFG) = getMetadata(getAgent(dfg))
Expand Down Expand Up @@ -212,7 +222,7 @@ emptyGraphMetadata!(dfg::AbstractDFG) = empty!(dfg.graphMetadata)
#TODO add__Data!?

##==============================================================================
## Agent/Graph Blob Entries CRUD
## Agent/Graph/Model Blob Entries CRUD
##==============================================================================

function getGraphBlobEntry end
Expand All @@ -229,8 +239,16 @@ function addAgentBlobEntries! end
function updateAgentBlobEntry! end
function deleteAgentBlobEntry! end

function getModelBlobEntry end
function getModelBlobEntries end
function addModelBlobEntry! end
function addModelBlobEntries! end
function updateModelBlobEntry! end
function deleteModelBlobEntry! end

function listGraphBlobEntries end
function listAgentBlobEntries end
function listModelBlobEntries end

##==============================================================================
## AbstractBlobStore CRUD
Expand Down Expand Up @@ -315,6 +333,30 @@ function getVariable(dfg::G, label::Union{Symbol, String}) where {G <: AbstractD
return error("getVariable not implemented for $(typeof(dfg))")
end

"""
$(SIGNATURES)
Get a VariableSummary from a DFG.
"""
function getVariableSummary end

"""
$(SIGNATURES)
Get the variables from a DFG as a Vector{VariableSummary}.
"""
function getVariablesSummary end

"""
$(SIGNATURES)
Get a VariableSkeleton from a DFG.
"""
function getVariableSkeleton end

"""
$(SIGNATURES)
Get the variables from a DFG as a Vector{VariableSkeleton}.
"""
function getVariablesSkeleton end

"""
$(SIGNATURES)
Get a DFGFactor from a DFG using its label.
Expand All @@ -323,6 +365,12 @@ function getFactor(dfg::G, label::Union{Symbol, String}) where {G <: AbstractDFG
return error("getFactor not implemented for $(typeof(dfg))")
end

"""
$(SIGNATURES)
Get the skeleton factors from a DFG as a Vector{FactorSkeleton}.
"""
function getFactorsSkeleton end

function Base.getindex(dfg::AbstractDFG, lbl::Union{Symbol, String})
if isVariable(dfg, lbl)
getVariable(dfg, lbl)
Expand Down
Loading
Loading