Skip to content

Commit 5cd7792

Browse files
committed
PPE calls, WIP on smallData
1 parent d770461 commit 5cd7792

File tree

6 files changed

+199
-18
lines changed

6 files changed

+199
-18
lines changed

docs/src/GraphData.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,59 @@ getSofttype
8989

9090
Solved graphs contain packed parametric estimates for the variables, which are keyed by the solution (the default is saved as :default).
9191

92+
For each PPE structure, there are accessors for getting individual values:
93+
9294
```@docs
9395
getMaxPPE
9496
getMeanPPE
9597
getSuggestedPPE
96-
getVariablePPE
9798
getPPE
98-
getVariablePPEs
99-
getPPEs
99+
```
100+
101+
Related functions for getting, adding/updating, and deleting PPE structures:
102+
103+
```@docs
104+
listPPE
105+
getPPE
106+
addPPE!
107+
updatePPE!
108+
deletePPE!
109+
```
110+
111+
Example of PPE operations:
112+
113+
```julia
114+
# Add a new PPE of type MeanMaxPPE to :x0
115+
ppe = MeanMaxPPE(:default, [0.0], [0.0], [0.0])
116+
addPPE!(dfg, :x0, ppe)
117+
@show listPPE(dfg, :x0)
118+
# Get the data back - note that this is a reference to above.
119+
v = getPPE(dfg, :x0, :default)
120+
# Delete it
121+
deletePPE!(dfg, :x0, :default)
122+
# Update add it
123+
updatePPE!(dfg, :x0, ppe, :default)
124+
# Update update it
125+
updatePPE!(dfg, :x0, ppe, :default)
126+
# Bulk copy PPE's for x0 and x1
127+
updatePPE!(dfg, [x0], :default)
100128
```
101129

102130
#### Solver Data
103131

104132
Solver data is used by IncrementalInference/RoME/Caesar solver to produce the above PPEs.
105133

106-
Example of updating solver data:
134+
Related functions:
135+
136+
```@docs
137+
listVariableSolverData
138+
getVariableSolverData
139+
addVariableSolverData!
140+
updateVariableSolverData!
141+
deleteVariableSolverData!
142+
```
143+
144+
Example of solver data operations:
107145

108146
```julia
109147
# Add new VND of type ContinuousScalar to :x0
@@ -117,17 +155,24 @@ vndBack = getVariableSolverData(dfg, :x0, :parametric)
117155
deleteVariableSolverData!(dfg, :x0, :parametric)
118156
```
119157

120-
Related Functions:
158+
#### Small Data
159+
160+
Small data allows you to assign a dictionary to variables. It is a useful way to
161+
keep small amounts of string data in a variable. As it is stored in the graph
162+
itself, large entries will slow the graph down, so if data should exceed a
163+
few bytes/kb, it should rather be saved in bigData.
121164

122165
```@docs
123-
listVariableSolverData
124-
getVariableSolverData
125-
addVariableSolverData!
126-
updateVariableSolverData!
127-
deleteVariableSolverData!
166+
getSmallData,
167+
setSmallData!
128168
```
129169

130-
#### Small Data
170+
Example:
171+
172+
```julia
173+
setSmallData!(x0, Dict("entry"=>"entry value"))
174+
getSmallData(x0)
175+
```
131176

132177
#### Big Data
133178

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const DataLevel2 = Union{VariableDataLevel2, FactorDataLevel2}
5757
# Level 0
5858
export getLabel, getTimestamp, setTimestamp!, getTags, setTags!
5959
# Level 1
60-
export getMaxPPE, getMeanPPE, getSuggestedPPE, getVariablePPE, getPPE, getVariablePPEs, getPPEs #, getEstimates
60+
export getMaxPPE, getMeanPPE, getSuggestedPPE, getVariablePPE, getVariablePPEs, getPPEs #, getEstimates
61+
export listPPE, getPPE, addPPE!, updatePPE!, deletePPE!
6162
export getSofttype
6263
# Level 2
6364
export getData, getSolverData, getSolverDataDict, setSolverData!, getInternalId

