diff --git a/src/Deprecated.jl b/src/Deprecated.jl index d8d59c3d..f1afce3d 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -338,6 +338,12 @@ getVariablePPE(args...) = _ppe_obsolete() MeanMaxPPE(args...; kwargs...) = _ppe_obsolete() getEstimateFields(args...) = _ppe_obsolete() +function getFactorState(args...) + return error( + "getFactorState is deprecated, use DFG.getRecipehyper or DFG.getRecipestate instead.", + ) +end + ## ================================================================================ ## Deprecated in v0.28 ##================================================================================= diff --git a/src/DistributedFactorGraphs.jl b/src/DistributedFactorGraphs.jl index 10867e30..35ea73c4 100644 --- a/src/DistributedFactorGraphs.jl +++ b/src/DistributedFactorGraphs.jl @@ -354,7 +354,6 @@ public getStateKind const unstable_functions::Vector{Symbol} = [ :getTags, :InMemoryBlobstore, - :getFactorState, # FIXME getFactorState were questioned and being reviewed again for name, other than that they are checked. :exists, :compare, :compareField, @@ -441,6 +440,7 @@ const unstable_functions::Vector{Symbol} = [ # no set on these #deprecated in v0.29 + :getFactorState, # FIXME getFactorState were questioned and being reviewed again for name, other than that they are checked. :packDistribution, :unpackDistribution, :hasTagsNeighbors, diff --git a/src/entities/DFGFactor.jl b/src/entities/DFGFactor.jl index 90d7aa85..c6573699 100644 --- a/src/entities/DFGFactor.jl +++ b/src/entities/DFGFactor.jl @@ -20,16 +20,17 @@ const FactorCache = AbstractFactorCache # ##============================================================================== #TODO is this mutable -@kwdef mutable struct FactorState - eliminated::Bool = false # TODO should eliminated and potentialused be moved outside of FactorState? - potentialused::Bool = false # TODO ^ +@kwdef mutable struct Recipehyper multihypo::Vector{Float64} = Float64[] # TODO re-evaluate after refactoring w #477 - certainhypo::Vector{Int} = Int[] #TODO mihgt be dead code? nullhypo::Float64 = 0.0 - # solveInProgress::Int = 0 #TODO maybe deprecated or move to operational memory, also why Int? inflation::Float64 = 0.0 end +@kwdef mutable struct Recipestate + eliminated::Bool = false + potentialused::Bool = false +end + ##============================================================================== ## Factors ##============================================================================== @@ -80,9 +81,10 @@ StructUtils.@kwarg struct FactorDFG{T <: AbstractObservation, N} <: AbstractGrap """Observation function or measurement for this factor. Accessors: [`getObservation`](@ref)(@ref)""" observation::T & (lower = pack_lower, choosetype = DFG.resolvePackedType)#TODO finalise serializd type - """Describes the current state of the factor. Persisted in serialization. - Accessors: [`getFactorState`](@ref)""" - state::FactorState = FactorState() + """Hyperparameters associated with this factor.""" + hyper::Recipehyper = Recipehyper() + """Describes the current state of the factor. Persisted in serialization.""" + state::Recipestate = Recipestate() """Temporary, non-persistent memory used internally by the solver for intermediate numerical computations and buffers. `solvercache` is lazily allocated and only used during factor operations; it is not serialized or retained after solving. Accessors: [`getCache`](@ref), [`setCache!`](@ref)""" @@ -96,7 +98,7 @@ end version(::Type{<:FactorDFG}) = v"0.29.0" ##------------------------------------------------------------------------------ -## Constructors +## Constructors - IIF like function FactorDFG( variableorder::Union{<:Tuple, Vector{Symbol}}, observation::AbstractObservation; @@ -129,7 +131,8 @@ function FactorDFG( end # create factor data - state = FactorState(; multihypo, nullhypo, inflation) + hyper = Recipehyper(; multihypo, nullhypo, inflation) + state = Recipestate() union!(tags, [:FACTOR]) # create factor @@ -140,6 +143,7 @@ function FactorDFG( timestamp, solvable = Ref(solvable), bloblets, + hyper, state, observation, ) @@ -152,7 +156,8 @@ function FactorDFG( label::Symbol, variableorder::Union{Vector{Symbol}, Tuple}, observation::AbstractObservation, - state::FactorState = FactorState(), + hyper::Recipehyper = Recipehyper(), + state::Recipestate = Recipestate(), cache = nothing; tags::Set{Symbol} = Set{Symbol}([:FACTOR]), timestamp::Union{DateTime, ZonedDateTime, TimeDateZone} = TimeDateZone( @@ -194,6 +199,7 @@ function FactorDFG( Ref(solvable), bloblets, observation, + hyper, state, solvercache, blobentries, diff --git a/src/services/CompareUtils.jl b/src/services/CompareUtils.jl index 46dded34..d60793c8 100644 --- a/src/services/CompareUtils.jl +++ b/src/services/CompareUtils.jl @@ -26,7 +26,8 @@ const GeneratedCompareUnion = Union{ VariableSkeleton, FactorSummary, FactorSkeleton, - FactorState, + Recipehyper, + Recipestate, } @generated function ==(x::T, y::T) where {T <: GeneratedCompareUnion} @@ -252,16 +253,7 @@ function compareVariable( skipsamples::Bool = true, ) # - skiplist = union( - [ - :states; - :atzone; - :inzone; - :blobentries; - :bloblets - ], - skip, - ) + skiplist = union([:states, :atzone, :inzone, :blobentries, :bloblets], skip) TP = compareAll(A, B; skip = skiplist, show = show) varskiplist = skipsamples ? [:val; :bw] : Symbol[] skiplist = union([:variableType;], varskiplist) @@ -303,13 +295,8 @@ function compareFactor( ) TP = compareAll(A, B; skip = skip_, show = show) @debug "compareFactor 1/5" TP - TP = - TP & compareAll( - getFactorState(A), - getFactorState(B); - skip = union([:fnc; :_gradients], skip), - show = show, - ) + TP &= compareAll(A.state, B.state; skip, show) + TP &= compareAll(A.hyper, B.hyper; skip, show) @debug "compareFactor 2/5" TP if !TP || :fnc in skip return TP diff --git a/src/services/CustomPrinting.jl b/src/services/CustomPrinting.jl index f18d195f..923d7d9d 100644 --- a/src/services/CustomPrinting.jl +++ b/src/services/CustomPrinting.jl @@ -112,8 +112,8 @@ function printFactor( println(ioc) println(ioc, " solvable: ", getSolvable(vert)) println(ioc, " VariableOrder: ", vert.variableorder) - println(ioc, " multihypo: ", getFactorState(vert).multihypo) # FIXME #477 - println(ioc, " nullhypo: ", getFactorState(vert).nullhypo) + println(ioc, " multihypo: ", vert.hyper.multihypo) # FIXME #477 + println(ioc, " nullhypo: ", vert.hyper.nullhypo) println(ioc, " tags: ", vert.tags) printstyled(ioc, " FactorType: "; bold = true, color = :blue) println(ioc, fctt) diff --git a/src/services/DFGFactor.jl b/src/services/DFGFactor.jl index 67d6c2cc..61a99a9f 100644 --- a/src/services/DFGFactor.jl +++ b/src/services/DFGFactor.jl @@ -6,14 +6,22 @@ # getSolveInProgress # isSolveInProgress -#TODO `FactorState` is no longer the correct noun, update getFactorState. """ $SIGNATURES -Return factor state from factor graph. +Return factor recipe state from factor graph. """ -getFactorState(f::AbstractGraphFactor) = f.state -getFactorState(dfg::AbstractDFG, lbl::Symbol) = getFactorState(getFactor(dfg, lbl)) +getRecipestate(f::AbstractGraphFactor) = f.state +getRecipestate(dfg::AbstractDFG, lbl::Symbol) = getRecipestate(getFactor(dfg, lbl)) + +""" + $SIGNATURES +Return the hyperparameters associated with a factor in the factor graph. +These hyperparameters may include settings such as multi-hypothesis handling, +null hypothesis thresholds, and inflation factors that influence the behavior of the factor during optimization. +""" +getRecipehyper(f::AbstractGraphFactor) = f.hyper +getRecipehyper(dfg::AbstractDFG, lbl::Symbol) = getRecipehyper(getFactor(dfg, lbl)) """ $SIGNATURES diff --git a/test/compareTests.jl b/test/compareTests.jl index 49f59766..bebbfc5b 100644 --- a/test/compareTests.jl +++ b/test/compareTests.jl @@ -33,9 +33,9 @@ setSolvable!(v2, 0) VariableCompute(:x1, TestVariableType1()) == VariableCompute(:x1, TestVariableType2()) ) -facstate1 = DFG.FactorState(; eliminated = true, potentialused = true) +facstate1 = DFG.Recipestate(; eliminated = true, potentialused = true) facstate2 = deepcopy(facstate1) -facstate3 = DFG.FactorState(; eliminated = true, potentialused = false) +facstate3 = DFG.Recipestate(; eliminated = true, potentialused = false) @test facstate1 == facstate2 @test !(facstate1 == facstate3) diff --git a/test/fileDFGTests.jl b/test/fileDFGTests.jl index b1af165e..fe402d59 100644 --- a/test/fileDFGTests.jl +++ b/test/fileDFGTests.jl @@ -61,8 +61,8 @@ using UUIDs 1:(numNodes - 1), ) map(f -> setSolvable!(f, Int(round(rand()))), facts) - map(f -> DFG.getFactorState(f).eliminated = rand() > 0.5, facts) - map(f -> DFG.getFactorState(f).potentialused = rand() > 0.5, facts) + map(f -> f.state.eliminated = rand() > 0.5, facts) + map(f -> f.state.potentialused = rand() > 0.5, facts) mergeFactor!.(dfg, facts) #test multihypo diff --git a/test/iifInterfaceTests.jl b/test/iifInterfaceTests.jl index 90fc5565..dd5de0a8 100644 --- a/test/iifInterfaceTests.jl +++ b/test/iifInterfaceTests.jl @@ -185,7 +185,7 @@ end @test getLabel(f1) == f1.label @test getTags(f1) == f1.tags - @test getFactorState(f1) === f1.state + @test DFG.getRecipestate(f1) === f1.state @test getObservation(f1) === f1.observation @test getSolverParams(dfg) !== nothing diff --git a/test/testBlocks.jl b/test/testBlocks.jl index 251c1e94..a4221e0b 100644 --- a/test/testBlocks.jl +++ b/test/testBlocks.jl @@ -100,8 +100,8 @@ function DFGStructureAndAccessors( des = "description for runtest" rId = :testRobotId sId = :testSessionId - rd = DFG.Bloblets(:rd=>DFG.Bloblet(:rd, "rdEntry")) - sd = DFG.Bloblets(:sd=>DFG.Bloblet(:sd, "sdEntry")) + rd = DFG.Bloblets(:rd => DFG.Bloblet(:rd, "rdEntry")) + sd = DFG.Bloblets(:sd => DFG.Bloblet(:sd, "sdEntry")) fg = T(; graphDescription = des, agentLabel = rId, @@ -434,6 +434,7 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2) f2.label, (:a,), f2.observation, + f2.hyper, f2.state; timestamp = f2.timestamp, tags = f2.tags, @@ -1236,13 +1237,8 @@ function connectivityTestGraph( setSolvable!(dfg, :x8, 0) setSolvable!(dfg, :x9, 0) - facstate = DFG.FactorState(; - eliminated = true, - potentialused = true, - multihypo = Float64[], - certainhypo = Int[], - inflation = 1.0, - ) + state = DFG.Recipestate(; eliminated = true, potentialused = true) + hyper = DFG.Recipehyper(; multihypo = Float64[], inflation = 1.0) f_tags = Set([:FACTOR]) facs = map( @@ -1252,8 +1248,9 @@ function connectivityTestGraph( Symbol("x$(n)x$(n+1)f1"), [vars[n].label, vars[n + 1].label], TestFunctorInferenceType1(), - facstate; - tags = deepcopy(f_tags), + deepcopy(hyper), + deepcopy(state); + tags = copy(f_tags), ), ), 1:(length(vars) - 1), @@ -1616,13 +1613,11 @@ function FileDFGTestBlock(testDFGAPI; kwargs...) mergeVariable!(dfg, v4) f45 = getFactor(dfg, :x4x5f1) - fsd = getFactorState(f45) # set some factor solver data - push!(fsd.certainhypo, 2) - fsd.eliminated = true - push!(fsd.multihypo, 4.0) - fsd.nullhypo = 5.0 - fsd.potentialused = true + f45.state.eliminated = true + push!(f45.hyper.multihypo, 4.0) + f45.hyper.nullhypo = 5.0 + f45.state.potentialused = true #update factor mergeFactor!(dfg, f45)