Skip to content

Splitting out IIFTypes as a separate module. #1872

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 3 commits into from
Jun 29, 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
132 changes: 33 additions & 99 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:

jobs:
test-stable:
name: JL${{ matrix.version }} - ${{ matrix.arch }} - ${{ matrix.group }} - ${{ matrix.os }}
name: Stable JL-${{ matrix.version }} - ${{ matrix.group }}
runs-on: ${{ matrix.os }}
env:
JULIA_PKG_SERVER: ""
strategy:
fail-fast: false
matrix:
version:
- '1.11'
- 'lts'
os:
- ubuntu-latest
arch:
Expand All @@ -26,26 +26,33 @@ jobs:
- 'basic_functional_group'
- 'test_cases_group'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
continue-on-error: ${{ matrix.version == 'nightly' }}
- name: Dev dependencies
shell: julia --project=monorepo {0}
run: |
using Pkg;
Pkg.develop([PackageSpec(path="IncrementalInference"), PackageSpec(path="IncrementalInferenceTypes")]);
- name: Run tests
continue-on-error: ${{ matrix.group == 'tmp_debug_group' }}
env:
IIF_TEST_GROUP: ${{ matrix.group }}
run: >
julia --color=yes --project=monorepo -e 'using Pkg; Pkg.test("IncrementalInference")'
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
files: lcov.info
fail_ci_if_error: false
if: ${{ matrix.version != 'nightly' }}

upstream-dev-functional:
name: Upstr Dev Functional
upstream-dev:
name: Develop JL-${{ matrix.version }} - ${{ matrix.group }}
runs-on: ubuntu-latest
env:
JULIA_PKG_SERVER: ""
Expand All @@ -55,105 +62,32 @@ jobs:
arch:
- x64
version:
- '~1.12.0-0'
- '1'
group:
- 'basic_functional_group'
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- run: |
git config --global user.name Tester
git config --global user.email te@st.er
- name: Upst Dev Functional
env:
IIF_TEST_GROUP: ${{ matrix.group }}
run: |
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="ApproxManifoldProducts",rev="develop"));'
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="DistributedFactorGraphs",rev="develop"));'
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.test("IncrementalInference"; coverage=false)'
shell: bash

upstream-dev-cases:
name: Upstr Dev Test Cases
runs-on: ubuntu-latest
env:
JULIA_PKG_SERVER: ""
strategy:
fail-fast: false
matrix:
arch:
- x64
version:
- '~1.12.0-0'
group:
- 'test_cases_group'
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- run: |
git config --global user.name Tester
git config --global user.email te@st.er
- name: Upstr Dev Cases
env:
IIF_TEST_GROUP: ${{ matrix.group }}
run: |
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="ApproxManifoldProducts",rev="develop"));'
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="DistributedFactorGraphs",rev="develop"));'
julia --project=@. --check-bounds=yes -e 'using Pkg; Pkg.test("IncrementalInference"; coverage=false)'
shell: bash

test-debug-group:
needs: [ upstream-dev-functional ]
name: JL${{ matrix.version }} - ${{ matrix.group }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
JULIA_PKG_SERVER: ""
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
version:
- '~1.12.0-0'
arch:
- x64
group:
- 'tmp_debug_group'
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/cache@v2
# - run: |
# git config --global user.name Tester
# git config --global user.email te@st.er
- name: Dev dependencies
shell: julia --project=monorepo {0}
run: |
using Pkg;
Pkg.add(PackageSpec(name="DistributedFactorGraphs",rev="develop"))
Pkg.add(PackageSpec(name="ApproxManifoldProducts",rev="develop"));
Pkg.develop([PackageSpec(path="IncrementalInference"), PackageSpec(path="IncrementalInferenceTypes")]);
- name: Run tests
continue-on-error: ${{ matrix.group == 'tmp_debug_group' }}
env:
IIF_TEST_GROUP: ${{ matrix.group }}
run: >
julia --color=yes --project=monorepo -e 'using Pkg; Pkg.test("IncrementalInference")'

1 change: 1 addition & 0 deletions Project.toml → IncrementalInference/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
FunctionalStateMachine = "3e9e306e-7e3c-11e9-12d2-8f8f67a2f951"
IncrementalInferenceTypes = "9808408f-4dbc-47e4-913c-6068b950e289"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
KernelDensityEstimate = "2472808a-b354-52ea-a80e-1658a3c6056d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions IncrementalInference/src/Factors/Circular.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ---------------------------------------------
# CircularCircular
# ---------------------------------------------

function (cf::CalcFactor{<:CircularCircular})(X, p, q)
M = getManifold(cf)
return distanceTangent2Point(M, X, p, q)
end

function getSample(cf::CalcFactor{<:CircularCircular})
# FIXME workaround for issue with manifolds CircularGroup,
return [rand(cf.factor.Z)]
end

function Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{CircularCircular})
return Manifolds.RealCircleGroup()
end