src/entities/DFGVariable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct DFGVariable{T<:InferenceVariable} <: AbstractDFGVariable
2929
solverDataDict::Dict{Symbol, VariableNodeData{T}}
3030
"""Dictionary of small data associated with this variable.
3131
Accessors: `addSmallData!`, `updateSmallData!`, and `deleteSmallData!`"""
32-
smallData::Dict{String, String}
32+
smallData::Ref{Dict{String, String}}
3333
"""Dictionary of large data associated with this variable.
3434
Accessors: `addBigDataEntry!`, `getBigDataEntry`, `updateBigDataEntry!`, and `deleteBigDataEntry!`"""
3535
bigData::Dict{Symbol, AbstractBigDataEntry}

src/services/AbstractDFG.jl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,105 @@ Delete variable solver data, returns the deleted element.
583583
deleteVariableSolverData!(dfg::AbstractDFG, sourceVariable::DFGVariable, solvekey::Symbol=:default) =
584584
deleteVariableSolverData!(dfg, sourceVariable.label, solvekey)
585585

586+
#####
587+
588+
"""
589+
$(SIGNATURES)
590+
List all the PPE data keys in the variable.
591+
"""
592+
function listPPE(dfg::AbstractDFG, variablekey::Symbol)::Vector{Symbol}
593+
v = getVariable(dfg, variablekey)
594+
return collect(keys(v.ppeDict))
595+
end
596+
597+
"""
598+
$(SIGNATURES)
599+
Get variable PPE for a given solve key.
600+
"""
601+
function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default)::AbstractPointParametricEst
602+
v = getVariable(dfg, variablekey)
603+
!haskey(v.ppeDict, ppekey) && error("PPE key '$ppeKey' not found in variable '$variableKey'")
604+
return v.ppeDict[ppekey]
605+
end
606+
607+
# Not the most efficient call but it at least reuses above (in memory it's probably ok)
608+
getPPE(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=default)::AbstractPointParametricEst = getPPE(dfg, sourceVariable.label, ppekey)
609+
610+
"""
611+
$(SIGNATURES)
612+
Add variable PPE, errors if it already exists.
613+
"""
614+
function addPPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::P, ppekey::Symbol=:default)::Dict{Symbol, AbstractPointParametricEst} where P <: AbstractPointParametricEst
615+
var = getVariable(dfg, variablekey)
616+
if haskey(var.ppeDict, ppekey)
617+
error("PPE '$(ppekey)' already exists")
618+
end
619+
var.ppeDict[ppekey] = ppe
620+
return var.ppeDict
621+
end
622+
623+
"""
624+
$(SIGNATURES)
625+
Add a new PPE entry from a deepcopy of the source variable PPE.
626+
NOTE: Copies the solver data.
627+
"""
628+
addPPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:default) =
629+
addPPE!(dfg, sourceVariable.label, deepcopy(getPPE(sourceVariable, ppekey)), ppekey)
630+
631+
632+
"""
633+
$(SIGNATURES)
634+
Update PPE data if it exists, otherwise add it.
635+
"""
636+
function updatePPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::P, ppekey::Symbol=:default)::Dict{Symbol, AbstractPointParametricEst} where P <: AbstractPointParametricEst
637+
#This is basically just setSolverData
638+
var = getVariable(dfg, variablekey)
639+
#for InMemoryDFGTypes, cloud would update here
640+
var.ppeDict[ppekey] = ppe
641+
return var.ppeDict
642+
end
643+
644+
"""
645+
$(SIGNATURES)
646+
Update PPE data if it exists, otherwise add it.
647+
NOTE: Copies the PPE data.
648+
"""
649+
updatePPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:default) =
650+
updateVariableSolverData!(dfg, sourceVariable.label, deepcopy(getPPE(sourceVariable, ppekey)), ppekey)
651+
652+
"""
653+
$(SIGNATURES)
654+
Update PPE data if it exists, otherwise add it.
655+
"""
656+
function updatePPE!(dfg::AbstractDFG, sourceVariables::Vector{<:DFGVariable}, ppekey::Symbol=:default)
657+
#I think cloud would do this in bulk for speed
658+
for var in sourceVariables
659+
updatePPE!(dfg, var.label, getPPE(dfg, var, ppekey), ppekey)
660+
end
661+
end
662+
663+
"""
664+
$(SIGNATURES)
665+
Delete PPE data, returns the deleted element.
666+
"""
667+
function deletePPE!(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default)::AbstractPointParametricEst
668+
var = getVariable(dfg, variablekey)
669+
670+
if !haskey(var.ppeDict, ppekey)
671+
error("VariableNodeData '$(ppekey)' does not exist")
672+
end
673+
vnd = pop!(var.ppeDict, ppekey)
674+
return vnd
675+
end
676+
677+
"""
678+
$(SIGNATURES)
679+
Delete PPE data, returns the deleted element.
680+
"""
681+
deletePPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:default) =
682+
deletePPE!(dfg, sourceVariable.label, ppekey)
683+
684+
####
586685

