Skip to content

Commit d0dbc75

Browse files
committed
rm factor data
1 parent 66666f1 commit d0dbc75

9 files changed

Lines changed: 141 additions & 154 deletions

File tree

src/Deprecated.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,49 @@ function FactorCompute(
227227
)
228228
end
229229

230+
function getSolverData(f::FactorCompute)
231+
return error(
232+
"getSolverData(f::FactorCompute) is obsolete, use getState, getObservation, or getWorkmem instead",
233+
)
234+
end
235+
236+
function setSolverData!(f::FactorCompute, data::GenericFunctionNodeData)
237+
return error(
238+
"setSolverData!(f::FactorCompute, data::GenericFunctionNodeData) is obsolete, use setState!, or setWorkmem! instead",
239+
)
240+
end
241+
242+
@deprecate unpackFactor(dfg::AbstractDFG, factor::FactorDFG; skipVersionCheck::Bool = false) unpackFactor(
243+
factor;
244+
skipVersionCheck,
245+
)
246+
247+
@deprecate rebuildFactorMetadata!(args...; kwargs...) rebuildFactorWorkmem!(
248+
args...;
249+
kwargs...,
250+
)
251+
252+
export reconstFactorData
253+
function reconstFactorData end
254+
255+
function decodePackedType(
256+
dfg::AbstractDFG,
257+
varOrder::AbstractVector{Symbol},
258+
::Type{T},
259+
packeddata::GenericFunctionNodeData{PT},
260+
) where {T <: FactorOperationalMemory, PT}
261+
error("decodePackedType is obsolete")
262+
#
263+
# TODO, to solve IIF 1424
264+
# variables = map(lb->getVariable(dfg, lb), varOrder)
265+
266+
# Also look at parentmodule
267+
usrtyp = convertStructType(PT)
268+
fulltype = DFG.FunctionNodeData{T{usrtyp}}
269+
factordata = reconstFactorData(dfg, varOrder, fulltype, packeddata)
270+
return factordata
271+
end
272+
230273
## ================================================================================
231274
## Deprecated in v0.25
232275
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export mergeVariableData!, mergeGraphVariableData!
262262
# Serialization type conversion
263263
export convertPackedType, convertStructType
264264

265-
export reconstFactorData
265+
export pack, unpack, packDistribution, unpackDistribution
266266

267267
##------------------------------------------------------------------------------
268268
## Other utility functions
@@ -286,7 +286,7 @@ export findClosestTimestamp, findVariableNearTimestamp
286286

287287
# Serialization
288288
export packVariable, unpackVariable, packFactor, unpackFactor
289-
export rebuildFactorMetadata!
289+
export rebuildFactorWorkmem!
290290
export @defVariable
291291

292292
# File import and export

src/FileDFG/services/FileDFG.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ function loadDFG!(
9999
dst::AbstractString;
100100
overwriteDFGMetadata::Bool = true,
101101
)
102-
103102
#
104103
# loaddir gets deleted so needs to be unique
105104
loaddir = split(joinpath("/", "tmp", "caesar", "random", string(uuid1())), '-')[1]
@@ -176,9 +175,10 @@ function loadDFG!(
176175
end
177176

178177
@info "Loaded $(length(variables)) variables"#- $(map(v->v.label, variables))"
179-
@info "Inserting variables into graph..."
180-
# Adding variables
181-
map(v -> addVariable!(dfgLoadInto, v), variables)
178+
@showprogress 1 "Inserting variables into graph" map(
179+
v -> addVariable!(dfgLoadInto, v),
180+
variables,
181+
)
182182

183183
usePackedFactor =
184184
isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) == FactorDFG
@@ -190,21 +190,23 @@ function loadDFG!(
190190
if usePackedFactor
191191
return packedfact
192192
else
193-
return unpackFactor(dfgLoadInto, packedfact)
193+
return unpackFactor(packedfact)
194194
end
195195
end
196196

197197
@info "Loaded $(length(factors)) factors"# - $(map(f->f.label, factors))"
198-
@info "Inserting factors into graph..."
199198
# # Adding factors
200-
map(f -> addFactor!(dfgLoadInto, f), factors)
199+
@showprogress 1 "Inserting factors into graph" map(
200+
f -> addFactor!(dfgLoadInto, f),
201+
factors,
202+
)
201203

202204
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) != FactorDFG
203205
# Finally, rebuild the CCW's for the factors to completely reinflate them
204206
# NOTE CREATES A NEW FactorCompute IF CCW TYPE CHANGES
205-
@info "Rebuilding CCW's for the factors..."
206-
@showprogress 1 "build factor operational memory" for factor in factors
207-
rebuildFactorMetadata!(dfgLoadInto, factor)
207+
# @info "Rebuilding CCW's for the factors..."
208+
@showprogress 1 "Rebuilding factor working memory" for factor in factors
209+
rebuildFactorWorkmem!(dfgLoadInto, factor)
208210
end
209211
end
210212

