Skip to content

Rename IIF abstract types #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
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
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Listing news on any major breaking changes in DFG. For regular changes, see integrated Github.com project milestones for DFG.
# v0.28
- Reading or deserialzing of factor graphs created prior to v0.25 are no longer suppoted with the complete removal of User/Robot/Session
- Deprecated AbstractRelativeMinimize and AbstractManifoldsMinimize

#TODO pending:
- AbstractPrior -> AbstractPriorObservation/PriorObservation
- AbstractRelative -> RelativeObservation/RelativeObservation
- InferenceType -> AbstractPackedFactorObservation
- InferenceVariable -> [Abstract]VariableStateType/AbstractVarstateType
- PackedSamplableBelief -> [Abstract]PackedBelief

# v0.27
- `delete` returns number of nodes deleted and no longer the object that was deleted.
Expand Down
26 changes: 24 additions & 2 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## ================================================================================
## Deprecated in v0.28
##=================================================================================
export AbstractRelativeMinimize,
AbstractManifoldMinimize,
AbstractPrior,
AbstractRelative,
InferenceVariable,
InferenceType,
PackedSamplableBelief

const AbstractPrior = PriorObservation
const AbstractRelative = RelativeObservation

abstract type AbstractRelativeMinimize <: RelativeObservation end
abstract type AbstractManifoldMinimize <: RelativeObservation end

const InferenceVariable = VariableStateType{Any}
const InferenceType = AbstractPackedFactorObservation

const PackedSamplableBelief = PackedBelief

## ================================================================================
## Deprecated in v0.27
##=================================================================================
Expand Down Expand Up @@ -430,15 +452,15 @@ function getFactorOperationalMemoryType(dfg::AbstractDFG)
return getFactorOperationalMemoryType(getSolverParams(dfg))
end

function typeModuleName(variableType::InferenceVariable)
function typeModuleName(variableType::VariableStateType)
Base.depwarn("typeModuleName is obsolete", :typeModuleName)
io = IOBuffer()
ioc = IOContext(io, :module => DistributedFactorGraphs)
show(ioc, typeof(variableType))
return String(take!(io))
end

typeModuleName(varT::Type{<:InferenceVariable}) = typeModuleName(varT())
typeModuleName(varT::Type{<:VariableStateType}) = typeModuleName(varT())

## ================================================================================
## Deprecated in v0.25
Expand Down
4 changes: 2 additions & 2 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export listTags, mergeTags!, removeTags!, emptyTags!
# Variable
##------------------------------------------------------------------------------
# Abstract Variable Data
export InferenceVariable
export VariableStateType

# accessors
export getSolverDataDict, setSolverData!
Expand Down Expand Up @@ -257,7 +257,7 @@ export @format_str # exported from FileIO
##------------------------------------------------------------------------------
# Factor Data
export AbstractFactorObservation, AbstractPackedFactorObservation
export AbstractPrior, AbstractRelative, AbstractRelativeMinimize, AbstractManifoldMinimize
export PriorObservation, RelativeObservation
export FactorSolverCache

# accessors
Expand Down
18 changes: 3 additions & 15 deletions src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
abstract type AbstractPackedFactorObservation end
abstract type AbstractFactorObservation end

abstract type AbstractPrior <: AbstractFactorObservation end
abstract type AbstractRelative <: AbstractFactorObservation end
abstract type AbstractRelativeMinimize <: AbstractRelative end
abstract type AbstractManifoldMinimize <: AbstractRelative end

abstract type PriorObservation <: AbstractFactorObservation end
abstract type RelativeObservation <: AbstractFactorObservation end
abstract type PackedObservation <: AbstractFactorObservation end
# NOTE DF, Convolution is IIF idea, but DFG should know about "FactorSolverCache"
# DF, IIF.CommonConvWrapper <: FactorSolverCache #
# NOTE was `<: Function` as unnecessary
Expand Down Expand Up @@ -129,16 +127,6 @@ end

FactorDFG(f::FactorDFG) = f

