Skip to content

Commit 66666f1

Browse files
committed
Intermediate removing factor solverData
1 parent eba3b38 commit 66666f1

7 files changed

Lines changed: 89 additions & 49 deletions

File tree

src/Deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ function updateVariableSolverData!(
7373
fields::Vector{Symbol} = Symbol[];
7474
warn_if_absent::Bool = true,
7575
)
76+
Base.depwarn(
77+
"updateVariableSolverData! is deprecated, use mergeVariableState! or copytoVariableState! instead",
78+
:updateVariableSolverData!,
79+
)
7680
#This is basically just setSolverData
7781
var = getVariable(dfg, variablekey)
7882
warn_if_absent &&

src/entities/DFGFactor.jl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ Base.@kwdef struct FactorDFG <: AbstractDFGFactor
114114
nstime::String
115115
fnctype::String
116116
solvable::Int
117-
data::String
117+
data::Union{String, Nothing} = nothing #TODO deprecated in v0.27 remove data completely, use state and observJSON
118118
metadata::String
119119
_version::String = string(_getDFGVersion())
120120
state::FactorState
121-
observJSON::String # serialized opbservation
121+
observJSON::String # serialized observation
122122
# blobEntries::Vector{Blobentry}#TODO should factor have blob entries?
123123
end
124124

@@ -131,7 +131,7 @@ StructTypes.StructType(::Type{FactorDFG}) = StructTypes.UnorderedStruct()
131131
StructTypes.idproperty(::Type{FactorDFG}) = :id
132132
StructTypes.omitempties(::Type{FactorDFG}) = (:id,)
133133