src/entities/DFGFactor.jl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ Base.@kwdef struct FactorDFG <: AbstractDFGFactor
114114
nstime::String
115115
fnctype::String
116116
solvable::Int
117-
data::Union{String, Nothing} = nothing #TODO deprecated in v0.27 remove data completely, use state and observJSON
118117
metadata::String
119118
_version::String = string(_getDFGVersion())
120119
state::FactorState
@@ -169,7 +168,6 @@ function FactorDFG(
169168
nstime,
170169
fnctype,
171170
solvable,
172-
data,
173171
metadata,
174172
_version,
175173
state,
@@ -268,9 +266,6 @@ Base.@kwdef struct FactorCompute{FT <: AbstractFactor, N} <: AbstractDFGFactor
268266
timestamp::ZonedDateTime
269267
"""Nano second time"""
270268
nstime::Nanosecond
271-
"""Solver data.
272-
Accessors: [`getSolverData`](@ref), [`setSolverData!`](@ref)"""
273-
solverData::Base.RefValue{<:GenericFunctionNodeData}
274269
"""Solvable flag for the factor.
275270
Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)"""
276271
solvable::Base.RefValue{Int}
@@ -309,11 +304,8 @@ function FactorCompute(
309304
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}(),
310305
solverData = nothing,
311306
)
312-
if isnothing(solverData)
313-
refsolverData = Ref{GenericFunctionNodeData}() #TODO solverData deprecated in v0.27 WIP
314-
else
307+
if !isnothing(solverData)
315308
Base.depwarn("`FactorCompute` solverData is deprecated", :FactorCompute)
316-
refsolverData = Ref(solverData)
317309
end
318310