587686
"""
588687
$(SIGNATURES)

src/services/DFGVariable.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function getSofttype(vnd::VariableNodeData)
307307
return vnd.softtype
308308
end
309309
function getSofttype(v::DFGVariable)
310-
return typeof(v).parameters[1] # Get the parameter of the DFGVariable
310+
return typeof(v).parameters[1]() # Get instantiated form of the parameter for the DFGVariable
311311
end
312312

313313
"""
@@ -347,14 +347,32 @@ $SIGNATURES
347347
348348
Get the small data for a variable.
349349
"""
350-
getSmallData(v::DFGVariable) = v.smallData
350+
getSmallData(v::DFGVariable)::Dict{String, String} = v.smallData
351351

352352
"""
353353
$SIGNATURES
354354
355355
Set the small data for a variable.
356356
"""
357-
setSmallData!(v::DFGVariable, smallData::String) = v.smallData = smallData
357+
function setSmallData!(v::DFGVariable, smallData::Dict{String, String})::Dict{String, String}
358+
v.smallData = smallData
359+
end
360+
361+
# WIP
362+
# """
363+
# $SIGNATURES
364+
#
365+
# Set the small data for a variable.
366+
# """
367+
# function addSmallData!(v::DFGVariable, smallData::Dict{String, String})::Dict{String, String}
368+
# v.smallData = smallData
369+
# end
370+
#
371+
# function updateSmallData!()
372+
# end
373+
#
374+
# function deleteSmallData!()
375+
# end
358376

359377
"""
360378
$SIGNATURES

test/interfaceTests.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ end
164164
@test getSolverDataDict(v1) == v1.solverDataDict
165165
@test getInternalId(v1) == v1._internalId
166166

167+
#TODO: Finish
167168
# Add new VND of type ContinuousScalar to :x0
168169
# Could also do VariableNodeData(ContinuousScalar())
169170
vnd = VariableNodeData{ContinuousScalar}()
@@ -177,11 +178,28 @@ end
177178
updateVariableSolverData!(dfg, :a, vnd, :parametric)
178179
# Update update it
179180
updateVariableSolverData!(dfg, :a, vnd, :parametric)
180-
# Bulk copy update x0 and x1
181-
updateVariableSolverData!(dfg, [v1, v2], :default)
181+
# Bulk copy update x0
182+
updateVariableSolverData!(dfg, [v1], :default)
182183
# Delete parametric from v1
183184
deleteVariableSolverData!(dfg, :a, :parametric)
184185

186+
#TODO: Finish
187+
# Add a new PPE of type MeanMaxPPE to :x0
188+
ppe = MeanMaxPPE(:default, [0.0], [0.0], [0.0])
189+
addPPE!(dfg, :x0, ppe)
190+
@show listPPE(dfg, :x0)
191+
# Get the data back - note that this is a reference to above.
192+
v = getPPE(dfg, :x0, :default)
193+
# Delete it
194+
deletePPE!(dfg, :x0, :default)
195+
# Update add it
196+
updatePPE!(dfg, :x0, ppe, :default)
197+
# Update update it
198+
updatePPE!(dfg, :x0, ppe, :default)
199+
# Bulk copy PPE's for x0 and x1
200+
updatePPE!(dfg, [x0], :default)
201+
# Delete it
202+
deletePPE!(dfg, :x0, :default)
185203

186204
#TODO I don't know what is supposed to happen to softtype
187205
@test getSofttype(v1) == st1

0 commit comments

Comments
 (0)