IIFTypes.CircularCircular(::UniformScaling) = CircularCircular(Normal())

# ---------------------------------------------
# PriorCircular
# ---------------------------------------------

IIFTypes.PriorCircular(::UniformScaling) = PriorCircular(Normal())

function getSample(cf::CalcFactor{<:PriorCircular})
# FIXME workaround for issue #TBD with manifolds CircularGroup,
# JuliaManifolds/Manifolds.jl#415
# no method similar(::Float64, ::Type{Float64})
return samplePoint(cf.manifold, cf.factor.Z, [0.0])
# return [Manifolds.sym_rem(rand(cf.factor.Z))]
end

function (cf::CalcFactor{<:PriorCircular})(m, p)
M = getManifold(cf)
Xc = vee(M, p, log(M, p, m))
return Xc
end

function Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{PriorCircular})
return Manifolds.RealCircleGroup()
end

# --------------------------------------------
7 changes: 7 additions & 0 deletions IncrementalInference/src/Factors/DefaultPrior.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

IIFTypes.Prior(::UniformScaling) = Prior(Normal())

# getSample(cf::CalcFactor{<:Prior}) = rand(cf.factor.Z)

# basic default
(s::CalcFactor{<:Prior})(z, x1) = z .- x1
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ function DFG.unpack(d::PackedLinearRelative)
return LinearRelative(DFG.unpackDistribution(d.Z))
end