319311
if isnothing(_workmem)
@@ -329,7 +321,6 @@ function FactorCompute(
329321
Tuple(variableOrder),
330322
timestamp,
331323
nstime,
332-
refsolverData,
333324
Ref(solvable),
334325
smallData,
335326
observation,
@@ -380,7 +371,6 @@ function FactorCompute(
380371
timestamp,
381372
nstime,
382373
tags,
383-
solverData,
384374
smallData,
385375
solvable,
386376
)
@@ -390,16 +380,9 @@ function Base.getproperty(x::FactorCompute, f::Symbol)
390380
if f == :solvable
391381
getfield(x, f)[]
392382
elseif f == :solverData
393-
Base.depwarn(
394-
"`FactorCompute` field `$(f)` is deprecated, use `getObservation`, `getState` or `getWorkmem` instead.",
395-
:getproperty,
383+
error(
384+
"`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getState` or `getWorkmem` instead.",
396385
)
397-
# error("WIP removing direct access, breaking change in v0.27, use `state` or `Workmem` instead.")
398-
if isassigned(getfield(x, f))
399-
getfield(x, f)[]
400-
else
401-
nothing
402-
end
403386
elseif f == :_variableOrderSymbols
404387
[getfield(x, f)...]
405388
else
@@ -408,8 +391,12 @@ function Base.getproperty(x::FactorCompute, f::Symbol)
408391
end
409392

410393
function Base.setproperty!(x::FactorCompute, f::Symbol, val)
411-
if f == :solvable || f == :solverData
394+
if f == :solvable
412395
getfield(x, f)[] = val
396+
elseif f == :solverData
397+
error(
398+
"`solverData` is obsolete in `FactorCompute`. Use `Observation`, `State` or `Workmem` instead.",
399+
)
413400
else
414401
setfield!(x, f, val)
415402
end

src/services/AbstractDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ end
116116
117117
Method must be overloaded by the user for Serialization to work.
118118
"""
119-
function rebuildFactorMetadata!(
119+
function rebuildFactorWorkmem!(
120120
dfg::AbstractDFG{<:AbstractParams},
121121
factor::AbstractDFGFactor,
122122
neighbors = [],
123123
)
124-
return error("rebuildFactorMetadata! is not implemented for $(typeof(dfg))")
124+
return error("rebuildFactorWorkmem! is not implemented for $(typeof(dfg))")
125125
end
126126

127127
"""

src/services/CompareUtils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function compareFactor(
359359
show = show,
360360
)
361361
@debug "compareFactor 3/5" TP
362-
362+
363363
#FIXME is measurement stil in use and should it be checked, skipping for now
364364
if false # !(:measurement in skip)
365365
TP =
@@ -388,7 +388,7 @@ function compareFactor(
388388
@debug "compareFactor 5/5" TP
389389
#FIXME is varidx stil in use and should it be checked, skipping for now
390390
if false #!(:varidx in skip) && hasfield(typeof(getSolverData(A).fnc), :varidx) &&
391-
getSolverData(A).fnc.varidx isa Base.RefValue
391+
getSolverData(A).fnc.varidx isa Base.RefValue
392392
TP =
393393
TP & (
394394
skipcompute || compareAll(

src/services/DFGFactor.jl

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ function getObservation(f::FactorDFG)
5656
#FIXME completely refactor to not need getTypeFromSerializationModule and just use StructTypes
5757
packtype = DFG.getTypeFromSerializationModule("Packed" * f.fnctype)
5858
return packtype(; JSON3.read(f.observJSON)...)
59+
# return packtype(JSON3.read(f.observJSON))
5960
end
6061

61-
getWorkmem(f::FactorCompute) = f.workmem[]
62+
function getWorkmem(f::FactorCompute)
63+
if isassigned(f.workmem)
64+
return f.workmem[]
65+
else
66+
return nothing
67+
end
68+
end
6269
setWorkmem!(f::FactorCompute, workmem::FactorOperationalMemory) = f.workmem[] = workmem
6370

6471
"""
@@ -84,7 +91,6 @@ end
8491
## Default Factors Function Macro
8592
##==============================================================================
8693
export PackedSamplableBelief
87-
# export pack, unpack, packDistribution, unpackDistribution
8894

8995
function pack end
9096
function unpack end
@@ -94,38 +100,48 @@ function unpackDistribution end
94100
abstract type PackedSamplableBelief end
95101
StructTypes.StructType(::Type{<:PackedSamplableBelief}) = StructTypes.UnorderedStruct()
96102

103+
#TODO remove, rather use StructTypes.jl properly
104+
function Base.convert(::Type{<:PackedSamplableBelief}, nt::Union{NamedTuple, JSON3.Object})
105+
distrType = getTypeFromSerializationModule(nt._type)
106+
return distrType(; nt...)
107+
end
108+
97109
"""
98-
@defFactorType StructName factortype<:AbstractFactor manifolds<:ManifoldsBase.AbstractManifold
110+
@defFactorType StructName factortype<:AbstractFactor manifolds<:AbstractManifold
99111
100-
A macro to create a new factor function with name `StructName` and manifolds. Note that
101-
the `manifolds` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
112+
A macro to create a new factor function with name `StructName` and manifold. Note that
113+
the `manifold` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
102114
See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).
103115
104116
Example:
105117
```
106-
DFG.@defFactorType Pose2Pos2 AbstractManifoldMinimize SpecialEuclidean(2)
118+
DFG.@defFactorType Pose2Pose2 AbstractManifoldMinimize SpecialEuclidean(2)
107119
```
108120
"""
109121
macro defFactorType(structname, factortype, manifold)
110122
packedstructname = Symbol("Packed", structname)
111123
return esc(
112124
quote
125+
# user manifold must be a <:Manifold
126+
@assert ($manifold isa AbstractManifold) "@defFactorType manifold (" *
127+
string($manifold) *
128+
") is not an `AbstractManifold`"
129+
130+
@assert ($factortype <: AbstractFactor) "@defFactorType factortype (" *
131+
string($factortype) *
132+
") is not an `AbstractFactor`"
133+
113134
Base.@__doc__ struct $structname{T} <: $factortype
114135
Z::T
115136
end
116137

117-
Base.@__doc__ struct $packedstructname{T <: PackedSamplableBelief} <:
118-
AbstractPackedFactor
119-
Z::T
138+
#TODO should this be $packedstructname{T <: PackedSamplableBelief}
139+
Base.@__doc__ struct $packedstructname <: AbstractPackedFactor
140+
Z::PackedSamplableBelief
120141
end
121142

122-
# user manifold must be a <:Manifold
123-
@assert ($manifold isa AbstractManifold) "@defFactorType of " *
124-
string($structname) *
125-
" requires that the " *
126-
string($manifold) *
127-
" be a subtype of `ManifoldsBase.AbstractManifold`"
128-
143+
# $structname(; Z) = $structname(Z)
144+
$packedstructname(; Z) = $packedstructname(Z)
129145
DFG.getManifold(::Type{$structname}) = $manifold
130146
DFG.pack(d::$structname) = $packedstructname(DFG.packDistribution(d.Z))
131147
DFG.unpack(d::$packedstructname) = $structname(DFG.unpackDistribution(d.Z))
@@ -223,26 +239,6 @@ getVariableOrder(fct::FactorCompute) = fct._variableOrderSymbols::Vector{Symbol}
223239
getVariableOrder(fct::FactorDFG) = fct._variableOrderSymbols::Vector{Symbol}
224240
getVariableOrder(dfg::AbstractDFG, fct::Symbol) = getVariableOrder(getFactor(dfg, fct))
225241

226-
##------------------------------------------------------------------------------
227-
## solverData
228-
##------------------------------------------------------------------------------
229-
230-
"""
231-
$SIGNATURES
232-
233-
Retrieve solver data structure stored in a factor.
234-
"""
235-
function getSolverData(f::FactorCompute)
236-
Base.depwarn("getSolverData(f::FactorCompute) is deprecated", :getSolverData)
237-
if isassigned(getfield(f, :solverData))
238-
return getfield(f, :solverData)[]
239-
else
240-
return nothing
241-
end
242-
end
243-
244-
setSolverData!(f::FactorCompute, data::GenericFunctionNodeData) = f.solverData = data
245-
246242
##------------------------------------------------------------------------------
247243
## utility
248244
##------------------------------------------------------------------------------

0 commit comments

Comments
 (0)