Skip to content

Flows ​

The CTFlows.Flows submodule is the central abstraction of CTFlows. A flow is a callable object that integrates a dynamical system over a time interval: you hand it an initial condition and a final time, and it returns the result.

CTFlows builds flows through a pipeline of five layers:

text
Data → Systems → Integrators → Flows → Trajectories

Each layer has a single responsibility. The arrows show the build order, not a data dependency: Systems and Integrators are constructed independently — one from Data, the other from integrator options — and only meet when build_flow(system, integrator) combines them into a Flow (see Building a flow):

LayerSubmoduleWhat it produces
DataCTBase.DataTyped function wrappers (VectorField, Hamiltonian, HamiltonianVectorField, PseudoHamiltonian, PseudoHamiltonianVectorField, ControlledVectorField) and control laws (OpenLoop, ClosedLoop, DynClosedLoop)
SystemsSystemsODE right-hand side + traits (VectorFieldSystem, HamiltonianSystem, …)
IntegratorsIntegratorsODE solver strategy (SciML)
FlowsFlowsCallable integration object (StateFlow, HamiltonianFlow, OptimalControlFlow, ControlledFlow)
TrajectoriesTrajectoriesResult container with semantic accessors (state, costate, control, time_grid, objective)

Reading order ​

PageTopicKey types
Building a flowAssembling the pipelinebuild_system, build_flow, Flow
IntegratingCalling a flow, configuration objects, integrator optionsStateEndPointConfig, StateTrajectoryConfig
TrajectoriesReading the resultstate, costate, time_grid, plot
Multi-phase flowsConcatenating flows with switching timesMultiPhaseStateFlow, MultiPhaseHamiltonianFlow, *
Optimal controlFlows from optimal control problemsOptimalControlFlow, Flow(ocp)
Control lawsFlows with control lawsControlledFlow, Flow(ocp, law), OpenLoop, ClosedLoop, DynClosedLoop
Constrained flowsPath-constraint terms on Flow(ocp, law)constraint, multiplier, hamiltonian_type
SciML flowsFlows from SciML functions and problemsFlow(::ODEFunction), Flow(::ODEProblem), SciMLProblemFlow
GPU flowsRunning a flow on a devicemethod=:gpu, CuArray states, the GPU contract

The data layer and the trait system (Autonomous, Fixed, InPlace, …) live in CTBase — see CTBase.Data and CTBase.Traits in the CTBase documentation. Likewise, the ODE solver strategy (SciML) is not implemented in CTFlows: it is provided by CTSolvers.Integrators and re-exported through CTFlows.Integrators — see SciML integrator internals for the split between the two packages.

Qualified access ​

CTFlows exports nothing at the package level. Bring submodules into scope explicitly:

julia
using CTFlows
using CTFlows: Flows        # StateFlow, HamiltonianFlow, Flow, build_flow
using CTBase: Data          # VectorField, Hamiltonian, HamiltonianVectorField
using CTFlows: Systems      # build_system
using CTFlows: Integrators  # SciML, build_problem, build_options
using CTFlows: Trajectories # VectorFieldTrajectory, state, time_grid
using CTBase: Traits        # Autonomous, Fixed, InPlace, …
using CTFlows: Configs      # StateEndPointConfig, StateTrajectoryConfig, …
using OrdinaryDiffEqTsit5: OrdinaryDiffEqTsit5 # activates the SciML extension

A first flow ​

Getting Started builds, integrates and reads a first flow step by step. The shortcut Flows.Flow(data; opts...) runs the whole pipeline in one call; Building a flow shows each step (build_system, the SciML integrator, build_flow) explicitly.

Mathematical setting ​

We work on a state space  .

  • A vector field is a map    (or with time and/or variable arguments).

  • A Hamiltonian is a scalar map   ,   defined on the cotangent bundle.

  • A Hamiltonian vector field is the map    ,   .

Which extra arguments appear (, ) is encoded by the trait system — see CTBase.Traits.

An optimal control problem adds a control  , dynamics  , and a Mayer/Lagrange cost to minimise (or maximise). Its pseudo-Hamiltonian       (  ,    for :min/:max) still carries the control explicitly. Two routes turn it into a genuine Hamiltonian that a flow can integrate:

  • Control-free: no control at all — reduces directly to . This is Flow(ocp) — see Optimal control.

  • With a control law: a feedback (or ) closes the loop,  . This is Flow(ocp, law) / Flow(h̃, law) — see Control laws.

See also ​