#
#
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const BeliefArray{T} = Union{<:AbstractMatrix{<:T}, <:Adjoint{<:T, AbstractMatri
# FIXME, remove this and let the user do either import or const definitions
export KDE, AMP, DFG, FSM, IIF

# include("../IncrementalInferenceTypes/src/IncrementalInferenceTypes.jl")
@reexport using IncrementalInferenceTypes

# TODO temporary for initial version of on-manifold products
KDE.setForceEvalDirect!(true)

Expand All @@ -116,7 +119,6 @@ include("ExportAPI.jl")


# regular
include("entities/SolverParams.jl")

include("entities/HypoRecipe.jl")
include("entities/CalcFactor.jl")
Expand Down Expand Up @@ -173,7 +175,6 @@ include("services/TreeBasedInitialization.jl")

# included variables of IIF, easy to extend in user's context
include("Variables/DefaultVariables.jl")
include("Variables/Circular.jl")

# included factors, see RoME.jl for more examples
include("Factors/GenericFunctions.jl")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# TODO, add `<:` for concrete dispatch when using StringThemSamplableBeliefs
StringThemSamplableBeliefs = Union{
<:Uniform,
<:Normal,
<:MvNormal,
<:ZeroMeanDiagNormal,
<:Categorical,
<:DiscreteNonParametric,
<:Rayleigh,
<:BallTreeDensity,
<:ManifoldKernelDensity,
<:AliasingScalarSampler,
<:HeatmapGridDensity,
<:LevelSetGridNormal,
}

## TODO, TBD
# Base.@kwdef struct PackedDiscreteNonParametric <: PackedSamplableBelief
# _type::String = "IncrementalInference.PackedDiscreteNonParametric"
# end
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function parchDistribution(mkd::ManifoldKernelDensity)
end

# Data converters for MKD
function packDistribution(mkd::ManifoldKernelDensity)
function DFG.packDistribution(mkd::ManifoldKernelDensity)
#
pts = getPoints(mkd)

Expand All @@ -58,7 +58,7 @@ function packDistribution(mkd::ManifoldKernelDensity)
)
end

function unpackDistribution(dtr::PackedManifoldKernelDensity)
function DFG.unpackDistribution(dtr::PackedManifoldKernelDensity)
# find InferenceVariable type from string (anything Manifolds.jl?)
M = DFG.getTypeFromSerializationModule(dtr.varType) |> getManifold
vecP = [AMP.makePointFromCoords(M, pt) for pt in dtr.pts]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@

## Distributions to JSON/Packed types

packDistribution(dtr::Categorical) = PackedCategorical(; p = dtr.p)
packDistribution(dtr::Uniform) = PackedUniform(; a = dtr.a, b = dtr.b)
packDistribution(dtr::Normal) = PackedNormal(; mu = dtr.μ, sigma = dtr.σ)
packDistribution(dtr::ZeroMeanDiagNormal) = PackedZeroMeanDiagNormal(; diag = dtr.Σ.diag)
packDistribution(dtr::ZeroMeanFullNormal) = PackedZeroMeanFullNormal(; cov = dtr.Σ.mat[:])
packDistribution(dtr::DiagNormal) = PackedDiagNormal(; mu = dtr.μ, diag = dtr.Σ.diag)
packDistribution(dtr::FullNormal) = PackedFullNormal(; mu = dtr.μ, cov = dtr.Σ.mat[:])
packDistribution(dtr::Rayleigh) = PackedRayleigh(; sigma = dtr.σ)

function packDistribution(dtr::AliasingScalarSampler)
return PackedAliasingScalarSampler(; domain = dtr.domain, weights = dtr.weights.values)
end


## Unpack JSON/Packed to Distribution types

unpackDistribution(dtr::PackedCategorical) = Categorical(dtr.p ./ sum(dtr.p))
unpackDistribution(dtr::PackedUniform) = Uniform(dtr.a, dtr.b)
unpackDistribution(dtr::PackedNormal) = Normal(dtr.mu, dtr.sigma)
function unpackDistribution(dtr::PackedZeroMeanDiagNormal)
return MvNormal(LinearAlgebra.Diagonal(map(abs2, sqrt.(dtr.diag))))
end # sqrt.(dtr.diag)
function unpackDistribution(dtr::PackedZeroMeanFullNormal)
d = round(Int,sqrt(size(dtr.cov)[1]))
return MvNormal(reshape(dtr.cov, d, d))
end
unpackDistribution(dtr::PackedDiagNormal) = MvNormal(dtr.mu, sqrt.(dtr.diag))
function unpackDistribution(dtr::PackedFullNormal)
return MvNormal(dtr.mu, reshape(dtr.cov, length(dtr.mu), :))
end
unpackDistribution(dtr::PackedRayleigh) = Rayleigh(dtr.sigma)

function unpackDistribution(dtr::PackedAliasingScalarSampler)
return AliasingScalarSampler(dtr.domain, dtr.weights ./ sum(dtr.weights))
end


# ## strip field from NamedTuple

# function _delete( nt::Union{<:NamedTuple, <:Dict{K,T}},
Expand Down
6 changes: 6 additions & 0 deletions IncrementalInference/src/Variables/DefaultVariables.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function Base.convert(
::Type{<:ManifoldsBase.AbstractManifold},
::InstanceType{Position{N}},
) where {N}
return TranslationGroup(N)
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function evalPotentialSpecific(
maxlen = _beforeSolveCCW!(ccwl, variables, sfidx, N; solveKey, needFreshMeasurements, measurement)

# Check which variables have been initialized
isinit = map(x -> isInitialized(x), variables)
isinit = map(x -> isInitialized(x, solveKey), variables)

# assemble how hypotheses should be computed
# nullSurplus see #1517
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,13 @@ function resetInitialValues!(
for vs in varList
vnd = getVariableState(getVariable(src, vs), initKey)
# guess we definitely want to use copy to preserve the initKey memory
updateVariableSolverData!(dest, vs, vnd, solveKey, true; warn_if_absent = false)
# updateVariableSolverData!(dest, vs, vnd, solveKey, true; warn_if_absent = false)
DFG.copytoVariableState!(
dest,
vs,
solveKey,
vnd,
)
end
return dest
end
Expand Down
File renamed without changes.
File renamed without changes.
Loading