Skip to content

Commit 97044de

Browse files
authored
FactorState -> Recipestate + Recipehyper (#1199)
1 parent 7a1e423 commit 97044de

File tree

10 files changed

+60
-58
lines changed

10 files changed

+60
-58
lines changed

src/Deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ getVariablePPE(args...) = _ppe_obsolete()
338338
MeanMaxPPE(args...; kwargs...) = _ppe_obsolete()
339339
getEstimateFields(args...) = _ppe_obsolete()
340340

341+
function getFactorState(args...)
342+
return error(
343+
"getFactorState is deprecated, use DFG.getRecipehyper or DFG.getRecipestate instead.",
344+
)
345+
end
346+
341347
## ================================================================================
342348
## Deprecated in v0.28
343349
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ public getStateKind
354354
const unstable_functions::Vector{Symbol} = [
355355
:getTags,
356356
:InMemoryBlobstore,
357-
:getFactorState, # FIXME getFactorState were questioned and being reviewed again for name, other than that they are checked.
358357
:exists,
359358
:compare,
360359
:compareField,
@@ -441,6 +440,7 @@ const unstable_functions::Vector{Symbol} = [
441440
# no set on these
442441

443442
#deprecated in v0.29
443+
:getFactorState, # FIXME getFactorState were questioned and being reviewed again for name, other than that they are checked.
444444
:packDistribution,
445445
:unpackDistribution,
446446
:hasTagsNeighbors,

src/entities/DFGFactor.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ const FactorCache = AbstractFactorCache #
2020
##==============================================================================
2121

2222
#TODO is this mutable
23-
@kwdef mutable struct FactorState
24-
eliminated::Bool = false # TODO should eliminated and potentialused be moved outside of FactorState?
25-
potentialused::Bool = false # TODO ^
23+
@kwdef mutable struct Recipehyper
2624
multihypo::Vector{Float64} = Float64[] # TODO re-evaluate after refactoring w #477
27-
certainhypo::Vector{Int} = Int[] #TODO mihgt be dead code?
2825
nullhypo::Float64 = 0.0
29-
# solveInProgress::Int = 0 #TODO maybe deprecated or move to operational memory, also why Int?
3026
inflation::Float64 = 0.0
3127
end
3228

29+
@kwdef mutable struct Recipestate
30+
eliminated::Bool = false
31+
potentialused::Bool = false
32+
end
33+
3334
##==============================================================================
3435
## Factors
3536
##==============================================================================
@@ -80,9 +81,10 @@ StructUtils.@kwarg struct FactorDFG{T <: AbstractObservation, N} <: AbstractGrap
8081
"""Observation function or measurement for this factor.
8182
Accessors: [`getObservation`](@ref)(@ref)"""
8283
observation::T & (lower = pack_lower, choosetype = DFG.resolvePackedType)#TODO finalise serializd type
83-
"""Describes the current state of the factor. Persisted in serialization.
84-
Accessors: [`getFactorState`](@ref)"""
85-
state::FactorState = FactorState()
84+
"""Hyperparameters associated with this factor."""
85+
hyper::Recipehyper = Recipehyper()
86+
"""Describes the current state of the factor. Persisted in serialization."""
87+
state::Recipestate = Recipestate()
8688
"""Temporary, non-persistent memory used internally by the solver for intermediate numerical computations and buffers.
8789
`solvercache` is lazily allocated and only used during factor operations; it is not serialized or retained after solving.
8890
Accessors: [`getCache`](@ref), [`setCache!`](@ref)"""
@@ -96,7 +98,7 @@ end
9698
version(::Type{<:FactorDFG}) = v"0.29.0"
9799

98100
##------------------------------------------------------------------------------
99-
## Constructors
101+
## Constructors - IIF like
100102
function FactorDFG(
101103
variableorder::Union{<:Tuple, Vector{Symbol}},
102104
observation::AbstractObservation;
@@ -129,7 +131,8 @@ function FactorDFG(
129131
end
130132

131133
# create factor data
132-
state = FactorState(; multihypo, nullhypo, inflation)
134+
hyper = Recipehyper(; multihypo, nullhypo, inflation)
135+
state = Recipestate()
133136

134137
union!(tags, [:FACTOR])
135138
# create factor
@@ -140,6 +143,7 @@ function FactorDFG(
140143
timestamp,
141144
solvable = Ref(solvable),
142145
bloblets,
146+
hyper,
143147
state,
144148
observation,
145149
)
@@ -152,7 +156,8 @@ function FactorDFG(
152156
label::Symbol,
153157
variableorder::Union{Vector{Symbol}, Tuple},
154158
observation::AbstractObservation,
155-
state::FactorState = FactorState(),
159+
hyper::Recipehyper = Recipehyper(),
160+
state::Recipestate = Recipestate(),
156161
cache = nothing;
157162
tags::Set{Symbol} = Set{Symbol}([:FACTOR]),
158163
timestamp::Union{DateTime, ZonedDateTime, TimeDateZone} = TimeDateZone(
@@ -194,6 +199,7 @@ function FactorDFG(
194199
Ref(solvable),
195200
bloblets,
196201
observation,
202+
hyper,
197203
state,
198204
solvercache,
199205
blobentries,

src/services/CompareUtils.jl

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const GeneratedCompareUnion = Union{
2626
VariableSkeleton,
2727
FactorSummary,
2828
FactorSkeleton,
29-
FactorState,
29+
Recipehyper,
30+
Recipestate,
3031
}
3132

3233
@generated function ==(x::T, y::T) where {T <: GeneratedCompareUnion}
@@ -252,16 +253,7 @@ function compareVariable(
252253
skipsamples::Bool = true,
253254
)
254255
#
255-
skiplist = union(
256-
[
257-
:states;
258-
:atzone;
259-
:inzone;
260-
:blobentries;
261-
:bloblets
262-
],
263-
skip,
264-
)
256+
skiplist = union([:states, :atzone, :inzone, :blobentries, :bloblets], skip)
265257
TP = compareAll(A, B; skip = skiplist, show = show)
266258
varskiplist = skipsamples ? [:val; :bw] : Symbol[]
267259
skiplist = union([:variableType;], varskiplist)
@@ -303,13 +295,8 @@ function compareFactor(
303295
)
304296
TP = compareAll(A, B; skip = skip_, show = show)
305297
@debug "compareFactor 1/5" TP
306-
TP =
307-
TP & compareAll(
308-
getFactorState(A),
309-
getFactorState(B);
310-
skip = union([:fnc; :_gradients], skip),
311-
show = show,
312-
)
298+
TP &= compareAll(A.state, B.state; skip, show)
299+
TP &= compareAll(A.hyper, B.hyper; skip, show)
313300
@debug "compareFactor 2/5" TP
314301
if !TP || :fnc in skip
315302
return TP

src/services/CustomPrinting.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ function printFactor(
112112
println(ioc)
113113
println(ioc, " solvable: ", getSolvable(vert))
114114
println(ioc, " VariableOrder: ", vert.variableorder)
115-
println(ioc, " multihypo: ", getFactorState(vert).multihypo) # FIXME #477
116-
println(ioc, " nullhypo: ", getFactorState(vert).nullhypo)
115+
println(ioc, " multihypo: ", vert.hyper.multihypo) # FIXME #477
116+
println(ioc, " nullhypo: ", vert.hyper.nullhypo)
117117
println(ioc, " tags: ", vert.tags)
118118
printstyled(ioc, " FactorType: "; bold = true, color = :blue)
119119
println(ioc, fctt)

src/services/DFGFactor.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@
66
# getSolveInProgress
77
# isSolveInProgress
88

9-
#TODO `FactorState` is no longer the correct noun, update getFactorState.
109
"""
1110
$SIGNATURES
1211
13-
Return factor state from factor graph.
12+
Return factor recipe state from factor graph.
1413
"""
15-
getFactorState(f::AbstractGraphFactor) = f.state
16-
getFactorState(dfg::AbstractDFG, lbl::Symbol) = getFactorState(getFactor(dfg, lbl))
14+
getRecipestate(f::AbstractGraphFactor) = f.state
15+
getRecipestate(dfg::AbstractDFG, lbl::Symbol) = getRecipestate(getFactor(dfg, lbl))
16+
17+
"""
18+
$SIGNATURES
19+
Return the hyperparameters associated with a factor in the factor graph.
20+
These hyperparameters may include settings such as multi-hypothesis handling,
21+
null hypothesis thresholds, and inflation factors that influence the behavior of the factor during optimization.
22+
"""
23+
getRecipehyper(f::AbstractGraphFactor) = f.hyper
24+
getRecipehyper(dfg::AbstractDFG, lbl::Symbol) = getRecipehyper(getFactor(dfg, lbl))
1725

1826
"""
1927
$SIGNATURES

test/compareTests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ setSolvable!(v2, 0)
3333
VariableCompute(:x1, TestVariableType1()) == VariableCompute(:x1, TestVariableType2())
3434
)
3535

36-
facstate1 = DFG.FactorState(; eliminated = true, potentialused = true)
36+
facstate1 = DFG.Recipestate(; eliminated = true, potentialused = true)
3737
facstate2 = deepcopy(facstate1)
38-
facstate3 = DFG.FactorState(; eliminated = true, potentialused = false)
38+
facstate3 = DFG.Recipestate(; eliminated = true, potentialused = false)
3939

4040
@test facstate1 == facstate2
4141
@test !(facstate1 == facstate3)

test/fileDFGTests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ using UUIDs
6161
1:(numNodes - 1),
6262
)
6363
map(f -> setSolvable!(f, Int(round(rand()))), facts)
64-
map(f -> DFG.getFactorState(f).eliminated = rand() > 0.5, facts)
65-
map(f -> DFG.getFactorState(f).potentialused = rand() > 0.5, facts)
64+
map(f -> f.state.eliminated = rand() > 0.5, facts)
65+
map(f -> f.state.potentialused = rand() > 0.5, facts)
6666
mergeFactor!.(dfg, facts)
6767

6868
#test multihypo

test/iifInterfaceTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ end
185185

186186
@test getLabel(f1) == f1.label
187187
@test getTags(f1) == f1.tags
188-
@test getFactorState(f1) === f1.state
188+
@test DFG.getRecipestate(f1) === f1.state
189189
@test getObservation(f1) === f1.observation
190190

191191
@test getSolverParams(dfg) !== nothing

test/testBlocks.jl

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ function DFGStructureAndAccessors(
100100
des = "description for runtest"
101101
rId = :testRobotId
102102
sId = :testSessionId
103-
rd = DFG.Bloblets(:rd=>DFG.Bloblet(:rd, "rdEntry"))
104-
sd = DFG.Bloblets(:sd=>DFG.Bloblet(:sd, "sdEntry"))
103+
rd = DFG.Bloblets(:rd => DFG.Bloblet(:rd, "rdEntry"))
104+
sd = DFG.Bloblets(:sd => DFG.Bloblet(:sd, "sdEntry"))
105105
fg = T(;
106106
graphDescription = des,
107107
agentLabel = rId,
@@ -434,6 +434,7 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
434434
f2.label,
435435
(:a,),
436436
f2.observation,
437+
f2.hyper,
437438
f2.state;
438439
timestamp = f2.timestamp,
439440
tags = f2.tags,
@@ -1236,13 +1237,8 @@ function connectivityTestGraph(
12361237
setSolvable!(dfg, :x8, 0)
12371238
setSolvable!(dfg, :x9, 0)
12381239

1239-
facstate = DFG.FactorState(;
1240-
eliminated = true,
1241-
potentialused = true,
1242-
multihypo = Float64[],
1243-
certainhypo = Int[],
1244-
inflation = 1.0,
1245-
)
1240+
state = DFG.Recipestate(; eliminated = true, potentialused = true)
1241+
hyper = DFG.Recipehyper(; multihypo = Float64[], inflation = 1.0)
12461242
f_tags = Set([:FACTOR])
12471243

12481244
facs = map(
@@ -1252,8 +1248,9 @@ function connectivityTestGraph(
12521248
Symbol("x$(n)x$(n+1)f1"),
12531249
[vars[n].label, vars[n + 1].label],
12541250
TestFunctorInferenceType1(),
1255-
facstate;
1256-
tags = deepcopy(f_tags),
1251+
deepcopy(hyper),
1252+
deepcopy(state);
1253+
tags = copy(f_tags),
12571254
),
12581255
),
12591256
1:(length(vars) - 1),
@@ -1616,13 +1613,11 @@ function FileDFGTestBlock(testDFGAPI; kwargs...)
16161613
mergeVariable!(dfg, v4)
16171614

16181615
f45 = getFactor(dfg, :x4x5f1)
1619-
fsd = getFactorState(f45)
16201616
# set some factor solver data
1621-
push!(fsd.certainhypo, 2)
1622-
fsd.eliminated = true
1623-
push!(fsd.multihypo, 4.0)
1624-
fsd.nullhypo = 5.0
1625-
fsd.potentialused = true
1617+
f45.state.eliminated = true
1618+
push!(f45.hyper.multihypo, 4.0)
1619+
f45.hyper.nullhypo = 5.0
1620+
f45.state.potentialused = true
16261621
#update factor
16271622
mergeFactor!(dfg, f45)
16281623

0 commit comments

Comments
 (0)