Skip to content

Commit 59d25bc

Browse files
committed
deprecate GenericFunctionNodeData and related
1 parent b7b90f9 commit 59d25bc

12 files changed

Lines changed: 139 additions & 276 deletions

File tree

src/Deprecated.jl

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## ================================================================================
22
## Deprecated in v0.27
33
##=================================================================================
4-
export AbstractFactor
4+
export AbstractFactor
55
const AbstractFactor = AbstractFactorObservation
66

77
export AbstractPackedFactor
@@ -202,6 +202,37 @@ function updateVariableSolverData!(
202202
end
203203
end
204204

205+
## factor refactor deprecations
206+
"""
207+
$(TYPEDEF)
208+
209+
Notes
210+
- S::Symbol
211+
212+
Designing (WIP)
213+
- T <: Union{FactorSolverCache, AbstractPackedFactorObservation}
214+
- in IIF.CCW{T <: DFG.AbstractFactorObservation}
215+
- in DFG.AbstractRelativeMinimize <: AbstractFactorObservation
216+
- in Main.SomeFactor <: AbstractRelativeMinimize
217+
"""
218+
Base.@kwdef mutable struct GenericFunctionNodeData{
219+
T <: Union{
220+
<:AbstractPackedFactorObservation,
221+
<:AbstractFactorObservation,
222+
<:FactorSolverCache,
223+
},
224+
}
225+
eliminated::Bool = false
226+
potentialused::Bool = false
227+
edgeIDs::Vector{Int} = Int[]
228+
fnc::T
229+
multihypo::Vector{Float64} = Float64[] # TODO re-evaluate after refactoring w #477
230+
certainhypo::Vector{Int} = Int[]
231+
nullhypo::Float64 = 0.0
232+
solveInProgress::Int = 0
233+
inflation::Float64 = 0.0
234+
end
235+
205236
function FactorCompute(
206237
label::Symbol,
207238
timestamp::Union{DateTime, ZonedDateTime},
@@ -297,6 +328,80 @@ function _packSolverData(f::FactorCompute, fnctype::AbstractFactorObservation)
297328
error(msg)
298329
end
299330
end
331+
332+
export GenericFunctionNodeData, PackedFunctionNodeData, FunctionNodeData
333+
334+
const PackedFunctionNodeData{T} =
335+
GenericFunctionNodeData{T} where {T <: AbstractPackedFactorObservation}
336+
function PackedFunctionNodeData(args...; kw...)
337+
error("PackedFunctionNodeData is obsolete")
338+
return PackedFunctionNodeData{typeof(args[4])}(args...; kw...)
339+
end
340+
341+
const FunctionNodeData{T} = GenericFunctionNodeData{
342+
T,
343+
} where {T <: Union{<:AbstractFactorObservation, <:FactorSolverCache}}
344+
FunctionNodeData(args...; kw...) = FunctionNodeData{typeof(args[4])}(args...; kw...)
345+
346+
# this is the GenericFunctionNodeData for packed types
347+
#TODO deprecate FactorData in favor of FactorState (with no more distinction between packed and compute)
348+
const FactorData = PackedFunctionNodeData{AbstractPackedFactorObservation}
349+
350+
function FactorCompute(
351+
label::Symbol,
352+
variableOrder::Union{Vector{Symbol}, Tuple},
353+
solverData::GenericFunctionNodeData;
354+
tags::Set{Symbol} = Set{Symbol}(),
355+
timestamp::Union{DateTime, ZonedDateTime} = now(localzone()),
356+
solvable::Int = 1,
357+
nstime::Nanosecond = Nanosecond(0),
358+
id::Union{UUID, Nothing} = nothing,
359+
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}(),
360+
)
361+
Base.depwarn(
362+
"`FactorCompute` constructor with `GenericFunctionNodeData` is deprecated. observation, state, and solvercache should be provided explicitly.",
363+
:FactorCompute,
364+
)
365+
observation = getFactorType(solverData)
366+
state = FactorState(
367+
solverData.eliminated,
368+
solverData.potentialused,
369+
solverData.multihypo,
370+
solverData.certainhypo,
371+
solverData.nullhypo,
372+
solverData.solveInProgress,
373+
solverData.inflation,
374+
)
375+
376+
if solverData.fnc isa FactorSolverCache
377+
solvercache = solverData.fnc
378+
else
379+
solvercache = nothing
380+
end
381+
382+
return FactorCompute(
383+
label,
384+
Tuple(variableOrder),
385+
observation,
386+
state,
387+
solvercache;
388+
id,
389+
timestamp,
390+
nstime,
391+
tags,
392+
smallData,
393+
solvable,
394+
)
395+
end
396+
397+
# Deprecated check usefull? # packedFnc = fncStringToData(factor.fnctype, factor.data)
398+
# Deprecated check usefull? # decodeType = getFactorOperationalMemoryType(dfg)
399+
# Deprecated check usefull? # fullFactorData = decodePackedType(dfg, factor._variableOrderSymbols, decodeType, packedFnc)
400+
function fncStringToData(args...; kwargs...)
401+
@warn "fncStringToData is obsolete, called with" args kwargs
402+
return error("fncStringToData is obsolete.")
403+
end
404+
300405
## ================================================================================
301406
## Deprecated in v0.25
302407
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ export @format_str
248248
# Factors
249249
##------------------------------------------------------------------------------
250250
# Factor Data
251-
export GenericFunctionNodeData, PackedFunctionNodeData, FunctionNodeData
252251
export AbstractFactorObservation, AbstractPackedFactorObservation
253252
export AbstractPrior, AbstractRelative, AbstractRelativeMinimize, AbstractManifoldMinimize
254253
export FactorSolverCache
@@ -303,7 +302,6 @@ export compare,
303302
compareField,
304303
compareFields,
305304
compareAll,
306-
compareAllSpecial,
307305
compareVariable,
308306
compareFactor,
309307
compareAllVariables,

src/FileDFG/services/FileDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function loadDFG!(
168168
jstr = read("$varFolder/$varFile", String)
169169
packedvar = JSON3.read(jstr, VariableDFG)
170170
v = usePackedVariable ? packedvar : unpackVariable(packedvar)
171-
addVariable!(dfgLoadInto, v)
171+
return addVariable!(dfgLoadInto, v)
172172
end
173173

174174
@info "Loaded $(length(variables)) variables"#- $(map(v->v.label, variables))"
@@ -181,7 +181,7 @@ function loadDFG!(
181181
jstr = read("$factorFolder/$factorFile", String)
182182
packedfact = JSON3.read(jstr, FactorDFG)
183183
f = usePackedFactor ? packedfact : unpackFactor(packedfact)
184-
addFactor!(dfgLoadInto, f)
184+
return addFactor!(dfgLoadInto, f)
185185
end
186186

187187
@info "Loaded $(length(factors)) factors"# - $(map(f->f.label, factors))"

src/entities/DFGFactor.jl

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,6 @@ abstract type FactorSolverCache end
1818
# we can add to IIF or have IIF.CommonConvWrapper <: FactorSolverCache directly
1919
# abstract type ConvolutionObject <: FactorSolverCache end
2020

21-
##==============================================================================
22-
## GenericFunctionNodeData
23-
##==============================================================================
24-
25-
"""
26-
$(TYPEDEF)
27-
28-
Notes
29-
- S::Symbol
30-
31-
Designing (WIP)
32-
- T <: Union{FactorSolverCache, AbstractPackedFactorObservation}
33-
- in IIF.CCW{T <: DFG.AbstractFactorObservation}
34-
- in DFG.AbstractRelativeMinimize <: AbstractFactorObservation
35-
- in Main.SomeFactor <: AbstractRelativeMinimize
36-
"""
37-
Base.@kwdef mutable struct GenericFunctionNodeData{
38-
T <: Union{<:AbstractPackedFactorObservation, <:AbstractFactorObservation, <:FactorSolverCache},
39-
}
40-
eliminated::Bool = false
41-
potentialused::Bool = false
42-
edgeIDs::Vector{Int} = Int[]
43-
fnc::T
44-
multihypo::Vector{Float64} = Float64[] # TODO re-evaluate after refactoring w #477
45-
certainhypo::Vector{Int} = Int[]
46-
nullhypo::Float64 = 0.0
47-
solveInProgress::Int = 0
48-
inflation::Float64 = 0.0
49-
end
50-
5121
#TODO is this mutable
5222
@kwdef mutable struct FactorState
5323
eliminated::Bool = false
@@ -66,25 +36,6 @@ end
6636

6737
## Constructors
6838

69-
##------------------------------------------------------------------------------
70-
## PackedFunctionNodeData and FunctionNodeData
71-
72-
const PackedFunctionNodeData{T} =
73-
GenericFunctionNodeData{T} where {T <: AbstractPackedFactorObservation}
74-
function PackedFunctionNodeData(args...; kw...)
75-
return PackedFunctionNodeData{typeof(args[4])}(args...; kw...)
76-
end
77-
78-
const FunctionNodeData{T} = GenericFunctionNodeData{
79-
T,
80-
} where {T <: Union{<:AbstractFactorObservation, <:FactorSolverCache}}
81-
FunctionNodeData(args...; kw...) = FunctionNodeData{typeof(args[4])}(args...; kw...)
82-
83-
# PackedFunctionNodeData(x2, x3, x4, x6::T, multihypo::Vector{Float64}=[], certainhypo::Vector{Int}=Int[], x9::Int=0) where T <: AbstractPackedFactorObservation =
84-
# GenericFunctionNodeData{T}(x2, x3, x4, x6, multihypo, certainhypo, x9)
85-
# FunctionNodeData(x2, x3, x4, x6::T, multihypo::Vector{Float64}=[], certainhypo::Vector{Int}=Int[], x9::Int=0) where T <: Union{AbstractFactorObservation, FactorSolverCache} =
86-
# GenericFunctionNodeData{T}(x2, x3, x4, x6, multihypo, certainhypo, x9)
87-
8839
##==============================================================================
8940
## Factors
9041
##==============================================================================
@@ -114,7 +65,7 @@ Base.@kwdef struct FactorDFG <: AbstractDFGFactor
11465
nstime::String
11566
fnctype::String
11667
solvable::Int
117-
data::Union{Nothing, String} #TODO deprecate data completely, left as a bridge to old serialization structure
68+
data::Union{Nothing, String} = nothing #TODO deprecate data completely, left as a bridge to old serialization structure
11869
metadata::String
11970
_version::String = string(_getDFGVersion())
12071
state::FactorState
@@ -129,7 +80,7 @@ end
12980

13081
StructTypes.StructType(::Type{FactorDFG}) = StructTypes.UnorderedStruct()
13182
StructTypes.idproperty(::Type{FactorDFG}) = :id
132-
StructTypes.omitempties(::Type{FactorDFG}) = (:id,)
83+
StructTypes.omitempties(::Type{FactorDFG}) = (:id, :data)
13384

13485
#TODO deprecate, added in v0.27 as a bridge to new serialization structure
13586
function FactorDFG(
@@ -189,10 +140,6 @@ abstract type InferenceType <: AbstractPackedFactorObservation end
189140

190141
#TODO deprecate InferenceType in favor of AbstractPackedFactorObservation v0.26
191142

192-
# this is the GenericFunctionNodeData for packed types
193-
#TODO deprecate FactorData in favor of FactorState (with no more distinction between packed and compute)
194-
const FactorData = PackedFunctionNodeData{AbstractPackedFactorObservation}
195-
196143
# Packed Factor constructor
197144
function assembleFactorName(xisyms::Union{Vector{String}, Vector{Symbol}})
198145
return Symbol(xisyms..., "_f", randstring(4))
@@ -331,57 +278,11 @@ function FactorCompute(
331278
)
332279
end
333280

334-
function FactorCompute(
335-
label::Symbol,
336-
variableOrder::Union{Vector{Symbol}, Tuple},
337-
solverData::GenericFunctionNodeData;
338-
tags::Set{Symbol} = Set{Symbol}(),
339-
timestamp::Union{DateTime, ZonedDateTime} = now(localzone()),
340-
solvable::Int = 1,
341-
nstime::Nanosecond = Nanosecond(0),
342-
id::Union{UUID, Nothing} = nothing,
343-
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}(),
344-
)
345-
Base.depwarn(
346-
"`FactorCompute` constructor with `GenericFunctionNodeData` is deprecated. observation, state, and solvercache should be provided explicitly.",
347-
:FactorCompute,
348-
)
349-
observation = getFactorType(solverData)
350-
state = FactorState(
351-
solverData.eliminated,
352-
solverData.potentialused,
353-
solverData.multihypo,
354-
solverData.certainhypo,
355-
solverData.nullhypo,
356-
solverData.solveInProgress,
357-
solverData.inflation,
358-
)
359-
360-
if solverData.fnc isa FactorSolverCache
361-
solvercache = solverData.fnc
362-
else
363-
solvercache = nothing
364-
end
365-
366-
return FactorCompute(
367-
label,
368-
Tuple(variableOrder),
369-
observation,
370-
state,
371-
solvercache;
372-
id,
373-
timestamp,
374-
nstime,
375-
tags,
376-
smallData,
377-
solvable,
378-
)
379-
end
380-
381281
function Base.getproperty(x::FactorCompute, f::Symbol)
382282
if f == :solvable
383283
getfield(x, f)[]
384284
elseif f == :solverData
285+
# TODO remove, deprecated in v0.27
385286
error(
386287
"`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getState` or `getCache` instead.",
387288
)

src/services/CompareUtils.jl

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const GeneratedCompareUnion = Union{
2525
VariableDFG,
2626
VariableSummary,
2727
VariableSkeleton,
28-
GenericFunctionNodeData,
2928
FactorCompute,
3029
FactorDFG,
3130
FactorSummary,
@@ -267,38 +266,6 @@ function compareVariable(
267266
return TP::Bool
268267
end
269268

270-
function compareAllSpecial(
271-
A::T1,
272-
B::T2;
273-
skip = Symbol[],
274-
show::Bool = true,
275-
) where {T1 <: GenericFunctionNodeData, T2 <: GenericFunctionNodeData}
276-
if T1 != T2
277-
@warn "compareAllSpecial is comparing different types" T1 T2
278-
# return false
279-
# else
280-
end
281-
return compareAll(A, B; skip = skip, show = show)
282-
end
283-
284-
# Compare FunctionNodeData
285-
function compare(
286-
a::GenericFunctionNodeData{T1},
287-
b::GenericFunctionNodeData{T2},
288-
) where {T1, T2}
289-
# TODO -- beef up this comparison to include the gwp
290-
TP = true
291-
TP = TP && a.eliminated == b.eliminated
292-
TP = TP && a.potentialused == b.potentialused
293-
TP = TP && a.edgeIDs == b.edgeIDs
294-
# TP = TP && typeof(a.fnc) == typeof(b.fnc)
295-
TP = TP && (a.multihypo - b.multihypo |> norm < 1e-10)
296-
TP = TP && a.certainhypo == b.certainhypo
297-
TP = TP && a.nullhypo == b.nullhypo
298-
TP = TP && a.solveInProgress == b.solveInProgress
299-
return TP
300-
end
301-
302269
"""
303270
$SIGNATURES
304271
@@ -406,7 +373,6 @@ end
406373
# Bd = getSolverData(B)
407374
# TP = compareAll(A, B, skip=[:attributes;:data], show=show)
408375
# TP &= compareAll(A.attributes, B.attributes, skip=[:data;], show=show)
409-
# TP &= compareAllSpecial(getSolverData(A).fnc, getSolverData(B).fnc, skip=[:cpt;], show=show)
410376
# TP &= compareAll(getSolverData(A).fnc.cpt, getSolverData(B).fnc.cpt, show=show)
411377

412378
"""

0 commit comments

Comments
 (0)