diff --git a/NEWS.md b/NEWS.md index 2e2388f8..6fa624f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,13 @@ Listing news on any major breaking changes in DFG. For regular changes, see int - This is used internally be the solver and should not affect the average user of DFG. - Rename FactorOperationalMemory -> FactorSolverCache - Rename AbstractFactor -> AbstractFactorObservation (keeping both around) +- Deprecate VariableNodeData -> VariableState +- Deprecate getVariableSolverData -> getVariableState +- Deprecate addVariableSolverData! -> addVariableState! +- Deprecate deleteVariableSolverData! -> deleteVariableState! +- Deprecate listVariableSolverData -> listVariableStates +- Deprecate getVariableSolverDataAll -> getVariableStates +- Deprecate getSolverData -> getVariableState/getFactorState # v0.26 - Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`. diff --git a/docs/src/GraphData.md b/docs/src/GraphData.md index c9bdca09..8afbb017 100644 --- a/docs/src/GraphData.md +++ b/docs/src/GraphData.md @@ -15,7 +15,7 @@ The following is a guideline to using these parameters. **NOTE**: Adds in general throw an error if the element already exists. Update will update the element if it exists, otherwise it will add it. -**NOTE**: In general these functions will return an error if the respective element is not found. This is to avoid returning, say, nothing, which will be horribly confusing if you tried `getVariableSolverData(dfg, :a, :b)` and it returned nothing - which was missing, :a or :b, or was there a communication issue? We recommend coding defensively and trapping errors in critical portions of your user code. +**NOTE**: In general these functions will return an error if the respective element is not found. This is to avoid returning, say, nothing, which will be horribly confusing if you tried `getVariableState(dfg, :a, :b)` and it returned nothing - which was missing, :a or :b, or was there a communication issue? We recommend coding defensively and trapping errors in critical portions of your user code. **NOTE**: All data is passed by reference, so if you update the returned structure it will update in the graph. The database driver is an exception, and once the variable or factor is updated you need to call update* to persist the changes to the graph. @@ -125,26 +125,26 @@ Solver data is used by IncrementalInference/RoME/Caesar solver to produce the ab Related functions: -- [`listVariableSolverData`](@ref) -- [`getVariableSolverData`](@ref) -- [`addVariableSolverData!`](@ref) +- [`listVariableStates`](@ref) +- [`getVariableState`](@ref) +- [`addVariableState!`](@ref) +- [`mergeVariableState!`](@ref) +- [`deleteVariableState!`](@ref) - [`mergeVariableState!`](@ref) -- [`deleteVariableSolverData!`](@ref) -- [`mergeVariableSolverData!`](@ref) Example of solver data operations: ```julia # Add new VND of type ContinuousScalar to :x0 -# Could also do VariableNodeData(ContinuousScalar()) -vnd = VariableNodeData{ContinuousScalar}() -addVariableSolverData!(dfg, :x0, vnd, :parametric) -@show listVariableSolverData(dfg, :x0) +# Could also do VariableState(ContinuousScalar()) +vnd = VariableState{ContinuousScalar}() +addVariableState!(dfg, :x0, vnd, :parametric) +@show listVariableStates(dfg, :x0) # Get the data back - note that this is a reference to above. -vndBack = getVariableSolverData(dfg, :x0, :parametric) +vndBack = getVariableState(dfg, :x0, :parametric) # Delete it -deleteVariableSolverData!(dfg, :x0, :parametric) +deleteVariableState!(dfg, :x0, :parametric) ``` #### Small Data diff --git a/src/Deprecated.jl b/src/Deprecated.jl index d7cda9b8..a323d107 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -10,6 +10,9 @@ const AbstractPackedFactor = AbstractPackedFactorObservation export FactorOperationalMemory const FactorOperationalMemory = FactorSolverCache +export VariableNodeData +const VariableNodeData = VariableState + @deprecate getNeighborhood(args...; kwargs...) listNeighborhood(args...; kwargs...) @deprecate addBlob!(store::AbstractBlobstore, blobId::UUID, data, ::String) addBlob!( store, @@ -70,13 +73,30 @@ const FactorOperationalMemory = FactorSolverCache ) @deprecate mergeBlobEntries!(args...; kwargs...) mergeBlobentries!(args...; kwargs...) +@deprecate getVariableSolverData(args...; kwargs...) getVariableState(args...; kwargs...) +@deprecate addVariableSolverData!(args...; kwargs...) addVariableState!(args...; kwargs...) +@deprecate deleteVariableSolverData!(args...; kwargs...) deleteVariableState!( + args...; + kwargs..., +) +@deprecate listVariableSolverData(args...; kwargs...) listVariableStates(args...; kwargs...) +@deprecate getVariableSolverDataAll(args...; kwargs...) getVariableStates( + args...; + kwargs..., +) + +@deprecate getSolverData(v::VariableCompute, solveKey::Symbol = :default) getVariableState( + v, + solveKey, +) + export updateVariableSolverData! #TODO possibly completely deprecated or not exported until update verb is standardized function updateVariableSolverData!( dfg::AbstractDFG, variablekey::Symbol, - vnd::VariableNodeData, + vnd::VariableState, useCopy::Bool = false, fields::Vector{Symbol} = Symbol[]; warn_if_absent::Bool = true, @@ -89,14 +109,14 @@ function updateVariableSolverData!( var = getVariable(dfg, variablekey) warn_if_absent && !haskey(var.solverDataDict, vnd.solveKey) && - @warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding" + @warn "VariableState '$(vnd.solveKey)' does not exist, adding" # for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update. usevnd = vnd # useCopy ? deepcopy(vnd) : vnd # should just one, or many pointers be updated? useExisting = haskey(var.solverDataDict, vnd.solveKey) && - isa(var.solverDataDict[vnd.solveKey], VariableNodeData) && + isa(var.solverDataDict[vnd.solveKey], VariableState) && length(fields) != 0 # @error useExisting vnd.solveKey if useExisting @@ -123,7 +143,7 @@ end function updateVariableSolverData!( dfg::AbstractDFG, variablekey::Symbol, - vnd::VariableNodeData, + vnd::VariableState, solveKey::Symbol, useCopy::Bool = false, fields::Vector{Symbol} = Symbol[]; @@ -131,9 +151,9 @@ function updateVariableSolverData!( ) # TODO not very clean if vnd.solveKey != solveKey - @warn( - "updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed", - maxlog = 1 + Base.depwarn( + "updateVariableSolverData with solveKey is deprecated use copytoVariableState! instead.", + :updateVariableSolverData!, ) usevnd = useCopy ? deepcopy(vnd) : vnd usevnd.solveKey = solveKey @@ -170,7 +190,7 @@ function updateVariableSolverData!( # toshow = listSolveKeys(sourceVariable) |> collect # @info "update DFGVar solveKey" solveKey vnd.solveKey # @show toshow - @assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey" + @assert solveKey == vnd.solveKey "VariableState's solveKey=:$(vnd.solveKey) does not match requested :$solveKey" return updateVariableSolverData!( dfg, sourceVariable.label, @@ -258,7 +278,7 @@ export getSolverData, setSolverData! function getSolverData(f::FactorCompute) return error( - "getSolverData(f::FactorCompute) is obsolete, use getState, getObservation, or getCache instead", + "getSolverData(f::FactorCompute) is obsolete, use getFactorState, getObservation, or getCache instead", ) end diff --git a/src/DistributedFactorGraphs.jl b/src/DistributedFactorGraphs.jl index 8cdee465..255e91ae 100644 --- a/src/DistributedFactorGraphs.jl +++ b/src/DistributedFactorGraphs.jl @@ -167,7 +167,7 @@ export getSolverDataDict, setSolverData! export getVariableType, getVariableTypeName export getObservation -export getState, getFactorState +export getFactorState export getVariableType @@ -186,11 +186,12 @@ export getMetadata, emptyMetadata! # CRUD & SET -export getVariableSolverData, - addVariableSolverData!, +export getVariableState, + getVariableStates, + addVariableState!, mergeVariableState!, - deleteVariableSolverData!, - listVariableSolverData, + deleteVariableState!, + listVariableStates, mergeVariableSolverData!, cloneSolveKey! @@ -211,9 +212,9 @@ export getPPE, # Variable Node Data ##------------------------------------------------------------------------------ -export VariableNodeData, PackedVariableNodeData +export VariableState, PackedVariableState -export packVariableNodeData, unpackVariableNodeData +export packVariableState, unpackVariableState export getSolvedCount, isSolved, setSolvedCount!, isInitialized, isMarginalized, setMarginalized! diff --git a/src/entities/DFGFactor.jl b/src/entities/DFGFactor.jl index 6a7e3970..a97fdc1f 100644 --- a/src/entities/DFGFactor.jl +++ b/src/entities/DFGFactor.jl @@ -283,7 +283,7 @@ function Base.getproperty(x::FactorCompute, f::Symbol) elseif f == :solverData # TODO remove, deprecated in v0.27 error( - "`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getState` or `getCache` instead.", + "`solverData` is obsolete in `FactorCompute`. Use `getObservation`, `getFactorState` or `getCache` instead.", ) elseif f == :_variableOrderSymbols [getfield(x, f)...] diff --git a/src/entities/DFGVariable.jl b/src/entities/DFGVariable.jl index 54a42405..d4b457e0 100644 --- a/src/entities/DFGVariable.jl +++ b/src/entities/DFGVariable.jl @@ -5,7 +5,7 @@ abstract type InferenceVariable end ##============================================================================== -## VariableNodeData +## VariableState ##============================================================================== """ @@ -19,7 +19,7 @@ N: Manifold dimension. Fields: $(TYPEDFIELDS) """ -Base.@kwdef mutable struct VariableNodeData{T <: InferenceVariable, P, N} +Base.@kwdef mutable struct VariableState{T <: InferenceVariable, P, N} "DEPRECATED remove in DFG v0.22" variableType::T = T() #tricky deprecation, also change covar to using N and not variableType """ @@ -72,7 +72,7 @@ Base.@kwdef mutable struct VariableNodeData{T <: InferenceVariable, P, N} """ solvedCount::Int = 0 """ - solveKey identifier associated with this VariableNodeData object. + solveKey identifier associated with this VariableState object. """ solveKey::Symbol = :default """ @@ -84,26 +84,26 @@ end ##------------------------------------------------------------------------------ ## Constructors -function VariableNodeData{T}(; kwargs...) where {T <: InferenceVariable} - return VariableNodeData{T, getPointType(T), getDimension(T)}(; kwargs...) +function VariableState{T}(; kwargs...) where {T <: InferenceVariable} + return VariableState{T, getPointType(T), getDimension(T)}(; kwargs...) end -function VariableNodeData(variableType::InferenceVariable; kwargs...) - return VariableNodeData{typeof(variableType)}(; kwargs...) +function VariableState(variableType::InferenceVariable; kwargs...) + return VariableState{typeof(variableType)}(; kwargs...) end ##============================================================================== -## PackedVariableNodeData.jl +## PackedVariableState.jl ##============================================================================== """ $(TYPEDEF) -Packed VariableNodeData structure for serializing DFGVariables. +Packed VariableState structure for serializing DFGVariables. --- Fields: $(TYPEDFIELDS) """ -Base.@kwdef mutable struct PackedVariableNodeData +Base.@kwdef mutable struct PackedVariableState id::Union{UUID, Nothing} # If it's blank it doesn't exist in the DB. vecval::Vector{Float64} dimval::Int @@ -130,9 +130,9 @@ end # createdTimestamp::DateTime#! # lastUpdatedTimestamp::DateTime#! -StructTypes.StructType(::Type{PackedVariableNodeData}) = StructTypes.UnorderedStruct() -StructTypes.idproperty(::Type{PackedVariableNodeData}) = :id -StructTypes.omitempties(::Type{PackedVariableNodeData}) = (:id,) +StructTypes.StructType(::Type{PackedVariableState}) = StructTypes.UnorderedStruct() +StructTypes.idproperty(::Type{PackedVariableState}) = :id +StructTypes.omitempties(::Type{PackedVariableState}) = (:id,) ##============================================================================== ## PointParametricEst @@ -228,7 +228,7 @@ Base.@kwdef struct VariableDFG <: AbstractDFGVariable _version::String = string(_getDFGVersion()) metadata::String = "e30=" solvable::Int = 1 - solverData::Vector{PackedVariableNodeData} = PackedVariableNodeData[] + solverData::Vector{PackedVariableState} = PackedVariableState[] end # maybe add to variable # createdTimestamp::DateTime @@ -304,9 +304,9 @@ Base.@kwdef struct VariableCompute{T <: InferenceVariable, P, N} <: AbstractDFGV ppeDict::Dict{Symbol, AbstractPointParametricEst} = Dict{Symbol, AbstractPointParametricEst}() """Dictionary of solver data. May be a subset of all solutions if a solver label was specified in the get call. - Accessors: [`addVariableSolverData!`](@ref), [`mergeVariableState!`](@ref), and [`deleteVariableSolverData!`](@ref)""" - solverDataDict::Dict{Symbol, VariableNodeData{T, P, N}} = - Dict{Symbol, VariableNodeData{T, P, N}}() + Accessors: [`addVariableState!`](@ref), [`mergeVariableState!`](@ref), and [`deleteVariableState!`](@ref)""" + solverDataDict::Dict{Symbol, VariableState{T, P, N}} = + Dict{Symbol, VariableState{T, P, N}}() """Dictionary of small data associated with this variable. Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)""" smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}() @@ -343,7 +343,7 @@ function VariableCompute(label::Symbol, variableType::InferenceVariable; kwargs. return VariableCompute(label, typeof(variableType); kwargs...) end -function VariableCompute(label::Symbol, solverData::VariableNodeData; kwargs...) +function VariableCompute(label::Symbol, solverData::VariableState; kwargs...) return VariableCompute(; label, solverDataDict = Dict(:default => solverData), diff --git a/src/services/CommonAccessors.jl b/src/services/CommonAccessors.jl index 9b41da99..1f2bf830 100644 --- a/src/services/CommonAccessors.jl +++ b/src/services/CommonAccessors.jl @@ -165,7 +165,7 @@ function getSolveInProgress( end end # Factor - return getState(var).solveInProgress + return getFactorState(var).solveInProgress end #TODO missing set solveInProgress and graph level accessor diff --git a/src/services/CompareUtils.jl b/src/services/CompareUtils.jl index 9ca1b6f9..62ad8349 100644 --- a/src/services/CompareUtils.jl +++ b/src/services/CompareUtils.jl @@ -19,8 +19,8 @@ implement compare if needed. # Generate compares automatically for all in this union const GeneratedCompareUnion = Union{ MeanMaxPPE, - VariableNodeData, - PackedVariableNodeData, + VariableState, + PackedVariableState, VariableCompute, VariableDFG, VariableSummary, @@ -193,8 +193,8 @@ function compareAll( return true end -#Compare VariableNodeData -function compare(a::VariableNodeData, b::VariableNodeData) +#Compare VariableState +function compare(a::VariableState, b::VariableState) a.val != b.val && @debug("val is not equal") == nothing && return false a.bw != b.bw && @debug("bw is not equal") == nothing && return false a.BayesNetOutVertIDs != b.BayesNetOutVertIDs && @@ -253,8 +253,8 @@ function compareVariable( union!(skiplist, skip) TP = TP && compareAll(A.solverDataDict, B.solverDataDict; skip = skiplist, show = show) - Ad = getSolverData(A) - Bd = getSolverData(B) + Ad = getVariableState(A) + Bd = getVariableState(B) # TP = TP && compareAll(A.attributes, B.attributes, skip=[:variableType;], show=show) varskiplist = union(varskiplist, [:variableType]) @@ -298,8 +298,8 @@ function compareFactor( @debug "compareFactor 1/5" TP TP = TP & compareAll( - getState(A), - getState(B); + getFactorState(A), + getFactorState(B); skip = union([:fnc; :_gradients], skip), show = show, ) diff --git a/src/services/CustomPrinting.jl b/src/services/CustomPrinting.jl index c8d1b0a7..da2f5ae1 100644 --- a/src/services/CustomPrinting.jl +++ b/src/services/CustomPrinting.jl @@ -30,8 +30,11 @@ function printVariable( println(ioc, "") catch e end - vnd = - haskey(vert.solverDataDict, :default) ? getSolverData(vert, :default) : nothing + vnd = if haskey(vert.solverDataDict, :default) + getVariableState(vert, :default) + else + nothing + end println(ioc, " ID: ", vert.id) println(ioc, " timestamp: ", vert.timestamp) println(ioc, " nstime: ", vert.nstime) @@ -54,7 +57,7 @@ function printVariable( println(ioc, "(true=", sum(ismarg), ",false=", length(ismarg) - sum(ismarg), ")") if vnd !== nothing - println(ioc, " :default <-- VariableNodeData") + println(ioc, " :default <-- VariableState") println(ioc, " initialized: ", isInitialized(vert, :default)) println(ioc, " marginalized: ", isMarginalized(vert, :default)) println(ioc, " size bel. samples: ", size(vnd.val)) @@ -131,8 +134,8 @@ function printFactor( println(ioc) println(ioc, " solvable: ", vert.solvable) println(ioc, " VariableOrder: ", vert._variableOrderSymbols) - println(ioc, " multihypo: ", getState(vert).multihypo) # FIXME #477 - println(ioc, " nullhypo: ", getState(vert).nullhypo) + println(ioc, " multihypo: ", getFactorState(vert).multihypo) # FIXME #477 + println(ioc, " nullhypo: ", getFactorState(vert).nullhypo) println(ioc, " tags: ", vert.tags) printstyled(ioc, " FactorType: "; bold = true, color = :blue) println(ioc, fctt) @@ -174,7 +177,7 @@ end """ $SIGNATURES -Display the content of `VariableNodeData` to console for a given factor graph and variable tag`::Symbol`. +Display the content of `VariableState` to console for a given factor graph and variable tag`::Symbol`. Dev Notes - TODO split as two show macros between AMP and DFG diff --git a/src/services/DFGFactor.jl b/src/services/DFGFactor.jl index 8120450c..76a0cee0 100644 --- a/src/services/DFGFactor.jl +++ b/src/services/DFGFactor.jl @@ -31,8 +31,6 @@ getFactorType(fct::FactorCompute) = getObservation(fct) getFactorType(f::FactorDFG) = getTypeFromSerializationModule(f.fnctype)() # TODO find a better way to do this that does not rely on empty constructor getFactorType(dfg::AbstractDFG, lbl::Symbol) = getFactorType(getFactor(dfg, lbl)) -getState(f::AbstractDFGFactor) = f.state - """ $SIGNATURES diff --git a/src/services/DFGVariable.jl b/src/services/DFGVariable.jl index bdc071ce..91f164f5 100644 --- a/src/services/DFGVariable.jl +++ b/src/services/DFGVariable.jl @@ -56,10 +56,10 @@ getVariableType """ getVariableType(::VariableCompute{T}) where {T} = T() -getVariableType(::VariableNodeData{T}) where {T} = T() +getVariableType(::VariableState{T}) where {T} = T() # TODO: Confirm that we can switch this out, instead of retrieving the complete variable. -# getVariableType(v::VariableCompute) = getVariableType(getSolverData(v)) +# getVariableType(v::VariableCompute) = getVariableType(getVariableState(v)) # Optimized in CGDFG getVariableType(dfg::AbstractDFG, lbl::Symbol) = getVariableType(getVariable(dfg, lbl)) @@ -217,9 +217,9 @@ Related isSolved, setSolvedCount! """ -getSolvedCount(v::VariableNodeData) = v.solvedCount +getSolvedCount(v::VariableState) = v.solvedCount function getSolvedCount(v::VariableDataLevel2, solveKey::Symbol = :default) - return getSolverData(v, solveKey) |> getSolvedCount + return getVariableState(v, solveKey) |> getSolvedCount end function getSolvedCount(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol = :default) return getSolvedCount(getVariable(dfg, sym), solveKey) @@ -234,9 +234,9 @@ Related getSolved, isSolved """ -setSolvedCount!(v::VariableNodeData, val::Int) = v.solvedCount = val +setSolvedCount!(v::VariableState, val::Int) = v.solvedCount = val function setSolvedCount!(v::VariableDataLevel2, val::Int, solveKey::Symbol = :default) - return setSolvedCount!(getSolverData(v, solveKey), val) + return setSolvedCount!(getVariableState(v, solveKey), val) end function setSolvedCount!( dfg::AbstractDFG, @@ -256,9 +256,9 @@ Related getSolved, setSolved! """ -isSolved(v::VariableNodeData) = 0 < v.solvedCount +isSolved(v::VariableState) = 0 < v.solvedCount function isSolved(v::VariableDataLevel2, solveKey::Symbol = :default) - return getSolverData(v, solveKey) |> isSolved + return getVariableState(v, solveKey) |> isSolved end function isSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol = :default) return isSolved(getVariable(dfg, sym), solveKey) @@ -276,7 +276,7 @@ Notes: - used by both factor graph variable and Bayes tree clique logic. """ function isInitialized(var::VariableCompute, key::Symbol = :default) - data = getSolverData(var, key) + data = getVariableState(var, key) if data === nothing #TODO we still have a mixture of 2 error behaviours # DF, not sure I follow the error here? @@ -296,10 +296,10 @@ end Return `::Bool` on whether this variable has been marginalized. Notes: -- VariableNodeData default `solveKey=:default` +- VariableState default `solveKey=:default` """ function isMarginalized(vert::VariableCompute, solveKey::Symbol = :default) - return getSolverData(vert, solveKey).ismargin + return getVariableState(vert, solveKey).ismargin end function isMarginalized(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol = :default) return isMarginalized(DFG.getVariable(dfg, sym), solveKey) @@ -310,11 +310,11 @@ end Mark a variable as marginalized `true` or `false`. """ -function setMarginalized!(vnd::VariableNodeData, val::Bool) +function setMarginalized!(vnd::VariableState, val::Bool) return vnd.ismargin = val end function setMarginalized!(vari::VariableCompute, val::Bool, solveKey::Symbol = :default) - return setMarginalized!(getSolverData(vari, solveKey), val) + return setMarginalized!(getVariableState(vari, solveKey), val) end function setMarginalized!( dfg::AbstractDFG, @@ -475,7 +475,7 @@ getVariablePPEDict(vari::VariableDataLevel1) = getPPEDict(vari) """ getVariablePPE(::VariableCompute) - getVariablePPE(::VariableNodeData) + getVariablePPE(::VariableState) Get the Parametric Point Estimate of the given variable. """ @@ -498,7 +498,7 @@ getSolverDataDict(v::VariableCompute) = v.solverDataDict Retrieve solver data structure stored in a variable. """ -function getSolverData(v::VariableCompute, key::Symbol = :default) +function getVariableState(v::VariableCompute, key::Symbol = :default) #TODO this does not fit in with some of the other error behaviour. but its used so added @error vnd = if haskey(getSolverDataDict(v), key) getSolverDataDict(v)[key] @@ -513,8 +513,8 @@ end $SIGNATURES Set solver data structure stored in a variable. """ -function setSolverData!(v::VariableCompute, data::VariableNodeData, key::Symbol = :default) - @assert key == data.solveKey "VariableNodeData.solveKey=:$(data.solveKey) does not match requested :$(key)" +function setSolverData!(v::VariableCompute, data::VariableState, key::Symbol = :default) + @assert key == data.solveKey "VariableState.solveKey=:$(data.solveKey) does not match requested :$(key)" return v.solverDataDict[key] = data end @@ -642,7 +642,7 @@ end $(SIGNATURES) Get variable solverdata for a given solve key. """ -function getVariableSolverData( +function getVariableState( dfg::AbstractDFG, variablekey::Symbol, solvekey::Symbol = :default, @@ -653,7 +653,7 @@ function getVariableSolverData( return v.solverDataDict[solvekey] end -function getVariableSolverDataAll(dfg::AbstractDFG, variablekey::Symbol) +function getVariableStates(dfg::AbstractDFG, variablekey::Symbol) v = getVariable(dfg, variablekey) return collect(values(v.solverDataDict)) end @@ -662,14 +662,10 @@ end $(SIGNATURES) Add variable solver data, errors if it already exists. """ -function addVariableSolverData!( - dfg::AbstractDFG, - variablekey::Symbol, - vnd::VariableNodeData, -) +function addVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableState) var = getVariable(dfg, variablekey) if haskey(var.solverDataDict, vnd.solveKey) - error("VariableNodeData '$(vnd.solveKey)' already exists") + error("VariableState '$(vnd.solveKey)' already exists") end var.solverDataDict[vnd.solveKey] = vnd return vnd @@ -680,15 +676,15 @@ end Add a new solver data entry from a deepcopy of the source variable solver data. NOTE: Copies the solver data. """ -function addVariableSolverData!( +function addVariableState!( dfg::AbstractDFG, sourceVariable::VariableCompute, solveKey::Symbol = :default, ) - return addVariableSolverData!( + return addVariableState!( dfg, sourceVariable.label, - deepcopy(getSolverData(sourceVariable, solveKey)), + deepcopy(getVariableState(sourceVariable, solveKey)), ) end @@ -700,11 +696,11 @@ Related mergeVariableStates! """ -function mergeVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableNodeData) +function mergeVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableState) v = getVariable(dfg, variablekey) if !haskey(v.solverDataDict, vnd.solveKey) - addVariableSolverData!(dfg, variablekey, vnd) + addVariableState!(dfg, variablekey, vnd) else v.solverDataDict[vnd.solveKey] = usevnd end @@ -712,6 +708,20 @@ function mergeVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::Variabl return 1 end +function copytoVariableState!( + dfg::AbstractDFG, + variableLabel::Symbol, + stateLabel::Symbol, + state::VariableState, +) + newstate = VariableState(; + (k => getproperty(state, k) for k in fieldnames(VariableState))..., + solveKey = stateLabel, + ) + #TODO deepcopy to make extra sure we don't have any references, should be improved in future. + return mergeVariableState!(dfg, variableLabel, deepcopy(newstate)) +end + """ $SIGNATURES Duplicate a `solveKey`` into a destination from a source. @@ -730,7 +740,7 @@ function cloneSolveKey!( ) # for x in labels - sd = deepcopy(getSolverData(getVariable(src_dfg, x), src)) + sd = deepcopy(getVariableState(getVariable(src_dfg, x), src)) sd.solveKey = dest updateVariableSolverData!(dest_dfg, x, sd, true, Symbol[]; warn_if_absent = verbose) end @@ -750,7 +760,7 @@ end $(SIGNATURES) Delete variable solver data, returns the deleted element. """ -function deleteVariableSolverData!( +function deleteVariableState!( dfg::AbstractDFG, variablekey::Symbol, solveKey::Symbol = :default, @@ -758,7 +768,7 @@ function deleteVariableSolverData!( var = getVariable(dfg, variablekey) if !haskey(var.solverDataDict, solveKey) - throw(KeyError("VariableNodeData '$(solveKey)' does not exist")) + throw(KeyError("VariableState '$(solveKey)' does not exist")) end pop!(var.solverDataDict, solveKey) return 1 @@ -768,12 +778,12 @@ end $(SIGNATURES) Delete variable solver data, returns the deleted element. """ -function deleteVariableSolverData!( +function deleteVariableState!( dfg::AbstractDFG, sourceVariable::VariableCompute, solveKey::Symbol = :default, ) - return deleteVariableSolverData!(dfg, sourceVariable.label, solveKey) + return deleteVariableState!(dfg, sourceVariable.label, solveKey) end ##------------------------------------------------------------------------------ @@ -784,7 +794,7 @@ end $(SIGNATURES) List all the solver data keys in the variable. """ -function listVariableSolverData(dfg::AbstractDFG, variablekey::Symbol) +function listVariableStates(dfg::AbstractDFG, variablekey::Symbol) v = getVariable(dfg, variablekey) return collect(keys(v.solverDataDict)) end @@ -954,7 +964,7 @@ function deletePPE!(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol = :def var = getVariable(dfg, variablekey) if !haskey(var.ppeDict, ppekey) - throw(KeyError("VariableNodeData '$(ppekey)' does not exist")) + throw(KeyError("VariableState '$(ppekey)' does not exist")) end pop!(var.ppeDict, ppekey) return 1 diff --git a/src/services/Serialization.jl b/src/services/Serialization.jl index 65e07d50..93d650ec 100644 --- a/src/services/Serialization.jl +++ b/src/services/Serialization.jl @@ -77,8 +77,8 @@ function getTypeFromSerializationModule(_typeString::AbstractString) return nothing end -# returns a PackedVariableNodeData -function packVariableNodeData(d::VariableNodeData{T}) where {T <: InferenceVariable} +# returns a PackedVariableState +function packVariableState(d::VariableState{T}) where {T <: InferenceVariable} @debug "Dispatching conversion variable -> packed variable for type $(string(getVariableType(d)))" castval = if 0 < length(d.val) precast = getCoordinates.(T, d.val) @@ -93,7 +93,7 @@ function packVariableNodeData(d::VariableNodeData{T}) where {T <: InferenceVaria "Packing of more than one parametric covariance is NOT supported yet, only packing first." ) - return PackedVariableNodeData( + return PackedVariableState( d.id, _val, size(castval, 1), @@ -118,7 +118,7 @@ function packVariableNodeData(d::VariableNodeData{T}) where {T <: InferenceVaria ) end -function unpackVariableNodeData(d::PackedVariableNodeData) +function unpackVariableState(d::PackedVariableState) @debug "Dispatching conversion packed variable -> variable for type $(string(d.variableType))" # Figuring out the variableType # TODO deprecated remove in v0.11 - for backward compatibility for saved variableTypes. @@ -144,7 +144,7 @@ function unpackVariableNodeData(d::PackedVariableNodeData) # N = getDimension(T) - return VariableNodeData{T, getPointType(T), N}(; + return VariableState{T, getPointType(T), N}(; id = d.id, val = vals, bw = BW, @@ -184,7 +184,7 @@ function packVariable( nstime = string(v.nstime.value), tags = collect(v.tags), # Symbol.() ppes = collect(values(v.ppeDict)), - solverData = packVariableNodeData.(collect(values(v.solverDataDict))), + solverData = packVariableState.(collect(values(v.solverDataDict))), metadata = base64encode(JSON3.write(v.smallData)), solvable = v.solvable, variableType = DFG.typeModuleName(DFG.getVariableType(v)), @@ -214,9 +214,9 @@ function unpackVariable(variable::VariableDFG; skipVersionCheck::Bool = false) ppeDict = Dict{Symbol, MeanMaxPPE}(map(p -> p.solveKey, variable.ppes) .=> variable.ppes) - solverDict = Dict{Symbol, VariableNodeData{variableType, pointType}}( + solverDict = Dict{Symbol, VariableState{variableType, pointType}}( map(sd -> sd.solveKey, variable.solverData) .=> - map(sd -> DFG.unpackVariableNodeData(sd), variable.solverData), + map(sd -> DFG.unpackVariableState(sd), variable.solverData), ) dataDict = Dict{Symbol, Blobentry}( map(de -> de.label, variable.blobEntries) .=> variable.blobEntries, diff --git a/test/GraphsDFGSummaryTypes.jl b/test/GraphsDFGSummaryTypes.jl index d668b83f..766ce52e 100644 --- a/test/GraphsDFGSummaryTypes.jl +++ b/test/GraphsDFGSummaryTypes.jl @@ -17,7 +17,7 @@ end function DistributedFactorGraphs.VariableSummary( label::Symbol, - ::VariableNodeData{T}, + ::VariableState{T}, ) where {T} return VariableSummary( nothing, @@ -36,7 +36,7 @@ end function DistributedFactorGraphs.VariableSkeleton( label::Symbol, - ::VariableNodeData{T}, + ::VariableState{T}, ) where {T} return VariableSkeleton(nothing, label, Set{Symbol}()) end diff --git a/test/compareTests.jl b/test/compareTests.jl index a1ebf7d6..02cc6117 100644 --- a/test/compareTests.jl +++ b/test/compareTests.jl @@ -7,10 +7,10 @@ using Dates # TestCCW1 ## Generated compare functions -# VariableNodeData -vnd1 = VariableNodeData(TestVariableType1()) +# VariableState +vnd1 = VariableState(TestVariableType1()) vnd2 = deepcopy(vnd1) -vnd3 = VariableNodeData(TestVariableType2()) +vnd3 = VariableState(TestVariableType2()) @test vnd1 == vnd2 push!(vnd1.val, [1.0;]) @@ -59,9 +59,9 @@ f3 = FactorCompute(:f1, [:b, :a], TestFunctorInferenceType1()) @test !(f1 == f3) ## Compare functions -vnd1 = VariableNodeData(TestVariableType1()) +vnd1 = VariableState(TestVariableType1()) vnd2 = deepcopy(vnd1) -vnd3 = VariableNodeData(TestVariableType2()) +vnd3 = VariableState(TestVariableType2()) @test compare(vnd1, vnd2) @test !compare(vnd1, vnd3) diff --git a/test/fileDFGTests.jl b/test/fileDFGTests.jl index 7ecef346..fb1f06d7 100644 --- a/test/fileDFGTests.jl +++ b/test/fileDFGTests.jl @@ -19,7 +19,7 @@ using UUIDs 1:numNodes, ) map(v -> setSolvable!(v, Int(round(rand()))), verts) - map(v -> getSolverData(verts[4]).solveInProgress = Int(round(rand())), verts) + map(v -> getVariableState(verts[4]).solveInProgress = Int(round(rand())), verts) map(v -> setSolvedCount!(v, Int(round(10 * rand()))), verts) # Add some data entries @@ -80,8 +80,8 @@ using UUIDs 1:(numNodes - 1), ) map(f -> setSolvable!(f, Int(round(rand()))), facts) - map(f -> DFG.getState(f).eliminated = rand() > 0.5, facts) - map(f -> DFG.getState(f).potentialused = rand() > 0.5, facts) + map(f -> DFG.getFactorState(f).eliminated = rand() > 0.5, facts) + map(f -> DFG.getFactorState(f).potentialused = rand() > 0.5, facts) mergeFactor!.(dfg, facts) #test multihypo diff --git a/test/iifInterfaceTests.jl b/test/iifInterfaceTests.jl index 2ac66208..39830652 100644 --- a/test/iifInterfaceTests.jl +++ b/test/iifInterfaceTests.jl @@ -187,9 +187,9 @@ end @test getTimestamp(v1) == v1.timestamp @test getVariablePPEDict(v1) == v1.ppeDict @test_throws Exception DistributedFactorGraphs.getVariablePPE(v1, :notfound) - @test getSolverData(v1) === v1.solverDataDict[:default] - @test getSolverData(v1) === v1.solverDataDict[:default] - @test getSolverData(v1, :default) === v1.solverDataDict[:default] + @test getVariableState(v1) === v1.solverDataDict[:default] + @test getVariableState(v1) === v1.solverDataDict[:default] + @test getVariableState(v1, :default) === v1.solverDataDict[:default] @test getSolverDataDict(v1) == v1.solverDataDict # legacy compat test @test getVariablePPEDict(v1) == v1.ppeDict # changed to .ppeDict -- delete by DFG v0.7 @@ -200,7 +200,7 @@ end @test getLabel(f1) == f1.label @test getTags(f1) == f1.tags - @test getState(f1) === f1.state + @test getFactorState(f1) === f1.state @test getObservation(f1) === f1.observation @test getSolverParams(dfg) !== nothing @@ -395,7 +395,7 @@ verts = map(n -> addVariable!(dfg, Symbol("x$n"), Position{1}; tags = [:POSE]), #TODO fix this to use accessors setSolvable!(verts[7], 1) setSolvable!(verts[8], 0) -getSolverData(verts[8]).solveInProgress = 1 +getVariableState(verts[8]).solveInProgress = 1 #call update to set it on cloud mergeVariable!(dfg, verts[7]) mergeVariable!(dfg, verts[8]) diff --git a/test/testBlocks.jl b/test/testBlocks.jl index 4b2e7cf8..df7c71a5 100644 --- a/test/testBlocks.jl +++ b/test/testBlocks.jl @@ -297,16 +297,16 @@ function DFGVariableSCA() TestVariableType1(); tags = v1_tags, solvable = 0, - solverDataDict = Dict(:default => VariableNodeData{TestVariableType1}()), + solverDataDict = Dict(:default => VariableState{TestVariableType1}()), ) v2 = VariableCompute( :b, - VariableNodeData{TestVariableType2}(); + VariableState{TestVariableType2}(); tags = Set([:VARIABLE, :LANDMARK]), ) v3 = VariableCompute( :c, - VariableNodeData{TestVariableType2}(); + VariableState{TestVariableType2}(); timestamp = ZonedDateTime("2020-08-11T00:12:03.000-05:00"), ) @@ -315,7 +315,7 @@ function DFGVariableSCA() TestVariableType1(); tags = v1_tags, solvable = 0, - solverDataDict = Dict(:default => VariableNodeData{TestVariableType1}()), + solverDataDict = Dict(:default => VariableState{TestVariableType1}()), ) # v1.solverDataDict[:default].val[1] = [0.0;] @@ -325,7 +325,7 @@ function DFGVariableSCA() # v3.solverDataDict[:default].val[1] = [0.0;0.0] # v3.solverDataDict[:default].bw[1] = [1.0;1.0] - getSolverData(v1).solveInProgress = 1 + getVariableState(v1).solveInProgress = 1 @test getLabel(v1) == v1_lbl @test getTags(v1) == v1_tags @@ -372,7 +372,7 @@ function DFGVariableSCA() # #TODO sort out # getPPEs - # getSolverData + # getVariableState # setSolverData # getVariablePPEs # getVariablePPE @@ -418,7 +418,7 @@ function DFGFactorSCA() @test getVariableOrder(f1) == [:a, :b] - getState(f1).solveInProgress = 1 + getFactorState(f1).solveInProgress = 1 @test setSolvable!(f1, 1) == 1 #TODO These 2 function are equivelent @@ -760,50 +760,46 @@ function VSDTestBlock!(fg, v1) # "Variable Solver Data" # #### Variable Solver Data # **CRUD** - # - `getVariableSolverData` - # - `addVariableSolverData!` + # - `getVariableState` + # - `addVariableState!` # - `updateVariableSolverData!` - # - `deleteVariableSolverData!` + # - `deleteVariableState!` # - # > - `getVariableSolverDataAll` #TODO Data is already plural so maybe Variables, All or Dict, or use Datum for singular + # > - `getVariableStates` #TODO Data is already plural so maybe Variables, All or Dict, or use Datum for singular # > - `getVariablesSolverData` # # **Set like** - # - `listVariableSolverData` + # - `listVariableStates` # # > - `emptyVariableSolverData!` #TODO ? # > - `mergeVariableSolverData!` #TODO ? # - # **VariableNodeData** + # **VariableState** # - `getSolveInProgress` - vnd = VariableNodeData{TestVariableType1}(; solveKey = :parametric) + vnd = VariableState{TestVariableType1}(; solveKey = :parametric) # vnd.val[1] = [0.0;] # vnd.bw[1] = [1.0;] - @test addVariableSolverData!(fg, :a, vnd) == vnd + @test addVariableState!(fg, :a, vnd) == vnd - @test_throws ErrorException addVariableSolverData!(fg, :a, vnd) + @test_throws ErrorException addVariableState!(fg, :a, vnd) - @test issetequal(listVariableSolverData(fg, :a), [:default, :parametric]) + @test issetequal(listVariableStates(fg, :a), [:default, :parametric]) # Get the data back - note that this is a reference to above. - vndBack = getVariableSolverData(fg, :a, :parametric) + vndBack = getVariableState(fg, :a, :parametric) @test vndBack == vnd # Delete it - @test deleteVariableSolverData!(fg, :a, :parametric) == 1 + @test deleteVariableState!(fg, :a, :parametric) == 1 # Update add it @test mergeVariableState!(fg, :a, vnd) == 1 - # Update update it - @test updateVariableSolverData!(fg, :a, vnd) == vnd - # test without deepcopy - @test updateVariableSolverData!(fg, :a, vnd, false) == vnd # Bulk copy update x0 @test updateVariableSolverData!(fg, [v1], :default) == nothing altVnd = vnd |> deepcopy - keepVnd = getSolverData(getVariable(fg, :a), :parametric) |> deepcopy + keepVnd = getVariableState(getVariable(fg, :a), :parametric) |> deepcopy altVnd.infoPerCoord .= [-99.0;] retVnd = updateVariableSolverData!(fg, :a, altVnd, false, [:infoPerCoord;]) @test retVnd == altVnd @@ -817,32 +813,32 @@ function VSDTestBlock!(fg, v1) # restore without copy @test updateVariableSolverData!(fg, :a, keepVnd, false, [:infoPerCoord; :bw]) == vnd - @test getSolverData(getVariable(fg, :a), :parametric).infoPerCoord[1] != + @test getVariableState(getVariable(fg, :a), :parametric).infoPerCoord[1] != altVnd.infoPerCoord[1] - @test getSolverData(getVariable(fg, :a), :parametric).bw != altVnd.bw + @test getVariableState(getVariable(fg, :a), :parametric).bw != altVnd.bw # Delete parametric from v1 - @test deleteVariableSolverData!(fg, :a, :parametric) == 1 + @test deleteVariableState!(fg, :a, :parametric) == 1 - @test_throws KeyError getVariableSolverData(fg, :a, :parametric) + @test_throws KeyError getVariableState(fg, :a, :parametric) #FIXME copied from lower - @test getSolverData(v1) === v1.solverDataDict[:default] + @test getVariableState(v1) === v1.solverDataDict[:default] # Add new VND of type ContinuousScalar to :x0 - # Could also do VariableNodeData(ContinuousScalar()) + # Could also do VariableState(ContinuousScalar()) - vnd = VariableNodeData{TestVariableType1}(; solveKey = :parametric) + vnd = VariableState{TestVariableType1}(; solveKey = :parametric) # vnd.val[1] = [0.0;] # vnd.bw[1] = [1.0;] - addVariableSolverData!(fg, :a, vnd) - @test setdiff(listVariableSolverData(fg, :a), [:default, :parametric]) == [] + addVariableState!(fg, :a, vnd) + @test setdiff(listVariableStates(fg, :a), [:default, :parametric]) == [] # Get the data back - note that this is a reference to above. - vndBack = getVariableSolverData(fg, :a, :parametric) + vndBack = getVariableState(fg, :a, :parametric) @test vndBack == vnd # Delete it - @test deleteVariableSolverData!(fg, :a, :parametric) == 1 + @test deleteVariableState!(fg, :a, :parametric) == 1 # Update add it updateVariableSolverData!(fg, :a, vnd) # Update update it @@ -850,7 +846,7 @@ function VSDTestBlock!(fg, v1) # Bulk copy update x0 updateVariableSolverData!(fg, [v1], :default) # Delete parametric from v1 - deleteVariableSolverData!(fg, :a, :parametric) + deleteVariableState!(fg, :a, :parametric) return nothing #TODO @@ -1426,14 +1422,11 @@ function connectivityTestGraph( vars = vcat( map( - n -> VARTYPE(Symbol("x$n"), VariableNodeData{TestVariableType1}()), + n -> VARTYPE(Symbol("x$n"), VariableState{TestVariableType1}()), 1:numNodesType1, ), map( - n -> VARTYPE( - Symbol("x$(numNodesType1+n)"), - VariableNodeData{TestVariableType2}(), - ), + n -> VARTYPE(Symbol("x$(numNodesType1+n)"), VariableState{TestVariableType2}()), 1:numNodesType2, ), ) @@ -1667,10 +1660,10 @@ function ProducingDotFiles( dotdfg = testDFGAPI(; userLabel = "test@navability.io") if v1 === nothing - v1 = VARTYPE(:a, VariableNodeData{TestVariableType1}()) + v1 = VARTYPE(:a, VariableState{TestVariableType1}()) end if v2 === nothing - v2 = VARTYPE(:b, VariableNodeData{TestVariableType1}()) + v2 = VARTYPE(:b, VariableState{TestVariableType1}()) end if f1 === nothing if (FACTYPE == FactorCompute) @@ -1821,7 +1814,7 @@ function FileDFGTestBlock(testDFGAPI; kwargs...) for filename in ["/tmp/fileDFG", "/tmp/FileDFGExtension.tar.gz"] v4 = getVariable(dfg, :x4) - vnd = getSolverData(v4) + vnd = getVariableState(v4) # set everything vnd.BayesNetVertID = :outid push!(vnd.BayesNetOutVertIDs, :id) @@ -1841,7 +1834,7 @@ function FileDFGTestBlock(testDFGAPI; kwargs...) mergeVariable!(dfg, v4) f45 = getFactor(dfg, :x4x5f1) - fsd = getState(f45) + fsd = getFactorState(f45) # set some factor solver data push!(fsd.certainhypo, 2) fsd.eliminated = true