134-
#TODO deprecate, added in v0.26 as a bridge to new serialization structure
134+
#TODO deprecate, added in v0.27 as a bridge to new serialization structure
135135
function FactorDFG(
136136
id::Union{UUID, Nothing},
137137
label::Symbol,
@@ -141,7 +141,7 @@ function FactorDFG(
141141
nstime::String,
142142
fnctype::String,
143143
solvable::Int,
144-
data::String,
144+
data::Union{Nothing, String},
145145
metadata::String,
146146
_version::String,
147147
state::Union{Nothing, FactorState},
@@ -300,25 +300,28 @@ function FactorCompute(
300300
variableOrder::Union{Vector{Symbol}, Tuple},
301301
observation::AbstractFactor,
302302
state::FactorState = FactorState(),
303-
workmem = Ref{FactorOperationalMemory}();
303+
_workmem = nothing;
304304
tags::Set{Symbol} = Set{Symbol}(),
305305
timestamp::Union{DateTime, ZonedDateTime} = now(localzone()),
306306
solvable::Int = 1,
307307
nstime::Nanosecond = Nanosecond(0),
308308
id::Union{UUID, Nothing} = nothing,
309309
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}(),
310-
solverData = nothing
310+
solverData = nothing,
311311
)
312312
if isnothing(solverData)
313313
refsolverData = Ref{GenericFunctionNodeData}() #TODO solverData deprecated in v0.27 WIP
314314
else
315-
Base.depwarn(
316-
"`FactorCompute` solverData is deprecated",
317-
:FactorCompute,
318-
)
315+
Base.depwarn("`FactorCompute` solverData is deprecated", :FactorCompute)
319316
refsolverData = Ref(solverData)
320317
end
321-
318+
319+
if isnothing(_workmem)
320+
workmem = Ref{FactorOperationalMemory}()
321+
else
322+
workmem = Ref(_workmem)
323+
end
324+
322325
return FactorCompute(
323326
id,
324327
label,
@@ -362,9 +365,9 @@ function FactorCompute(
362365
)
363366

364367
if solverData.fnc isa FactorOperationalMemory
365-
workmem = Ref(solverData.fnc)
368+
workmem = solverData.fnc
366369
else
367-
workmem = Ref{FactorOperationalMemory}()
370+
workmem = nothing
368371
end
369372

370373
return FactorCompute(
@@ -383,9 +386,20 @@ function FactorCompute(
383386
)
384387
end
385388

386-
Base.getproperty(x::FactorCompute, f::Symbol) = begin
387-
if f == :solvable || f == :solverData
389+
function Base.getproperty(x::FactorCompute, f::Symbol)
390+
if f == :solvable
388391
getfield(x, f)[]
392+
elseif f == :solverData
393+
Base.depwarn(
394+
"`FactorCompute` field `$(f)` is deprecated, use `getObservation`, `getState` or `getWorkmem` instead.",
395+
:getproperty,
396+
)
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
389403
elseif f == :_variableOrderSymbols
390404
[getfield(x, f)...]
391405
else

src/services/CompareUtils.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const GeneratedCompareUnion = Union{
3434
}
3535

3636
@generated function ==(x::T, y::T) where {T <: GeneratedCompareUnion}
37-
ignored = [:workmem]
37+
ignored = [:workmem, :solverData]
3838
return mapreduce(
3939
n -> :(x.$n == y.$n),
4040
(a, b) -> :($a && $b),
@@ -330,9 +330,9 @@ function compareFactor(
330330
TP = compareAll(A, B; skip = skip_, show = show)
331331
@debug "compareFactor 1/5" TP
332332
TP =
333-
TP & compareAllSpecial(
334-
getSolverData(A),
335-
getSolverData(B);
333+
TP & compareAll(
334+
getState(A),
335+
getState(B);
336336
skip = union([:fnc; :_gradients], skip),
337337
show = show,
338338
)
@@ -341,9 +341,9 @@ function compareFactor(
341341
return TP
342342
end
343343
TP =
344-
TP & compareAllSpecial(
345-
getSolverData(A).fnc,
346-
getSolverData(B).fnc;
344+
TP & compareAll(
345+
getObservation(A),
346+
getObservation(B);
347347
skip = union(
348348
[
349349
:cpt
@@ -359,7 +359,9 @@ function compareFactor(
359359
show = show,
360360
)
361361
@debug "compareFactor 3/5" TP
362-
if !(:measurement in skip)
362+
363+
#FIXME is measurement stil in use and should it be checked, skipping for now
364+
if false # !(:measurement in skip)
363365
TP =
364366
TP & (
365367
skipsamples || compareAll(
@@ -371,7 +373,8 @@ function compareFactor(
371373
)
372374
end
373375
@debug "compareFactor 4/5" TP
374-
if !(:varValsAll in skip) && hasfield(typeof(getSolverData(A).fnc), :varValsAll)
376+
#FIXME is varValsAll stil in use and should it be checked, skipping for now
377+
if false #!(:varValsAll in skip) && hasfield(typeof(getSolverData(A).fnc), :varValsAll)
375378
TP =
376379
TP & (
377380
skipcompute || compareAll(
@@ -383,8 +386,8 @@ function compareFactor(
383386
)
384387
end
385388
@debug "compareFactor 5/5" TP
386-
if !(:varidx in skip) &&
387-
hasfield(typeof(getSolverData(A).fnc), :varidx) &&
389+
#FIXME is varidx stil in use and should it be checked, skipping for now
390+
if false #!(:varidx in skip) && hasfield(typeof(getSolverData(A).fnc), :varidx) &&
388391
getSolverData(A).fnc.varidx isa Base.RefValue
389392
TP =
390393
TP & (

src/services/DFGFactor.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
Return reference to the user factor in `<:AbstractDFG` identified by `::Symbol`.
2222
"""
2323
getFactorFunction(fcd::GenericFunctionNodeData) = fcd.fnc.usrfnc!
24-
getFactorFunction(fc::FactorCompute) = getFactorFunction(getSolverData(fc))
24+
getFactorFunction(fc::FactorCompute) = getObservation(fc)
2525
getFactorFunction(dfg::AbstractDFG, fsym::Symbol) = getFactorFunction(getFactor(dfg, fsym))
2626

2727
"""
@@ -32,9 +32,17 @@ Return user factor type from factor graph identified by label `::Symbol`.
3232
Notes
3333
- Replaces older `getfnctype`.
3434
"""
35-
getFactorType(data::GenericFunctionNodeData{<:FactorOperationalMemory}) = data.fnc.usrfnc!
36-
getFactorType(data::GenericFunctionNodeData{<:AbstractFactor}) = data.fnc
37-
getFactorType(fct::FactorCompute) = getFactorType(getSolverData(fct))
35+
function getFactorType(data::GenericFunctionNodeData{<:FactorOperationalMemory})
36+
#TODO deprecated in v0.27
37+
Base.depwarn("getFactorType(::GenericFunctionNodeData) is deprecated", :getFactorType)
38+
return data.fnc.usrfnc!
39+
end
40+
function getFactorType(data::GenericFunctionNodeData{<:AbstractFactor})
41+
#TODO deprecated in v0.27
42+
Base.depwarn("getFactorType(::GenericFunctionNodeData) is deprecated", :getFactorType)
43+
return data.fnc
44+
end
45+
getFactorType(fct::FactorCompute) = getObservation(fct)
3846
getFactorType(f::FactorDFG) = getTypeFromSerializationModule(f.fnctype)() # TODO find a better way to do this that does not rely on empty constructor
3947
getFactorType(dfg::AbstractDFG, lbl::Symbol) = getFactorType(getFactor(dfg, lbl))
4048

@@ -225,7 +233,12 @@ getVariableOrder(dfg::AbstractDFG, fct::Symbol) = getVariableOrder(getFactor(dfg
225233
Retrieve solver data structure stored in a factor.
226234
"""
227235
function getSolverData(f::FactorCompute)
228-
return f.solverData
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
229242
end
230243

231244
setSolverData!(f::FactorCompute, data::GenericFunctionNodeData) = f.solverData = data

src/services/Serialization.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,13 @@ VariableDFG(v::VariableCompute) = packVariable(v)
253253

254254
function _packSolverData(f::FactorCompute, fnctype::AbstractFactor)
255255
#
256+
Base.depwarn(
257+
"_packSolverData is deprecated, use seperate packing of observation #TODO",
258+
:_packSolverData,
259+
)
256260
packtype = convertPackedType(fnctype)
257261
try
258-
packed = convert(PackedFunctionNodeData{packtype}, getSolverData(f))
262+
packed = convert(PackedFunctionNodeData{packtype}, getSolverData(f)) #TODO getSolverData
259263
packedJson = packed
260264
return packedJson
261265
catch ex
@@ -269,7 +273,7 @@ end
269273

270274
# returns FactorDFG
271275
function packFactor(f::FactorCompute)
272-
fnctype = getSolverData(f).fnc.usrfnc!
276+
fnctype = getObservation(f)
273277
return FactorDFG(;
274278
id = f.id,
275279
label = f.label,
@@ -281,7 +285,6 @@ function packFactor(f::FactorCompute)
281285
solvable = getSolvable(f),
282286
metadata = base64encode(JSON3.write(f.smallData)),
283287
# Pack the node data
284-
data = JSON3.write(_packSolverData(f, fnctype)),
285288
_version = string(_getDFGVersion()),
286289
state = f.state,
287290
observJSON = JSON3.write(packObservation(f)),
@@ -383,15 +386,19 @@ function unpackFactor(dfg::AbstractDFG, factor::FactorDFG; skipVersionCheck::Boo
383386
local fullFactorData
384387
local observation
385388
try
386-
if factor.data[1] == '{'
387-
packedFnc = fncStringToData(factor.fnctype, factor.data)
388-
observation = unpackObservation(factor)
389+
observation = unpackObservation(factor)
390+
if !isnothing(factor.data)
391+
if factor.data[1] == '{'
392+
packedFnc = fncStringToData(factor.fnctype, factor.data)
393+
else
394+
packedFnc = fncStringToData(factor.fnctype, String(base64decode(factor.data)))
395+
end
396+
decodeType = getFactorOperationalMemoryType(dfg)
397+
fullFactorData =
398+
decodePackedType(dfg, factor._variableOrderSymbols, decodeType, packedFnc)
389399
else
390-
packedFnc = fncStringToData(factor.fnctype, String(base64decode(factor.data)))
400+
fullFactorData = nothing
391401
end
392-
decodeType = getFactorOperationalMemoryType(dfg)
393-
fullFactorData =
394-
decodePackedType(dfg, factor._variableOrderSymbols, decodeType, packedFnc)
395402
catch ex
396403
io = IOBuffer()
397404
showerror(io, ex, catch_backtrace())
@@ -402,10 +409,10 @@ function unpackFactor(dfg::AbstractDFG, factor::FactorDFG; skipVersionCheck::Boo
402409

403410
metadata = JSON3.read(base64decode(factor.metadata), Dict{Symbol, DFG.SmallDataTypes})
404411

405-
if fullFactorData.fnc isa FactorOperationalMemory
406-
workmem = Ref(fullFactorData.fnc)
412+
if !isnothing(fullFactorData) && fullFactorData.fnc isa FactorOperationalMemory
413+
workmem = fullFactorData.fnc
407414
else
408-
workmem = Ref{FactorOperationalMemory}()
415+
workmem = nothing
409416
end
410417
return FactorCompute(
411418
factor.label,

test/fileDFGTests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ using UUIDs
8080
1:(numNodes - 1),
8181
)
8282
map(f -> setSolvable!(f, Int(round(rand()))), facts)
83-
map(f -> f.solverData.eliminated = rand() > 0.5, facts)
84-
map(f -> f.solverData.potentialused = rand() > 0.5, facts)
83+
map(f -> DFG.getState(f).eliminated = rand() > 0.5, facts)
84+
map(f -> DFG.getState(f).potentialused = rand() > 0.5, facts)
8585
mergeFactor!.(dfg, facts)
8686

8787
#test multihypo
@@ -135,7 +135,7 @@ using UUIDs
135135
@test compareFactor(
136136
getFactor(dfg, fact),
137137
getFactor(retDFG, fact),
138-
skip = [:timezone, :zone],
138+
skip = [:timezone, :zone, :solverData,],
139139
) # Timezones
140140
# :hypotheses, :certainhypo, :multihypo, # Multihypo
141141
# :eliminated,

test/testBlocks.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@ function VSDTestBlock!(fg, v1)
794794
# Delete it
795795
@test deleteVariableSolverData!(fg, :a, :parametric) == 1
796796
# Update add it
797-
@test @test_logs (:warn, r"does not exist") updateVariableSolverData!(fg, :a, vnd) ==
798-
vnd
797+
@test mergeVariableState!(fg, :a, vnd) == 1
799798

800799
# Update update it
801800
@test updateVariableSolverData!(fg, :a, vnd) == vnd

0 commit comments

Comments
 (0)