Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
##=================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 17 additions & 11 deletions src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
##==============================================================================
Expand Down Expand Up @@ -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)"""
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -140,6 +143,7 @@ function FactorDFG(
timestamp,
solvable = Ref(solvable),
bloblets,
hyper,
state,
observation,
)
Expand All @@ -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(
Expand Down Expand Up @@ -194,6 +199,7 @@ function FactorDFG(
Ref(solvable),
bloblets,
observation,
hyper,
state,
solvercache,
blobentries,
Expand Down
23 changes: 5 additions & 18 deletions src/services/CompareUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const GeneratedCompareUnion = Union{
VariableSkeleton,
FactorSummary,
FactorSkeleton,
FactorState,
Recipehyper,
Recipestate,
}

@generated function ==(x::T, y::T) where {T <: GeneratedCompareUnion}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/services/CustomPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions src/services/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/compareTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/fileDFGTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/iifInterfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 12 additions & 17 deletions test/testBlocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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),
Expand Down Expand Up @@ -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)

Expand Down
Loading