CTFlows.jl
CTFlows.jl is the flow integration layer of the control-toolbox ecosystem. Given a dynamical system — a vector field, a Hamiltonian, a Hamiltonian vector field, or directly an optimal control problem — it builds a callable flow that integrates the system from any initial condition to any final time, with a pluggable ODE solver and optional automatic differentiation.
CTFlows in the ecosystem
CTFlows handles integration. For modelling optimal control problems see CTModels.jl; for solving NLPs see CTSolvers.jl; for differential-geometric tools (Lie brackets, Poisson brackets, lifts) see CTLie.jl; the umbrella package is OptimalControl.jl.
Quick start
using CTFlows
using CTBase.Data, CTFlows.Flows, CTFlows.Trajectories
import OrdinaryDiffEqTsit5 # activates the SciML integrator extension
# 1. Wrap the dynamics
vf = Data.VectorField(x -> -x) # autonomous, fixed, out-of-place
# 2. Build the flow
flow = Flows.Flow(vf; reltol=1e-8)
# 3. Integrate — point form (final state)
xf = flow(0.0, [1.0, 0.0], 1.0)
# 4. Integrate — trajectory form (full history)
sol = flow((0.0, 1.0), [1.0, 0.0])
t = Trajectories.time_grid(sol)
x = Trajectories.state(sol) # callable: x(t) → state at time t
x(0.5) # interpolateQualified access
CTFlows exports nothing at the package level. Every symbol lives in a submodule (CTBase.Data, CTFlows.Flows, …) and is reached via a qualified path or a using CTFlows.SubModule import.
The same Flow constructor also builds directly from an optimal control problem — a CTModels.Models.Model — with no Hamiltonian to write by hand: Flows.Flow(ocp). This is the entry point most users of the control-toolbox ecosystem actually reach for; see the Getting Started walkthrough and the Optimal control guide.
Architecture
CTFlows is organised as a pipeline:
Data → Systems → Integrators → Flows → Trajectories| Layer | Submodule | Key types |
|---|---|---|
| Data | CTBase.Data | VectorField, Hamiltonian, HamiltonianVectorField, PseudoHamiltonian, ControlledVectorField, OpenLoop, ClosedLoop, DynClosedLoop |
| Configs | CTFlows.Configs | StateEndPointConfig, HamiltonianTrajectoryConfig, AugmentedHamiltonianEndPointConfig |
| Systems | CTFlows.Systems | VectorFieldSystem, HamiltonianSystem, PseudoHamiltonianSystem |
| Integrators | CTFlows.Integrators | SciML |
| Flows | CTFlows.Flows | StateFlow, HamiltonianFlow, OptimalControlFlow, ControlledFlow |
| Trajectories | CTFlows.Trajectories | VectorFieldTrajectory, HamiltonianVectorFieldTrajectory, StateFlowTrajectory |
| Multi-phase | CTFlows.MultiPhase | MultiPhaseStateFlow |
The data layer (VectorField, Hamiltonian, HamiltonianVectorField) lives in CTBase.Data; the ODE integrator strategy is provided by CTSolvers.Integrators and re-exported through CTFlows.Integrators.
The shortcut Flows.Flow(data; opts...) collapses all pipeline steps into a single call. The explicit pipeline (build_system → build_integrator → build_flow) gives full control over each step.
Guides
| Guide | Contents |
|---|---|
| Getting Started | Installation, mental model, 5-minute walkthrough |
| Flows | End-to-end pipeline: data → systems → flows → trajectories, multi-phase |
| Building a flow | Shortcut and explicit constructors |
| Integrating | Call styles, configuration objects, integrator options |
| Trajectories | Reading the result: state, costate, time_grid, plotting |
| Multi-phase flows | Concatenating flows with switching times and jumps |
| Optimal control | Flows from optimal control problems (Flow(ocp)) |
| Control laws | Flow(ocp, law), Flow(h̃, law), Flow(fc, law) — OpenLoop, ClosedLoop, DynClosedLoop |
| SciML flows | Flows from ODEFunction / ODEProblem (SciML extension) |