Skip to content

Commit 94835a0

Browse files
authored
Deprecate Variable[NodeData/SolverData] to VariableState (#1139)
1 parent d8a5695 commit 94835a0

17 files changed

+201
-169
lines changed

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
1212
- This is used internally be the solver and should not affect the average user of DFG.
1313
- Rename FactorOperationalMemory -> FactorSolverCache
1414
- Rename AbstractFactor -> AbstractFactorObservation (keeping both around)
15+
- Deprecate VariableNodeData -> VariableState
16+
- Deprecate getVariableSolverData -> getVariableState
17+
- Deprecate addVariableSolverData! -> addVariableState!
18+
- Deprecate deleteVariableSolverData! -> deleteVariableState!
19+
- Deprecate listVariableSolverData -> listVariableStates
20+
- Deprecate getVariableSolverDataAll -> getVariableStates
21+
- Deprecate getSolverData -> getVariableState/getFactorState
1522

1623
# v0.26
1724
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.

docs/src/GraphData.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following is a guideline to using these parameters.
1515

1616
**NOTE**: Adds in general throw an error if the element already exists. Update will update the element if it exists, otherwise it will add it.
1717

18-
**NOTE**: In general these functions will return an error if the respective element is not found. This is to avoid returning, say, nothing, which will be horribly confusing if you tried `getVariableSolverData(dfg, :a, :b)` and it returned nothing - which was missing, :a or :b, or was there a communication issue? We recommend coding defensively and trapping errors in critical portions of your user code.
18+
**NOTE**: In general these functions will return an error if the respective element is not found. This is to avoid returning, say, nothing, which will be horribly confusing if you tried `getVariableState(dfg, :a, :b)` and it returned nothing - which was missing, :a or :b, or was there a communication issue? We recommend coding defensively and trapping errors in critical portions of your user code.
1919

2020
**NOTE**: All data is passed by reference, so if you update the returned structure it will update in the graph. The database driver is an exception, and once the variable or factor is updated you need to call update* to persist the changes to the graph.
2121

@@ -125,26 +125,26 @@ Solver data is used by IncrementalInference/RoME/Caesar solver to produce the ab
125125
Related functions:
126126

127127

128-
- [`listVariableSolverData`](@ref)
129-
- [`getVariableSolverData`](@ref)
130-
- [`addVariableSolverData!`](@ref)
128+
- [`listVariableStates`](@ref)
129+
- [`getVariableState`](@ref)
130+
- [`addVariableState!`](@ref)
131+
- [`mergeVariableState!`](@ref)
132+
- [`deleteVariableState!`](@ref)
131133
- [`mergeVariableState!`](@ref)
132-
- [`deleteVariableSolverData!`](@ref)
133-
- [`mergeVariableSolverData!`](@ref)
134134

135135

136136
Example of solver data operations:
137137

138138
```julia
139139
# Add new VND of type ContinuousScalar to :x0
140-
# Could also do VariableNodeData(ContinuousScalar())
141-
vnd = VariableNodeData{ContinuousScalar}()
142-
addVariableSolverData!(dfg, :x0, vnd, :parametric)
143-
@show listVariableSolverData(dfg, :x0)
140+
# Could also do VariableState(ContinuousScalar())
141+
vnd = VariableState{ContinuousScalar}()
142+
addVariableState!(dfg, :x0, vnd, :parametric)
143+
@show listVariableStates(dfg, :x0)
144144
# Get the data back - note that this is a reference to above.
145-
vndBack = getVariableSolverData(dfg, :x0, :parametric)
145+
vndBack = getVariableState(dfg, :x0, :parametric)
146146
# Delete it
147-
deleteVariableSolverData!(dfg, :x0, :parametric)
147+
deleteVariableState!(dfg, :x0, :parametric)
148148
```
149149

150150
#### Small Data

src/Deprecated.jl

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const AbstractPackedFactor = AbstractPackedFactorObservation
1010
export FactorOperationalMemory
1111
const FactorOperationalMemory = FactorSolverCache
1212

13+
export VariableNodeData
14+
const VariableNodeData = VariableState
15+
1316
@deprecate getNeighborhood(args...; kwargs...) listNeighborhood(args...; kwargs...)
1417
@deprecate addBlob!(store::AbstractBlobstore, blobId::UUID, data, ::String) addBlob!(
1518
store,
@@ -70,13 +73,30 @@ const FactorOperationalMemory = FactorSolverCache
7073
)
7174
@deprecate mergeBlobEntries!(args...; kwargs...) mergeBlobentries!(args...; kwargs...)
7275

76+
@deprecate getVariableSolverData(args...; kwargs...) getVariableState(args...; kwargs...)
77+
@deprecate addVariableSolverData!(args...; kwargs...) addVariableState!(args...; kwargs...)
78+
@deprecate deleteVariableSolverData!(args...; kwargs...) deleteVariableState!(
79+
args...;
80+
kwargs...,
81+
)
82+
@deprecate listVariableSolverData(args...; kwargs...) listVariableStates(args...; kwargs...)
83+
@deprecate getVariableSolverDataAll(args...; kwargs...) getVariableStates(
84+
args...;
85+
kwargs...,
86+
)
87+
88+
@deprecate getSolverData(v::VariableCompute, solveKey::Symbol = :default) getVariableState(
89+
v,
90+
solveKey,
91+
)
92+
7393
export updateVariableSolverData!
7494

7595
#TODO possibly completely deprecated or not exported until update verb is standardized
7696
function updateVariableSolverData!(
7797
dfg::AbstractDFG,
7898
variablekey::Symbol,
79-
vnd::VariableNodeData,
99+
vnd::VariableState,
80100
useCopy::Bool = false,
81101
fields::Vector{Symbol} = Symbol[];
82102
warn_if_absent::Bool = true,
@@ -89,14 +109,14 @@ function updateVariableSolverData!(
89109
var = getVariable(dfg, variablekey)
90110
warn_if_absent &&
91111
!haskey(var.solverDataDict, vnd.solveKey) &&
92-
@warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding"
112+
@warn "VariableState '$(vnd.solveKey)' does not exist, adding"
93113

94114
# for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update.
95115
usevnd = vnd # useCopy ? deepcopy(vnd) : vnd
96116
# should just one, or many pointers be updated?
97117
useExisting =
98118
haskey(var.solverDataDict, vnd.solveKey) &&
99-
isa(var.solverDataDict[vnd.solveKey], VariableNodeData) &&
119+
isa(var.solverDataDict[vnd.solveKey], VariableState) &&
100120
length(fields) != 0
101121
# @error useExisting vnd.solveKey
102122
if useExisting
@@ -123,17 +143,17 @@ end
123143
function updateVariableSolverData!(
124144
dfg::AbstractDFG,
125145
variablekey::Symbol,
126-
vnd::VariableNodeData,
146+
vnd::VariableState,
127147
solveKey::Symbol,
128148
useCopy::Bool = false,
129149
fields::Vector{Symbol} = Symbol[];
130150
warn_if_absent::Bool = true,
131151
)
132152
# TODO not very clean
133153
if vnd.solveKey != solveKey
134-
@warn(
135-
"updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed",
136-
maxlog = 1
154+
Base.depwarn(
155+
"updateVariableSolverData with solveKey is deprecated use copytoVariableState! instead.",
156+
:updateVariableSolverData!,
137157
)
138158
usevnd = useCopy ? deepcopy(vnd) : vnd
139159
usevnd.solveKey = solveKey
@@ -170,7 +190,7 @@ function updateVariableSolverData!(
170190
# toshow = listSolveKeys(sourceVariable) |> collect
171191
# @info "update DFGVar solveKey" solveKey vnd.solveKey
172192
# @show toshow
173-
@assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey"
193+
@assert solveKey == vnd.solveKey "VariableState's solveKey=:$(vnd.solveKey) does not match requested :$solveKey"
174194
return updateVariableSolverData!(
175195
dfg,
176196
sourceVariable.label,
@@ -258,7 +278,7 @@ export getSolverData, setSolverData!
258278

259279
function getSolverData(f::FactorCompute)
260280
return error(
261-
"getSolverData(f::FactorCompute) is obsolete, use getState, getObservation, or getCache instead",
281+
"getSolverData(f::FactorCompute) is obsolete, use getFactorState, getObservation, or getCache instead",
262282
)
263283
end
264284

src/DistributedFactorGraphs.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export getSolverDataDict, setSolverData!
167167
export getVariableType, getVariableTypeName
168168

169169
export getObservation
170-
export getState, getFactorState
170+
export getFactorState
171171

172172
export getVariableType
173173

@@ -186,11 +186,12 @@ export getMetadata,
186186
emptyMetadata!
187187

188188
# CRUD & SET
189-
export getVariableSolverData,
190-
addVariableSolverData!,
189+
export getVariableState,
190+
getVariableStates,
191+
addVariableState!,
191192
mergeVariableState!,
192-
deleteVariableSolverData!,
193-
listVariableSolverData,
193+
deleteVariableState!,
194+
listVariableStates,
194195
mergeVariableSolverData!,
195196
cloneSolveKey!
196197

@@ -211,9 +212,9 @@ export getPPE,
211212

212213
# Variable Node Data
213214
##------------------------------------------------------------------------------
214-
export VariableNodeData, PackedVariableNodeData
215+
export VariableState, PackedVariableState
215216

216-
export packVariableNodeData, unpackVariableNodeData
217+
export packVariableState, unpackVariableState
217218

218219
export getSolvedCount,
219220
isSolved, setSolvedCount!, isInitialized, isMarginalized, setMarginalized!

src/entities/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function Base.getproperty(x::FactorCompute, f::Symbol)
283283
elseif f == :solverData
284284
# TODO remove, deprecated in v0.27
285285
error(
286-
"`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getState` or `getCache` instead.",
286+
"`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getFactorState` or `getCache` instead.",
287287
)
288288
elseif f == :_variableOrderSymbols
289289
[getfield(x, f)...]

src/entities/DFGVariable.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
abstract type InferenceVariable end
66

77
##==============================================================================
8-
## VariableNodeData
8+
## VariableState
99
##==============================================================================
1010

1111
"""
@@ -19,7 +19,7 @@ N: Manifold dimension.
1919
Fields:
2020
$(TYPEDFIELDS)
2121
"""
22-
Base.@kwdef mutable struct VariableNodeData{T <: InferenceVariable, P, N}
22+
Base.@kwdef mutable struct VariableState{T <: InferenceVariable, P, N}
2323
"DEPRECATED remove in DFG v0.22"
2424
variableType::T = T() #tricky deprecation, also change covar to using N and not variableType
2525
"""
@@ -72,7 +72,7 @@ Base.@kwdef mutable struct VariableNodeData{T <: InferenceVariable, P, N}
7272
"""
7373
solvedCount::Int = 0
7474
"""
75-
solveKey identifier associated with this VariableNodeData object.
75+
solveKey identifier associated with this VariableState object.
7676
"""
7777
solveKey::Symbol = :default
7878
"""
@@ -84,26 +84,26 @@ end
8484

8585
##------------------------------------------------------------------------------
8686
## Constructors
87-
function VariableNodeData{T}(; kwargs...) where {T <: InferenceVariable}
88-
return VariableNodeData{T, getPointType(T), getDimension(T)}(; kwargs...)
87+
function VariableState{T}(; kwargs...) where {T <: InferenceVariable}
88+
return VariableState{T, getPointType(T), getDimension(T)}(; kwargs...)
8989
end
90-
function VariableNodeData(variableType::InferenceVariable; kwargs...)
91-
return VariableNodeData{typeof(variableType)}(; kwargs...)
90+
function VariableState(variableType::InferenceVariable; kwargs...)
91+
return VariableState{typeof(variableType)}(; kwargs...)
9292
end
9393

9494
##==============================================================================
95-
## PackedVariableNodeData.jl
95+
## PackedVariableState.jl
9696
##==============================================================================
9797

9898
"""
9999
$(TYPEDEF)
100-
Packed VariableNodeData structure for serializing DFGVariables.
100+
Packed VariableState structure for serializing DFGVariables.
101101
102102
---
103103
Fields:
104104
$(TYPEDFIELDS)
105105
"""
106-
Base.@kwdef mutable struct PackedVariableNodeData
106+
Base.@kwdef mutable struct PackedVariableState
107107
id::Union{UUID, Nothing} # If it's blank it doesn't exist in the DB.
108108
vecval::Vector{Float64}
109109
dimval::Int
@@ -130,9 +130,9 @@ end
130130
# createdTimestamp::DateTime#!
131131
# lastUpdatedTimestamp::DateTime#!
132132

133-
StructTypes.StructType(::Type{PackedVariableNodeData}) = StructTypes.UnorderedStruct()
134-
StructTypes.idproperty(::Type{PackedVariableNodeData}) = :id
135-
StructTypes.omitempties(::Type{PackedVariableNodeData}) = (:id,)
133+
StructTypes.StructType(::Type{PackedVariableState}) = StructTypes.UnorderedStruct()
134+
StructTypes.idproperty(::Type{PackedVariableState}) = :id
135+
StructTypes.omitempties(::Type{PackedVariableState}) = (:id,)
136136

137137
##==============================================================================
138138
## PointParametricEst
@@ -228,7 +228,7 @@ Base.@kwdef struct VariableDFG <: AbstractDFGVariable
228228
_version::String = string(_getDFGVersion())
229229
metadata::String = "e30="
230230
solvable::Int = 1
231-
solverData::Vector{PackedVariableNodeData} = PackedVariableNodeData[]
231+
solverData::Vector{PackedVariableState} = PackedVariableState[]
232232
end
233233
# maybe add to variable
234234
# createdTimestamp::DateTime
@@ -304,9 +304,9 @@ Base.@kwdef struct VariableCompute{T <: InferenceVariable, P, N} <: AbstractDFGV
304304
ppeDict::Dict{Symbol, AbstractPointParametricEst} =
305305
Dict{Symbol, AbstractPointParametricEst}()
306306
"""Dictionary of solver data. May be a subset of all solutions if a solver label was specified in the get call.
307-
Accessors: [`addVariableSolverData!`](@ref), [`mergeVariableState!`](@ref), and [`deleteVariableSolverData!`](@ref)"""
308-
solverDataDict::Dict{Symbol, VariableNodeData{T, P, N}} =
309-
Dict{Symbol, VariableNodeData{T, P, N}}()
307+
Accessors: [`addVariableState!`](@ref), [`mergeVariableState!`](@ref), and [`deleteVariableState!`](@ref)"""
308+
solverDataDict::Dict{Symbol, VariableState{T, P, N}} =
309+
Dict{Symbol, VariableState{T, P, N}}()
310310
"""Dictionary of small data associated with this variable.
311311
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
312312
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
@@ -343,7 +343,7 @@ function VariableCompute(label::Symbol, variableType::InferenceVariable; kwargs.
343343
return VariableCompute(label, typeof(variableType); kwargs...)
344344
end
345345

346-
function VariableCompute(label::Symbol, solverData::VariableNodeData; kwargs...)
346+
function VariableCompute(label::Symbol, solverData::VariableState; kwargs...)
347347
return VariableCompute(;
348348
label,
349349
solverDataDict = Dict(:default => solverData),

src/services/CommonAccessors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function getSolveInProgress(
165165
end
166166
end
167167
# Factor
168-
return getState(var).solveInProgress
168+
return getFactorState(var).solveInProgress
169169
end
170170

171171
#TODO missing set solveInProgress and graph level accessor

src/services/CompareUtils.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ implement compare if needed.
1919
# Generate compares automatically for all in this union
2020
const GeneratedCompareUnion = Union{
2121
MeanMaxPPE,
22-
VariableNodeData,
23-
PackedVariableNodeData,
22+
VariableState,
23+
PackedVariableState,
2424
VariableCompute,
2525
VariableDFG,
2626
VariableSummary,
@@ -193,8 +193,8 @@ function compareAll(
193193
return true
194194
end
195195

196-
#Compare VariableNodeData
197-
function compare(a::VariableNodeData, b::VariableNodeData)
196+
#Compare VariableState
197+
function compare(a::VariableState, b::VariableState)
198198
a.val != b.val && @debug("val is not equal") == nothing && return false
199199
a.bw != b.bw && @debug("bw is not equal") == nothing && return false
200200
a.BayesNetOutVertIDs != b.BayesNetOutVertIDs &&
@@ -253,8 +253,8 @@ function compareVariable(
253253
union!(skiplist, skip)
254254
TP = TP && compareAll(A.solverDataDict, B.solverDataDict; skip = skiplist, show = show)
255255

256-
Ad = getSolverData(A)
257-
Bd = getSolverData(B)
256+
Ad = getVariableState(A)
257+
Bd = getVariableState(B)
258258

259259
# TP = TP && compareAll(A.attributes, B.attributes, skip=[:variableType;], show=show)
260260
varskiplist = union(varskiplist, [:variableType])
@@ -298,8 +298,8 @@ function compareFactor(
298298
@debug "compareFactor 1/5" TP
299299
TP =
300300
TP & compareAll(
301-
getState(A),
302-
getState(B);
301+
getFactorState(A),
302+
getFactorState(B);
303303
skip = union([:fnc; :_gradients], skip),
304304
show = show,
305305
)

0 commit comments

Comments
 (0)