Skip to content

Commit

Permalink
Merge pull request #1748 from JuliaRobotics/23Q3/ext/derelative
Browse files Browse the repository at this point in the history
wip DiffEqFactorExt
  • Loading branch information
dehann authored Jul 12, 2023
2 parents 71a5c22 + 1393d57 commit 4918b57
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"

[extensions]
DiffEqFactorExt = "DifferentialEquations"
GadflyExt = "Gadfly"
InteractiveUtilsExt = "InteractiveUtils"
InterpolationsExt = "Interpolations"
Expand Down Expand Up @@ -96,7 +98,6 @@ TimeZones = "1.3.1"
julia = "1.8"

[extras]
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
Expand Down
43 changes: 13 additions & 30 deletions src/ODE/DERelative.jl → ext/DiffEqFactorExt.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
module DiffEqFactorExt

@info "IncrementalInference.jl is loading tools related to DifferentialEquations.jl"
@info "IncrementalInference.jl is loading extensions related to DifferentialEquations.jl"

using .DifferentialEquations
using DifferentialEquations
import DifferentialEquations: solve

import .DifferentialEquations: solve
using Dates

import IncrementalInference: getSample, getManifold
using IncrementalInference
import IncrementalInference: getSample, getManifold, DERelative

export DERelative
using DocStringExtensions

"""
$TYPEDEF
export DERelative

Build a full ODE solution into a relative factor to condense possible sensor data into a relative transformation,
but keeping the parameter estimation process fluid. Assumes first and second variable in order
are of same dimension and compatible manifolds, such that ODE runs from Xi to Xi+1 on all
dimensions. Internal state vector can be decoupled onto different domain as needed.

Notes
- Based on DifferentialEquations.jl
- `getSample` step does the `solve(ODEProblem)` step.
- `tspan` is taken from variables only once at object construction -- i.e. won't detect changed timestamps.
- Regular factor evaluation is done as full dimension `AbstractRelativeRoots`, and is basic linear difference.
DevNotes
- FIXME see 1025, `multihypo=` will not yet work.
- FIXME Lots of consolidation and standardization to do, see RoME.jl #244 regarding Manifolds.jl.
- TODO does not yet handle case where a factor spans across two timezones.
"""
struct DERelative{T <: InferenceVariable, P, D} <: AbstractRelativeRoots
domain::Type{T}
forwardProblem::P
backwardProblem::P
# second element of this data tuple is additional variables that will be passed down as a parameter
data::D
specialSampler::Function
end

getManifold(de::DERelative{T}) where {T} = getManifold(de.domain)

Expand Down Expand Up @@ -132,6 +111,8 @@ function _solveFactorODE!(measArr, prob, u0pts, Xtra...)
return sol
end

getSample(cf::CalcFactor{<:DERelative}) = error("getSample(::CalcFactor{<:DERelative}) not implemented yet")

# FIXME see #1025, `multihypo=` will not work properly yet
function sampleFactor(cf::CalcFactor{<:DERelative}, N::Int = 1)
#
Expand Down Expand Up @@ -220,3 +201,5 @@ end
# ode.problem.f.f

#

end # module
2 changes: 1 addition & 1 deletion ext/GadflyExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module GadflyExt

using Gadfly
using DocStringExtensions
using IncrementalInference: AbstractBayesTree, TreeCliq, getCliqueData, getCliqAssocMat, getCliqMat, getLabel, getCliqMsgMat, getClique
using IncrementalInference: AbstractBayesTree, TreeClique, getCliqueData, getCliqAssocMat, getCliqMat, getLabel, getCliqMsgMat, getClique
import IncrementalInference: exportimg, spyCliqMat

export exportimg, spyCliqMat
Expand Down
28 changes: 28 additions & 0 deletions ext/WeakDepsPrototypes.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@

"""
$TYPEDEF
Build a full ODE solution into a relative factor to condense possible sensor data into a relative transformation,
but keeping the parameter estimation process fluid. Assumes first and second variable in order
are of same dimension and compatible manifolds, such that ODE runs from Xi to Xi+1 on all
dimensions. Internal state vector can be decoupled onto different domain as needed.
Notes
- Based on DifferentialEquations.jl
- `getSample` step does the `solve(ODEProblem)` step.
- `tspan` is taken from variables only once at object construction -- i.e. won't detect changed timestamps.
- Regular factor evaluation is done as full dimension `AbstractRelativeRoots`, and is basic linear difference.
DevNotes
- FIXME see 1025, `multihypo=` will not yet work.
- FIXME Lots of consolidation and standardization to do, see RoME.jl #244 regarding Manifolds.jl.
- TODO does not yet handle case where a factor spans across two timezones.
"""
struct DERelative{T <: InferenceVariable, P, D} <: AbstractRelativeMinimize
domain::Type{T}
forwardProblem::P
backwardProblem::P
# second element of this data tuple is additional variables that will be passed down as a parameter
data::D
specialSampler::Function
end

# InteractiveUtils.jl
function getCurrentWorkspaceFactors end
function getCurrentWorkspaceVariables end
Expand Down
2 changes: 2 additions & 0 deletions src/ExportAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ export makeSolverData!

export MetaPrior

export DERelative

# weakdeps on InteractiveUtils.jl
export getCurrentWorkspaceFactors, getCurrentWorkspaceVariables
export listTypeTree
Expand Down
6 changes: 3 additions & 3 deletions src/IncrementalInference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ function __init__()
# @require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include(
# "services/EmbeddedPlottingUtils.jl",
# )
@require DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" include(
"ODE/DERelative.jl",
)
# @require DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" include(
# "ODE/DERelative.jl",
# )
# @require Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" include(
# "services/HeatmapSampler.jl",
# )
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ include("testCircular.jl")
include("testMixtureLinearConditional.jl")
include("testFluxModelsDistribution.jl")
include("testAnalysisTools.jl")
# include("testDERelative.jl")
try
include("testDERelative.jl")
catch
@error "[FAILED] Fix testDERelative.jl, likely just requires implementing DiffEqFactorExt.getSample(::CalcFactor{<:DERelative})."
end

include("testBasicParametric.jl")
include("testMixtureParametric.jl")
Expand Down

0 comments on commit 4918b57

Please sign in to comment.