# TODO consolidate to just one type
"""
$(TYPEDEF)
Abstract parent type for all InferenceTypes, which are the
observation functions inside of factors.
"""
abstract type InferenceType <: AbstractPackedFactorObservation end

#TODO deprecate InferenceType in favor of AbstractPackedFactorObservation v0.26

# Packed Factor constructor
function assembleFactorName(xisyms::Union{Vector{String}, Vector{Symbol}})
return Symbol(xisyms..., "_f", randstring(4))
Expand Down
14 changes: 7 additions & 7 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Abstract Types
##==============================================================================

abstract type InferenceVariable end
abstract type VariableStateType{N} end

##==============================================================================
## VariableState
Expand All @@ -19,7 +19,7 @@ N: Manifold dimension.
Fields:
$(TYPEDFIELDS)
"""
Base.@kwdef mutable struct VariableState{T <: InferenceVariable, P, N}
Base.@kwdef mutable struct VariableState{T <: VariableStateType, P, N}
"""
Globally unique identifier.
"""
Expand Down Expand Up @@ -82,10 +82,10 @@ end

##------------------------------------------------------------------------------
## Constructors
function VariableState{T}(; kwargs...) where {T <: InferenceVariable}
function VariableState{T}(; kwargs...) where {T <: VariableStateType}
return VariableState{T, getPointType(T), getDimension(T)}(; kwargs...)
end
function VariableState(variableType::InferenceVariable; kwargs...)
function VariableState(variableType::VariableStateType; kwargs...)
return VariableState{typeof(variableType)}(; kwargs...)
end

Expand Down Expand Up @@ -283,7 +283,7 @@ Complete variable structure for a DistributedFactorGraph variable.
Fields:
$(TYPEDFIELDS)
"""
Base.@kwdef struct VariableCompute{T <: InferenceVariable, P, N} <: AbstractDFGVariable
Base.@kwdef struct VariableCompute{T <: VariableStateType, P, N} <: AbstractDFGVariable
"""The ID for the variable"""
id::Union{UUID, Nothing} = nothing
"""Variable label, e.g. :x1.
Expand Down Expand Up @@ -325,7 +325,7 @@ The default VariableCompute constructor.
"""
function VariableCompute(
label::Symbol,
T::Type{<:InferenceVariable};
T::Type{<:VariableStateType};
timestamp::ZonedDateTime = now(localzone()),
solvable::Union{Int, Base.RefValue{Int}} = Ref(1),
kwargs...,
Expand All @@ -337,7 +337,7 @@ function VariableCompute(
return VariableCompute{T, P, N}(; label, timestamp, solvable, kwargs...)
end

function VariableCompute(label::Symbol, variableType::InferenceVariable; kwargs...)
function VariableCompute(label::Symbol, variableType::VariableStateType; kwargs...)
return VariableCompute(label, typeof(variableType); kwargs...)
end

Expand Down
6 changes: 3 additions & 3 deletions src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ end
# to be consolidated, see #612
function listVariables(
dfg::AbstractDFG,
typeFilter::Type{<:InferenceVariable};
typeFilter::Type{<:VariableStateType};
tags::Vector{Symbol} = Symbol[],
solvable::Int = 0,
)
Expand Down Expand Up @@ -667,7 +667,7 @@ end

function listSolveKeys(
dfg::AbstractDFG,
filterVariables::Union{Type{<:InferenceVariable}, Regex, Nothing} = nothing;
filterVariables::Union{Type{<:VariableStateType}, Regex, Nothing} = nothing;
filterSolveKeys::Union{Regex, Nothing} = nothing,
tags::Vector{Symbol} = Symbol[],
solvable::Int = 0,
Expand Down Expand Up @@ -747,7 +747,7 @@ end
## list by types
##--------------

function ls(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: InferenceVariable}
function ls(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: VariableStateType}
xx = getVariables(dfg)
mask = getVariableType.(xx) .|> typeof .== T
vxx = view(xx, mask)
Expand Down
4 changes: 2 additions & 2 deletions src/services/CompareUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Base.==
# Reference https://github.com/JuliaLang/julia/issues/4648

#=
For now abstract `InferenceVariable`s are considered equal if they are the same type, dims, and manifolds (abels are deprecated)
For now abstract `VariableStateType`s are considered equal if they are the same type, dims, and manifolds (abels are deprecated)
If your implentation has aditional properties such as `DynPose2` with `ut::Int64` (microsecond time) or support different manifolds
implement compare if needed.
=#
# ==(a::InferenceVariable,b::InferenceVariable) = typeof(a) == typeof(b) && a.dims == b.dims && a.manifolds == b.manifolds
# ==(a::VariableStateType,b::VariableStateType) = typeof(a) == typeof(b) && a.dims == b.dims && a.manifolds == b.manifolds

==(a::FactorSolverCache, b::FactorSolverCache) = typeof(a) == typeof(b)

Expand Down
28 changes: 14 additions & 14 deletions src/services/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,61 +102,61 @@ using RoME
@assert RoME.PriorPose2 == DFG._getPriorType(Pose2)
```
"""
function _getPriorType(_type::Type{<:InferenceVariable})
function _getPriorType(_type::Type{<:VariableStateType})
return getfield(_type.name.module, Symbol(:Prior, _type.name.name))
end

##==============================================================================
## Default Factors Function Macro
##==============================================================================
export PackedSamplableBelief
export PackedBelief

function pack end
function unpack end
function packDistribution end
function unpackDistribution end

abstract type PackedSamplableBelief end
StructTypes.StructType(::Type{<:PackedSamplableBelief}) = StructTypes.UnorderedStruct()
abstract type PackedBelief end
StructTypes.StructType(::Type{<:PackedBelief}) = StructTypes.UnorderedStruct()

#TODO remove, rather use StructTypes.jl properly
function Base.convert(::Type{<:PackedSamplableBelief}, nt::Union{NamedTuple, JSON3.Object})
function Base.convert(::Type{<:PackedBelief}, nt::Union{NamedTuple, JSON3.Object})
distrType = getTypeFromSerializationModule(nt._type)
return distrType(; nt...)
end

"""
@defFactorType StructName factortype<:AbstractFactorObservation manifolds<:AbstractManifold
@defObservationType StructName factortype<:AbstractFactorObservation manifolds<:AbstractManifold

A macro to create a new factor function with name `StructName` and manifold. Note that
the `manifold` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).

Example:
```
DFG.@defFactorType Pose2Pose2 AbstractManifoldMinimize SpecialEuclidean(2)
DFG.@defObservationType Pose2Pose2 RelativeObservation SpecialEuclidean(2)
```
"""
macro defFactorType(structname, factortype, manifold)
macro defObservationType(structname, factortype, manifold)
packedstructname = Symbol("Packed", structname)
return esc(
quote
# user manifold must be a <:Manifold
@assert ($manifold isa AbstractManifold) "@defFactorType manifold (" *
@assert ($manifold isa AbstractManifold) "@defObservationType manifold (" *
string($manifold) *
") is not an `AbstractManifold`"

@assert ($factortype <: AbstractFactorObservation) "@defFactorType factortype (" *
@assert ($factortype <: AbstractFactorObservation) "@defObservationType factortype (" *
string($factortype) *
") is not an `AbstractFactorObservation`"

Base.@__doc__ struct $structname{T} <: $factortype
Z::T
end

#TODO should this be $packedstructname{T <: PackedSamplableBelief}
#TODO should this be $packedstructname{T <: PackedBelief}
Base.@__doc__ struct $packedstructname <: AbstractPackedFactorObservation
Z::PackedSamplableBelief
Z::PackedBelief
end

# $structname(; Z) = $structname(Z)
Expand Down Expand Up @@ -275,11 +275,11 @@ function isPrior(dfg::AbstractDFG, fc::Symbol)
return isPrior(getFactorType(fco))
end

function isPrior(::AbstractPrior)
function isPrior(::PriorObservation)
return true
end

function isPrior(::AbstractRelative)
function isPrior(::RelativeObservation)
return false
end

Expand Down
Loading
Loading