Skip to content

Private API ​

This page lists non-exported (internal) symbols of CTFlowsSciMLFlows, CTFlowsPlots, CTFlows.MultiPhase, CTFlowsStaticArrays, CTFlows.TrajectoryPlots, CTFlows.Systems, CTFlowsSciMLIntegrator, CTFlows.Flows, CTFlowsMakie, CTFlows.Configs, CTFlows.Display, CTFlows.Integrators, CTFlows.Trajectories.


From CTFlowsSciMLFlows ​

IPSciMLIpRHS [Struct] ​

CTFlowsSciMLFlows.IPSciMLIpRHS Type
julia
struct IPSciMLIpRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPRHS

In-place RHS functor for an in-place SciML ODEFunction.

Wraps an in-place SciML function and provides an in-place interface by directly calling the function.

Fields

  • f::F: The wrapped SciML ODEFunction

  • cx::CX: coercion applied to the state before calling f (_safe_only for a 1-D state, identity otherwise, per issue #357 — SciMLFunctionSystem shares VectorFieldSystem's Systems/Trajectories dispatch, so it gets the same 1-D = scalar coercion; see CTFlows.Systems._coerce_state).

Call signature

(r::IPSciMLIpRHS)(du, u, λ, t) -> nothing

See also: CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.

IPSciMLOoPRHS [Struct] ​

CTFlowsSciMLFlows.IPSciMLOoPRHS Type
julia
struct IPSciMLOoPRHS{F<:SciMLBase.AbstractODEFunction{false}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPRHS

In-place RHS functor for an out-of-place SciML ODEFunction.

Wraps an out-of-place SciML function and provides an in-place interface by allocating the result into the pre-allocated du buffer.

Fields

  • f::F: The wrapped SciML ODEFunction

  • cx::CX: coercion applied to the state before calling f.

Call signature

(r::IPSciMLOoPRHS)(du, u, λ, t) -> nothing

See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.

OoPSciMLIpFinalizeRHS [Struct] ​

CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS Type
julia
struct OoPSciMLIpFinalizeRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHS

Out-of-place RHS functor for an in-place SciML ODEFunction with type conversion.

Wraps an in-place SciML function and provides an out-of-place interface that converts the result to match the input type (e.g., Vector → SVector).

Fields

  • f::F: The wrapped SciML ODEFunction

  • cx::CX: coercion applied to the state before calling f.

Call signature

(r::OoPSciMLIpFinalizeRHS)(u, λ, t) -> du

See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.

OoPSciMLIpRHS [Struct] ​

CTFlowsSciMLFlows.OoPSciMLIpRHS Type
julia
struct OoPSciMLIpRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHS

Out-of-place RHS functor for an in-place SciML ODEFunction.

Wraps an in-place SciML function and provides an out-of-place interface by allocating a temporary buffer on each call.

Fields

  • f::F: The wrapped SciML ODEFunction

  • cx::CX: coercion applied to the state before calling f.

Call signature

(r::OoPSciMLIpRHS)(u, λ, t) -> du

Notes

  • dx = similar(u) already matches u's actual (uncoerced) shape, so no reshaping is needed even when cx collapses the CALL argument to a scalar.

See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.

OoPSciMLOoPRHS [Struct] ​

CTFlowsSciMLFlows.OoPSciMLOoPRHS Type
julia
struct OoPSciMLOoPRHS{F<:SciMLBase.AbstractODEFunction{false}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHS

Out-of-place RHS functor for an out-of-place SciML ODEFunction.

Wraps an out-of-place SciML function and provides an out-of-place interface by directly calling the function.

Fields

  • f::F: The wrapped SciML ODEFunction

  • cx::CX: coercion applied to the state before calling f.

Call signature

(r::OoPSciMLOoPRHS)(u, λ, t) -> du

Notes

  • Unlike the Hamiltonian-family out-of-place functors, this functor has a single block and nothing to reassemble: when cx collapses u to a scalar for the call, f may return a bare scalar too, which does not match u's own (uncoerced) container shape. That case is reshaped back explicitly, matching CTFlows.Systems.OoPVFOoPRHS's identical handling.

See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS.

SciMLFunctionSystem [Struct] ​

CTFlowsSciMLFlows.SciMLFunctionSystem Type
julia
struct SciMLFunctionSystem{F<:SciMLBase.AbstractODEFunction} <: CTFlows.Systems.AbstractStateSystem{CTBase.Traits.NonAutonomous, CTBase.Traits.NonFixed}

Concrete AbstractStateSystem wrapping a SciMLBase.AbstractODEFunction.

Unlike a genuine SciML bypass (SciMLProblemFlow, wrapping an AbstractODEProblem), this system implements Systems.AbstractSystem (get_ip_rhs/get_oop_rhs) and shares VectorFieldSystem's Systems/Trajectories dispatch, so per issue control-toolbox/CTFlows.jl#357 it also follows the "1-D = scalar" convention: RHS closures are built lazily by get_ip_rhs/get_oop_rhs based on the actual initial condition type, coercing a 1-D state to a scalar before calling the wrapped ODE function — mirroring CTFlows.Systems.VectorFieldSystem.

Unlike CTFlows-native systems, this system passes p = variable directly to the ODE — no ODEParameters wrapper — so users can pass arbitrary SciML parameter objects.

The mutability trait is encoded in the iip type parameter of the wrapped function:

  • AbstractODEFunction{true} → in-place f!(du, u, p, t)

  • AbstractODEFunction{false} → out-of-place f(u, p, t) -> du

Type Parameters

  • F <: SciMLBase.AbstractODEFunction: The wrapped ODE function.

Fields

  • f::F: The wrapped SciML ODE function.

Example

julia
using SciMLBase, CTFlows

f = ODEFunction((du, u, p, t) -> du .= -p .* u)
sys = SciMLFunctionSystem(f)

SciMLProblemFlow [Struct] ​

CTFlowsSciMLFlows.SciMLProblemFlow Type
julia
struct SciMLProblemFlow{P<:SciMLBase.AbstractODEProblem, I<:CTSolvers.Integrators.AbstractIntegrator} <: CTFlows.Flows.AbstractStateFlow{CTBase.Traits.NonAutonomous, CTBase.Traits.NonFixed}

Concrete AbstractFlow wrapping a SciMLBase.AbstractODEProblem directly.

Unlike StateFlow which wraps an AbstractSystem and an AbstractIntegrator, SciMLProblemFlow wraps a fully-assembled ODE problem. The system method returns nothing because there is no CTFlows AbstractSystem to extract.

The flow supports three call modes:

  • No-arg call f(; unsafe) — solves the problem as-is with trajectory options.

  • Point call f(t0, x0, tf; variable, unsafe) — calls SciMLBase.remake first with point options, returns final state only.

  • Trajectory call f(tspan, x0; variable, unsafe) — calls SciMLBase.remake first with trajectory options, returns complete solution.

Type Parameters

  • P <: SciMLBase.AbstractODEProblem: The wrapped ODE problem.

  • I <: Integrators.AbstractIntegrator: The integrator strategy (typically SciML).

Fields

  • prob::P: The wrapped ODE problem (contains u0, tspan, p).

  • integrator::I: The integrator strategy (provides options via build_options).

  • label::String: The label of the phase the flow integrates ("" for no label), see CTFlows.Flows.label.

Example

julia
using SciMLBase, CTFlows

prob = ODEProblem((du, u, p, t) -> du .= -p .* u, [1.0], (0.0, 1.0), 2.0)
flow = SciMLProblemFlow(prob, Integrators.SciML())

# No-arg call: solve as-is
sol = flow(; unsafe=false)

# Point call: modify initial condition and time span, returns final state
xf = flow(0.5, [2.0], 2.0; variable=3.0, unsafe=false)

# Trajectory call: modify initial condition and time span, returns complete solution
sol = flow((0.5, 2.0), [2.0]; variable=3.0, unsafe=false)

_AnySciMLRHS [Struct] ​

CTFlowsSciMLFlows._AnySciMLRHS Type

Union type of all SciML RHS functors.

Notes

  • Internal type alias used for method dispatch on display methods.

  • Covers all five conversion strategies between in-place and out-of-place interfaces.

See also: CTFlowsSciMLFlows._rhs_sciml_label, CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.

_check_problem_saveat [Function] ​

CTFlowsSciMLFlows._check_problem_saveat Function
julia
_check_problem_saveat(prob, config)

Reject an output grid given at the call when the wrapped problem stores its own saveat.

Throws

  • CTBase.Exceptions.IncorrectArgument: If a grid is given and prob.kwargs has saveat.

_rhs_sciml_label [Function] ​

CTFlowsSciMLFlows._rhs_sciml_label Function
julia
_rhs_sciml_label(
    _::CTFlowsSciMLFlows.IPSciMLIpRHS
) -> String

Return a human-readable label describing the RHS conversion strategy.

Arguments

  • r::IPSciMLIpRHS: In-place SciML → in-place interface functor.

  • r::OoPSciMLIpRHS: In-place SciML → out-of-place interface functor.

  • r::OoPSciMLIpFinalizeRHS: In-place SciML → out-of-place interface with type conversion functor.

  • r::IPSciMLOoPRHS: Out-of-place SciML → in-place interface functor.

  • r::OoPSciMLOoPRHS: Out-of-place SciML → out-of-place interface functor.

Returns

  • String: A descriptive label of the conversion strategy.

Notes

  • Internal helper used for display purposes in Base.show methods.

  • Labels describe both the wrapped SciML function's interface and the provided interface.

See also: CTFlowsSciMLFlows._AnySciMLRHS.


From CTFlowsPlots ​

_plot [Function] ​

CTFlowsPlots._plot Function
julia
_plot(sol, description::Symbol...; size, kwargs...) -> Any

Internal implementation of Plots.plot for the CTFlows trajectory types.

Builds the figure with CTFlows.TrajectoryPlots.build_figure (which owns the user-facing defaults and throws on an empty description) and renders it via CTBase.Plotting.render on the Plots backend. Returns a Plots.Plot.

_plot! [Function] ​

CTFlowsPlots._plot! Function
julia
_plot!(
    p::Plots.Plot,
    sol,
    description::Symbol...;
    kwargs...
) -> Plots.Plot

Internal implementation of Plots.plot! for the CTFlows trajectory types: build the figure with CTFlows.TrajectoryPlots.build_figure and overlay it onto the existing plot p via CTBase.Plotting.render! (Plots backend).


From CTFlows.MultiPhase ​

_PiecewiseControlLaw [Struct] ​

CTFlows.MultiPhase._PiecewiseControlLaw Type
julia
struct _PiecewiseControlLaw{L, S}

Piecewise control law reconstructed from the per-phase laws of a multi-phase flow. It selects the phase by time (a flat searchsortedfirst over the switching times — no nested closures), then delegates to that phase's law with the caller's uniform signature. It serves both reconstruction paths: (pl)(t, x, p, v) for the Hamiltonian/OCP law, and CTFlows.Trajectories._controlled_u(pl, t, x, v) for the state (controlled) law.

At an exact switching time tᵢ the phase that ends at tᵢ is selected, consistently with the state and costate, which are left-continuous: u(tᵢ) is the left limit, computed from the values before the jump. The right limit, the next phase's law evaluated after the jump, is given by CTFlows.MultiPhase._right_law.

Type Parameters

  • L: type of the tuple of per-phase control laws.

  • S: type of the switching-times vector.

Fields

  • laws::L: tuple of the per-phase control laws (each a CTBase.Data.ControlLaw).

  • switches::S: the n-1 sorted switching times.

See also: CTFlows.MultiPhase._reconstruct_ocp_solution, CTFlows.MultiPhase._reconstruct_controlled_trajectory.

_PiecewiseDuals [Struct] ​

CTFlows.MultiPhase._PiecewiseDuals Type
julia
struct _PiecewiseDuals{D<:Tuple, S}

Constraint duals of a multi-phase OCP flow: the duals of each phase, selected by time as the CTFlows.MultiPhase._PiecewiseControlLaw selects the law (at a switching time, the phase that ends there). A label adjoined in some phases only has a zero dual in the others, except a control box (a saturated control has a nonzero box dual that a phase without the box does not compute): a control box is known only when every phase adjoins it.

Fields

  • duals::D: tuple of the per-phase CTFlows.Flows._FlowDuals.

  • switches::S: the n-1 sorted switching times.

  • labels::Vector{Symbol}: the labels with a known dual.

  • dims::Dict{Symbol,Int}: the number of rows (or components) of each label.

_apply_component_jump [Function] ​

CTFlows.MultiPhase._apply_component_jump Function
julia
_apply_component_jump(v, j) -> Any

Apply an additive jump to a single component.

Arguments

  • v: Component value (state or costate).

  • j: Additive offset (vector or scalar); added element-wise.

Returns

  • v .+ j.

See also: CTFlows.MultiPhase._apply_jump.

julia
_apply_component_jump(v, j::Function) -> Any

Apply a callable jump to a single component.

Arguments

  • v: Component value (state or costate).

  • j::Function: Callable; called as j(v).

Returns

  • j(v).

See also: CTFlows.MultiPhase._apply_jump.

julia
_apply_component_jump(v, _::Nothing) -> Any

Identity jump — leave the component unchanged.

Arguments

  • v: Component value (state or costate).

  • ::Nothing: Sentinel for "no jump on this component".

Returns

  • v unchanged.

See also: CTFlows.MultiPhase._apply_jump.

_apply_hamiltonian_jump [Function] ​

CTFlows.MultiPhase._apply_hamiltonian_jump Function
julia
_apply_hamiltonian_jump(
    state_tuple::Tuple,
    jump::Tuple
) -> Tuple{Any, Any}

Apply per-component jumps to a Hamiltonian state tuple.

Each component (jump[1] for state, jump[2] for costate) is handled independently by CTFlows.MultiPhase._apply_component_jump: a vector/scalar is added, a callable is applied, and nothing leaves the component unchanged.

Arguments

  • state_tuple::Tuple: Tuple of (state, costate).

  • jump::Tuple: Tuple of (state_jump, costate_jump); each element may be a vector/scalar, a callable, or nothing.

Returns

  • Tuple of updated (state, costate).

See also: CTFlows.MultiPhase._apply_jump, CTFlows.MultiPhase._apply_component_jump.

julia
_apply_hamiltonian_jump(
    state_tuple::Tuple,
    jump::Function
) -> Any

Apply a callable jump to a Hamiltonian state tuple.

The callable receives both components and must return an updated (state, costate) tuple: (x, p) ← jump(x, p).

Arguments

  • state_tuple::Tuple: Tuple of (state, costate).

  • jump::Function: Callable with signature (x, p) -> (x', p').

Returns

  • Tuple (x', p') returned by jump.

See also: CTFlows.MultiPhase._apply_jump, CTFlows.MultiPhase._apply_component_jump.

julia
_apply_hamiltonian_jump(
    state_tuple::Tuple,
    jump
) -> Tuple{Any, Any}

Apply an additive costate jump to a Hamiltonian state tuple.

Adds jump to the costate only; the state is left unchanged. Follows the "1-D is a scalar" convention: pass a scalar for a 1-D costate, a vector for an n-D costate.

Arguments

  • state_tuple::Tuple: Tuple of (state, costate).

  • jump: Additive costate offset (scalar or vector).

Returns

  • Tuple of (state, costate .+ jump).

See also: CTFlows.MultiPhase._apply_jump, CTFlows.MultiPhase._apply_component_jump.

_apply_inverse_jump [Function] ​

CTFlows.MultiPhase._apply_inverse_jump Function
julia
_apply_inverse_jump(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    i,
    state
) -> Any

Apply the inverse of the jump at the i-th switching time of mpf, for a backward horizon that crosses it: the state before the jump, in increasing time, from the state after it.

An additive jump (a vector or a number, on the state, or on the costate of a Hamiltonian flow) is undone by subtraction, and nothing leaves the component unchanged. A jump given as a function has no known inverse: crossing it backward throws.

Throws

See also: CTFlows.MultiPhase._apply_jump.

_apply_jump [Function] ​

CTFlows.MultiPhase._apply_jump Function
julia
_apply_jump(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    i,
    state
) -> Any

Apply a jump to the state for state flows.

Arguments

  • mpf::MultiPhaseStateFlow: The multi-phase state flow.

  • i: Phase index.

  • state: Current state.

Returns

  • State after applying the jump.

See also: CTFlows.MultiPhase.jumps.

julia
_apply_jump(
    _::Type{CTBase.Traits.StateDynamics},
    mpf,
    i,
    state
) -> Any

Apply a jump to the state for state dynamics.

Arguments

  • ::Type{Traits.StateDynamics}: State dynamics trait tag.

  • mpf::MultiPhaseFlow: The multi-phase flow.

  • i::Int: Phase index.

  • state: Current state.

Returns

  • State after applying the jump.

Notes

This is an internal dispatch method for the _apply_jump function. Delegates to CTFlows.MultiPhase._apply_component_jump, which supports additive offsets (j a vector/scalar), callables (j(state)), and nothing (identity).

julia
_apply_jump(
    _::Type{CTBase.Traits.HamiltonianDynamics},
    mpf,
    i,
    state_tuple
) -> Any

Apply a jump to the state and costate for Hamiltonian dynamics.

Arguments

  • ::Type{Traits.HamiltonianDynamics}: Hamiltonian dynamics trait tag.

  • mpf::MultiPhaseFlow: The multi-phase flow.

  • i::Int: Phase index.

  • state_tuple: Tuple of (state, costate).

Returns

  • Tuple of (state, costate) after applying the jump.

Notes

This is an internal dispatch method for the _apply_jump function.

_check_phase_grids [Function] ​

CTFlows.MultiPhase._check_phase_grids Function
julia
_check_phase_grids(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    config
)

Reject a generated grid (grid=) when a phase integrator sets saveat. A grid of times is checked by each phase flow on its sub-grid.

_check_switching_times_order [Function] ​

CTFlows.MultiPhase._check_switching_times_order Function
julia
_check_switching_times_order(switches::Vector{<:Real})

Validate that switching times are strictly increasing.

Throws a CTBase.Exceptions.PreconditionError if the switching times are not in strictly increasing order (i.e., if any switches[i] >= switches[i+1]).

Arguments

  • switches::Vector{<:Real}: Vector of switching times to validate.

Throws

Notes

  • This is a private helper function used internally by concatenation operators.

  • Strictly increasing means each time must be greater than the previous one.

_cross [Function] ​

CTFlows.MultiPhase._cross Function
julia
_cross(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    c::Int64,
    state,
    forward::Bool
) -> Any

Cross the switching time t_c of mpf with the state state: apply its jump in the forward direction, its inverse in the backward one (see CTFlows.MultiPhase._apply_inverse_jump).

_end_point_reached [Function] ​

CTFlows.MultiPhase._end_point_reached Function
julia
_end_point_reached(
    raw,
    flow,
    t0,
    tf,
    x,
    config,
    variable,
    unsafe
) -> Any

Fallback of CTFlows.MultiPhase._evaluate_phase_reached: a phase that cannot report its time is evaluated by CTFlows.MultiPhase._evaluate_phase and assumed to reach tf.

julia
_end_point_reached(
    raw::CTFlows.Flows.StateFlow{TD, VD} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence},
    flow,
    t0,
    tf,
    x,
    _,
    variable,
    unsafe
) -> Any

State flow: the point call of the raw flow through CTFlows.Flows._timed, which returns (x, t_reached).

julia
_end_point_reached(
    raw::CTFlows.Flows.HamiltonianFlow{TD, VD} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence},
    flow,
    t0,
    tf,
    state_tuple,
    _,
    variable,
    unsafe
) -> Any

Hamiltonian flow: the point call of the raw flow through CTFlows.Flows._timed, which returns ((x, p), t_reached).

_evaluate_multiphase [Function] ​

CTFlows.MultiPhase._evaluate_multiphase Function
julia
_evaluate_multiphase(
    mpf,
    config::CTFlows.Configs.AbstractEndPointConfig;
    variable,
    unsafe
)

Evaluate a multi-phase flow for a point configuration, returning only the final state.

The horizon [t0, tf] may be anywhere: it may start after the first switching time, end before the last one, lie in a single phase, or be backward (t0 > tf). The phases met by the horizon are integrated in the order of the integration, each on its intersection with the horizon, and the jumps of the switching times strictly inside the horizon are applied — their inverse on a backward horizon. See CTFlows.MultiPhase._phase_plan.

A phase that stops before its end (a terminate! callback, a failure with unsafe=true) ends the flow: the following phases are not integrated, no jump is applied, and the state at the stop time is returned, as the point call of a single flow does (issue #526).

Arguments

  • mpf: The multi-phase flow to evaluate.

  • config::Configs.AbstractEndPointConfig: The point configuration with time span and initial conditions.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • The state at tf (or at the stop time).

Throws

See also: CTFlows.MultiPhase._evaluate_phase, CTFlows.MultiPhase._apply_jump.

julia
_evaluate_multiphase(
    mpf,
    config::CTFlows.Configs.AbstractTrajectoryConfig;
    variable,
    unsafe
)

Evaluate a multi-phase flow for a trajectory configuration, returning the full trajectory.

The phases met by the horizon are integrated as for the point call (see CTFlows.MultiPhase._phase_plan): the horizon may start after the first switching time, end before the last one, or be backward. The trajectory is returned in increasing time whatever the direction of integration: its switching times are those strictly inside the horizon, in increasing order, its phase labels those of the phases met, in increasing time, and it is left-continuous at a switching time (the value at tᵢ is the one before the jump, in increasing time). See CTFlows.Trajectories.in_increasing_time.

A phase that stops before its end (a terminate! callback, a failure with unsafe=true) ends the flow (issue #526): the following phases are not integrated, no jump is applied, and the trajectory, its labels, its switching times and its output grid stop at the stop time.

Arguments

  • mpf: The multi-phase flow to evaluate.

  • config::Configs.AbstractTrajectoryConfig: The trajectory configuration with time span and initial conditions.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • The merged trajectory over the phases met, in increasing time.

Throws

See also: CTSolvers.Integrators.merge, CTFlows.MultiPhase._evaluate_phase, CTFlows.MultiPhase._apply_jump.

_evaluate_multiphase_variable_costate [Function] ​

CTFlows.MultiPhase._evaluate_multiphase_variable_costate Function
julia
_evaluate_multiphase_variable_costate(
    mpf,
    config;
    variable,
    unsafe
)

Point call of a multi-phase Hamiltonian flow with variable_costate=true: the phases met by the horizon are integrated as in CTFlows.MultiPhase._evaluate_multiphase, each with the costate of the variable, ṗv = -∂H/∂v, carried from one phase to the next from pv(t0) = 0. The jumps act on the state and the costate only.

Returns

  • (xf, pf, pvf) at tf, or at the stop time of a phase stopped early.

Throws

  • CTBase.Exceptions.PreconditionError: if a phase does not support the costate of the variable, or if variable is not given (as for a single flow).

_evaluate_phase [Function] ​

CTFlows.MultiPhase._evaluate_phase Function
julia
_evaluate_phase(
    flow::CTFlows.Flows.AbstractStateFlow,
    t0,
    tf,
    x,
    ::CTFlows.Configs.AbstractEndPointConfig;
    variable,
    unsafe
)

Evaluate a single phase for a state flow with point configuration.

Dispatches on the abstract dynamics axis (AbstractStateFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.

Arguments

  • flow::Flows.AbstractStateFlow: The state (or decorated state) flow to evaluate.

  • t0: Start time.

  • tf: End time.

  • x: Initial state.

  • ::Configs.AbstractEndPointConfig: Point configuration type tag.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • Final state at time tf.

See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.StateFlow.

julia
_evaluate_phase(
    flow::CTFlows.Flows.AbstractStateFlow,
    t0,
    tf,
    x,
    config::CTFlows.Configs.AbstractTrajectoryConfig;
    variable,
    unsafe
)

Evaluate a single phase for a state flow with trajectory configuration.

Dispatches on the abstract dynamics axis (AbstractStateFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.

Arguments

  • flow::Flows.AbstractStateFlow: The state (or decorated state) flow to evaluate.

  • t0: Start time.

  • tf: End time.

  • x: Initial state.

  • ::Configs.AbstractTrajectoryConfig: Trajectory configuration type tag.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • Trajectory solution from t0 to tf.

See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.StateFlow.

julia
_evaluate_phase(
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    t0,
    tf,
    state_tuple,
    ::CTFlows.Configs.AbstractEndPointConfig;
    variable,
    unsafe
)

Evaluate a single phase for a Hamiltonian flow with point configuration.

Dispatches on the abstract dynamics axis (AbstractHamiltonianFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.

Arguments

  • flow::Flows.AbstractHamiltonianFlow: The Hamiltonian (or decorated Hamiltonian) flow to evaluate.

  • t0: Start time.

  • tf: End time.

  • state_tuple: Tuple of (initial_state, initial_costate).

  • ::Configs.AbstractEndPointConfig: Point configuration type tag.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • Tuple of (final_state, final_costate) at time tf.

See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.HamiltonianFlow.

julia
_evaluate_phase(
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    t0,
    tf,
    state_tuple,
    config::CTFlows.Configs.AbstractTrajectoryConfig;
    variable,
    unsafe
)

Evaluate a single phase for a Hamiltonian flow with trajectory configuration.

Dispatches on the abstract dynamics axis (AbstractHamiltonianFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.

Arguments

  • flow::Flows.AbstractHamiltonianFlow: The Hamiltonian (or decorated Hamiltonian) flow to evaluate.

  • t0: Start time.

  • tf: End time.

  • state_tuple: Tuple of (initial_state, initial_costate).

  • ::Configs.AbstractTrajectoryConfig: Trajectory configuration type tag.

  • variable: The variable parameter value (for NonFixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • Trajectory solution from t0 to tf.

See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.HamiltonianFlow.

_evaluate_phase_reached [Function] ​

CTFlows.MultiPhase._evaluate_phase_reached Function
julia
_evaluate_phase_reached(
    flow,
    t0,
    tf,
    x,
    config;
    variable,
    unsafe
)

Evaluate a single phase for a point configuration and report the time the solver reached.

The phase of a real flow (CTFlows.Flows.StateFlow, CTFlows.Flows.HamiltonianFlow, after CTFlows.MultiPhase._raw_flow) is integrated through CTFlows.Flows._timed. Any other phase is evaluated by CTFlows.MultiPhase._evaluate_phase and is assumed to reach tf.

Returns

  • Tuple: (final state, t_reached); the state is (x, p) for a Hamiltonian flow.

_extract_final_state [Function] ​

CTFlows.MultiPhase._extract_final_state Function
julia
_extract_final_state(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    segment,
    current_state
) -> Any

Extract the final state from a segment result for state flows.

Arguments

  • ::MultiPhaseStateFlow: Multi-phase state flow type tag.

  • segment: The segment solution.

  • current_state: Current state (unused for state flows).

Returns

  • Final state from the segment.

See also: CTSolvers.Integrators.final_state.

julia
_extract_final_state(
    _::Type{CTBase.Traits.StateDynamics},
    segment,
    _
) -> Any

Extract the final state from a segment result for state dynamics.

Arguments

  • ::Type{Traits.StateDynamics}: State dynamics trait tag.

  • segment: The segment solution.

  • _: Current state (unused for state dynamics).

Returns

  • Final state from the segment.

Notes

This is an internal dispatch method for the _extract_final_state function.

julia
_extract_final_state(
    _::Type{CTBase.Traits.StateDynamics},
    segment::CTFlows.Trajectories.VectorFieldTrajectory,
    _
) -> Any

Extract the final state from a VectorFieldTrajectory segment for state dynamics, reshaped back to the segment's own x0 container type (see CTFlows.MultiPhase._reshape_to_x0) rather than through its "1-D = scalar" Integrators.final_state accessor (issue #357).

julia
_extract_final_state(
    _::Type{CTBase.Traits.StateDynamics},
    segment::CTFlows.Trajectories.StateFlowTrajectory,
    _
) -> Any

Extract the final state from a StateFlowTrajectory segment for state dynamics (Flow(fc, law) / Flow(ocp, law)), reshaped back to the inner trajectory's own x0 container type (see CTFlows.MultiPhase._reshape_to_x0) rather than through its "1-D = scalar" Integrators.final_state accessor — see the VectorFieldTrajectory overload above for why.

julia
_extract_final_state(
    _::Type{CTBase.Traits.HamiltonianDynamics},
    segment,
    current_state
) -> Tuple{Any, Any}

Extract the final state and costate from a segment result for Hamiltonian dynamics.

Arguments

  • ::Type{Traits.HamiltonianDynamics}: Hamiltonian dynamics trait tag.

  • segment: The segment solution (concatenated state and costate).

  • current_state: Current state tuple (state, costate) used to determine dimensions.

Returns

  • Tuple of (final_state, final_costate).

Notes

This is an internal dispatch method for the _extract_final_state function.

julia
_extract_final_state(
    _::Type{CTBase.Traits.HamiltonianDynamics},
    segment::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
    _
) -> Tuple{Any, Any}

Extract the final state and costate from a HamiltonianVectorFieldTrajectory segment.

Unlike the generic HamiltonianDynamics method, no manual splitting is needed because HamiltonianVectorFieldTrajectory already stores the combined (x, p) vector and Integrators.final_state returns it directly.

Returns

  • The final combined (state, costate) vector from the segment.

_extract_initial_state [Function] ​

CTFlows.MultiPhase._extract_initial_state Function
julia
_extract_initial_state(
    config::CTFlows.Configs.AbstractStateConfig
) -> Any

Extract the initial state from a state configuration.

Arguments

  • config::Configs.AbstractStateConfig: The state configuration (StateEndPointConfig or StateTrajectoryConfig).

Returns

  • Initial state vector.

See also: CTFlows.Configs.initial_state, CTFlows.Configs.AbstractStateConfig.

julia
_extract_initial_state(
    config::CTFlows.Configs.AbstractHamiltonianConfig
) -> Tuple{Any, Any}

Extract the initial state and costate from a Hamiltonian configuration.

Arguments

  • config::Configs.AbstractHamiltonianConfig: The Hamiltonian configuration (HamiltonianEndPointConfig or HamiltonianTrajectoryConfig).

Returns

  • Tuple of (initial_state, initial_costate).

See also: CTFlows.Configs.initial_state, CTFlows.Configs.initial_costate, CTFlows.Configs.AbstractHamiltonianConfig.

_finalize_multiphase_trajectory [Function] ​

CTFlows.MultiPhase._finalize_multiphase_trajectory Function
julia
_finalize_multiphase_trajectory(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    merged,
    variable
) -> Any
_finalize_multiphase_trajectory(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    merged,
    variable,
    grid
) -> Any
_finalize_multiphase_trajectory(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    merged,
    variable,
    grid,
    bounds
) -> Any

Finalize a merged multi-phase trajectory into the type a single-phase flow would return.

All-OptimalControlFlow phases rebuild a CTModels.Solutions.Solution (via CTFlows.MultiPhase._reconstruct_ocp_solution); all-ControlledFlow phases rebuild a CTFlows.Trajectories.StateFlowTrajectory (via CTFlows.MultiPhase._reconstruct_controlled_trajectory); any other case (plain flows carrying no law) returns the merged raw trajectory unchanged.

The branch is a runtime isa test on the phase types rather than dispatch: a parametric alias (e.g. MultiPhaseHamiltonianFlow) is not more specific than the constrained base type, so it cannot select a method here.

Arguments

  • mpf::MultiPhaseFlow: The multi-phase flow whose phases carry the per-phase laws.

  • merged: The merged trajectory over all phases.

  • variable: The variable parameter value (for NonFixed systems).

Returns

  • A CTModels.Solution, a StateFlowTrajectory, or the merged trajectory (see above).

See also: CTFlows.MultiPhase._evaluate_multiphase.

_format_final_output [Function] ​

CTFlows.MultiPhase._format_final_output Function
julia
_format_final_output(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    state
) -> Any

Format the final output for state flows.

Arguments

  • ::MultiPhaseStateFlow: Multi-phase state flow type tag.

  • x: Final state.

Returns

  • The final state (no formatting needed).

See also: CTFlows.MultiPhase._evaluate_multiphase.

julia
_format_final_output(
    _::Type{CTBase.Traits.StateDynamics},
    x
) -> Any

Format the final output for state dynamics.

Arguments

  • ::Type{Traits.StateDynamics}: State dynamics trait tag.

  • x: Final state.

Returns

  • The final state (no formatting needed).

Notes

This is an internal dispatch method for the _format_final_output function.

julia
_format_final_output(
    _::Type{CTBase.Traits.HamiltonianDynamics},
    state_tuple
) -> Any

Format the final output for Hamiltonian dynamics.

Arguments

  • ::Type{Traits.HamiltonianDynamics}: Hamiltonian dynamics trait tag.

  • state_tuple: Tuple of (state, costate).

Returns

  • Tuple of (state, costate).

Notes

This is an internal dispatch method for the _format_final_output function.

_in_phase [Function] ​

CTFlows.MultiPhase._in_phase Function
julia
_in_phase(evaluate, i::Int64, n::Int64, unsafe::Bool) -> Any

Evaluate the phase i of a multi-phase flow of n phases and, when its integration raises a CTBase.Exceptions.SolverFailure with unsafe=false, raise it again with the phase in its context (issue #523): "phase 2 of 3, point call of the flow (SciML solve)".

The message, the return code and the suggestion are kept: the call of the flow of the phase already names unsafe=true (see CTFlows.Flows._with_unsafe_hint). With unsafe=true, evaluate is called as is. Any other exception is rethrown unchanged.

Arguments

  • evaluate: A function of no argument that evaluates the phase.

  • i::Int: The index of the phase.

  • n::Int: The number of phases.

  • unsafe::Bool: The unsafe keyword of the call.

Returns

  • The value of evaluate().

Throws

See also: CTFlows.MultiPhase._evaluate_multiphase.

_inverse_component_jump [Function] ​

CTFlows.MultiPhase._inverse_component_jump Function
julia
_inverse_component_jump(v, j, i) -> Any

Undo an additive jump on a single component: v .- j.

See also: CTFlows.MultiPhase._apply_component_jump.

_merge_switching_times [Function] ​

CTFlows.MultiPhase._merge_switching_times Function
julia
_merge_switching_times(f1, t_switch, f2) -> Any

Merge the switching times of two flows and a new switching time into a concrete vector.

_multiphase_display_name [Function] ​

CTFlows.MultiPhase._multiphase_display_name Function

Return a human-readable display name for a MultiPhaseFlow, dispatching on the dynamics trait.

  • StateDynamics → "MultiPhaseStateFlow"

  • HamiltonianDynamics → "MultiPhaseHamiltonianFlow"

  • Fallback → string(nameof(typeof(mpf)))

See also: CTFlows.MultiPhase.MultiPhaseFlow.

julia
_multiphase_display_name(
    _::CTFlows.MultiPhase.MultiPhaseHamiltonianFlow
) -> String

Return "MultiPhaseHamiltonianFlow" for a MultiPhaseFlow with HamiltonianDynamics.

julia
_multiphase_display_name(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow
) -> String

Fallback: return the concrete type name as a string.

_no_inverse_jump [Function] ​

CTFlows.MultiPhase._no_inverse_jump Function
julia
_no_inverse_jump(i)

Throw the error of a jump given as a function, crossed by a backward horizon: its inverse is not known.

Throws

_phase_dual [Function] ​

CTFlows.MultiPhase._phase_dual Function
julia
_phase_dual(
    pd::CTFlows.MultiPhase._PiecewiseDuals,
    d,
    label::Symbol,
    t,
    x,
    p,
    v
) -> Any

Dual of the phase d for label: its value when the phase knows it, zero otherwise.

_phase_law [Function] ​

CTFlows.MultiPhase._phase_law Function
julia
_phase_law(
    pl::CTFlows.MultiPhase._PiecewiseControlLaw,
    t
) -> Any

Return the phase law active at time t: the law of the phase selected by searchsortedfirst over the switching times, clamped to the valid phase range. At a switching time, it is the law of the phase that ends there (left continuity).

Arguments

  • pl::_PiecewiseControlLaw: The piecewise control law.

  • t: The time at which to select the active phase.

Returns

  • The per-phase control law active at time t.

_phase_plan [Function] ​

CTFlows.MultiPhase._phase_plan Function
julia
_phase_plan(switches, t0, tf) -> Any

The phases of a multi-phase flow met by the horizon from t0 to tf, in the order of the integration (issue #547).

The phase k holds on [t_{k-1}, t_k], with the switching times t_1 < … < t_{n-1}; the first phase extends to -∞ and the last one to +∞. Every phase that meets the horizon is integrated on its intersection with it, in increasing time when t0 ≤ tf and in decreasing time when t0 > tf. A switching time is crossed only when it lies strictly inside the horizon; at a bound of the horizon equal to a switching time, the phase on the side of the horizon is used, and no jump is applied: φ(tᵢ, x, tf) starts the phase i + 1 from x, and φ(t0, x, tᵢ) ends the phase i at tᵢ.

Arguments

  • switches: the switching times t_1 < … < t_{n-1}.

  • t0, tf: the horizon.

Returns

  • Vector{Tuple{Int,Any,Any,Int}}: one (k, a, b, c) per phase, in integration order: the phase k is integrated from a to b, after crossing the switching time t_c (c = 0 for the first phase, which crosses none).

_phase_times [Function] ​

CTFlows.MultiPhase._phase_times Function
julia
_phase_times(
    t0,
    tf,
    _::Union{Nothing, CTFlows.Configs.AbstractGrid}
) -> Tuple{Any, Any}

Time specification of a phase [t0, tf] when no output grid is imposed at the call: the phase's time span.

julia
_phase_times(t0, tf, grid::AbstractVector) -> Any

Time specification of a phase [t0, tf] under an output grid imposed at the call: the grid times strictly inside the phase, framed by the phase bounds (a switching time thus closes one phase and opens the next, as without a grid).

_piecewise_duals [Function] ​

CTFlows.MultiPhase._piecewise_duals Function
julia
_piecewise_duals(
    ocp,
    duals::Tuple,
    switches
) -> Union{Nothing, CTFlows.Flows._UnlabelledPathDuals, CTFlows.MultiPhase._PiecewiseDuals}

Combine the duals of the phases: nothing if a phase has none (control-free OCP), CTFlows.Flows._UnlabelledPathDuals if a phase has a constraint without a label (its duals cannot be placed, so neither can those of the whole solution), a CTFlows.MultiPhase._PiecewiseDuals otherwise.

_raw_flow [Function] ​

CTFlows.MultiPhase._raw_flow Function
julia
_raw_flow(f::CTFlows.Flows.AbstractFlow) -> Any

Return the raw inner flow of a phase, unwrapping the decorator flows (CTFlows.Flows.OptimalControlFlow / CTFlows.Flows.ControlledFlow) to the inner HamiltonianFlow/StateFlow that yields a mergeable raw segment; any other CTFlows.Flows.AbstractFlow (a plain HamiltonianFlow/StateFlow or a nested MultiPhaseFlow) is returned unchanged.

Dispatching on the abstract flow type — one method per decorator plus the fallback — covers every phase kind with no forgotten case.

Arguments

  • f::Flows.AbstractFlow: The phase flow.

Returns

  • The raw inner flow to integrate for this phase.
julia
_raw_flow(f::CTFlows.Flows.OptimalControlFlow) -> Any

Unwrap an CTFlows.Flows.OptimalControlFlow to its inner flow.

Returns

  • f.flow: the inner StateFlow/HamiltonianFlow.
julia
_raw_flow(f::CTFlows.Flows.ControlledFlow) -> Any

Unwrap a CTFlows.Flows.ControlledFlow to its inner flow.

Returns

  • f.flow: the inner StateFlow/HamiltonianFlow.

_reached_end [Function] ​

CTFlows.MultiPhase._reached_end Function
julia
_reached_end(t_reached, t_start, t_end) -> Any

Whether a phase integrated from t_start reached its end t_end, given the last time t_reached of its integration, in the direction of integration. A phase stopped before t_end (a terminate! callback, a failure with unsafe=true) has not.

See also: CTFlows.MultiPhase._sub.

_reconstruct_controlled_trajectory [Function] ​

CTFlows.MultiPhase._reconstruct_controlled_trajectory Function
julia
_reconstruct_controlled_trajectory(
    mpf,
    merged,
    variable
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}
_reconstruct_controlled_trajectory(
    mpf,
    merged,
    variable,
    grid
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}
_reconstruct_controlled_trajectory(
    mpf,
    merged,
    variable,
    grid,
    bounds
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}

Rebuild a CTFlows.Trajectories.StateFlowTrajectory from an all-ControlledFlow multi-phase trajectory, reconstructing the control as a CTFlows.MultiPhase._PiecewiseControlLaw and recomputing the objective (Mayer + Lagrange) over the merged trajectory when the phases carry an OCP (nothing objective for Flow(fc, law) phases).

Arguments

  • mpf: The multi-phase state flow.

  • merged: The merged state trajectory over all phases.

  • variable: The variable parameter value (for NonFixed systems).

Returns

See also: CTFlows.MultiPhase._reconstruct_ocp_solution, CTFlows.Flows._state_flow_objective.

_reconstruct_ocp_solution [Function] ​

CTFlows.MultiPhase._reconstruct_ocp_solution Function
julia
_reconstruct_ocp_solution(
    mpf,
    merged,
    variable
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.Solutions.AbstractTimeGridModel, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, ModelType<:CTModels.Models.AbstractModel, CostateModelType<:Function, DualModelType<:CTModels.Solutions.AbstractDualModel}
_reconstruct_ocp_solution(
    mpf,
    merged,
    variable,
    grid
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.Solutions.AbstractTimeGridModel, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, ModelType<:CTModels.Models.AbstractModel, CostateModelType<:Function, DualModelType<:CTModels.Solutions.AbstractDualModel}
_reconstruct_ocp_solution(
    mpf,
    merged,
    variable,
    grid,
    bounds
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.Solutions.AbstractTimeGridModel, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, ModelType<:CTModels.Models.AbstractModel, CostateModelType<:Function, DualModelType<:CTModels.Solutions.AbstractDualModel}

Rebuild a CTModels.Solutions.Solution from an all-OptimalControlFlow multi-phase trajectory, reconstructing the control as a CTFlows.MultiPhase._PiecewiseControlLaw over the per-phase laws.

Arguments

  • mpf: The multi-phase Hamiltonian flow.

  • merged: The merged Hamiltonian trajectory over all phases.

  • variable: The variable parameter value (for NonFixed systems).

Returns

See also: CTFlows.MultiPhase._reconstruct_controlled_trajectory, CTFlows.Flows._build_ocp_solution.

_regrid_raw [Function] ​

CTFlows.MultiPhase._regrid_raw Function
julia
_regrid_raw(
    merged,
    grid,
    bounds
) -> CTFlows.Trajectories.VectorFieldTrajectory

Regrid a raw merged trajectory (no control law) on a generated grid, whose plotted curves are the state (and the costate); unchanged otherwise.

_reshape_to_x0 [Function] ​

CTFlows.MultiPhase._reshape_to_x0 Function
julia
_reshape_to_x0(x0::Number, raw) -> Any

Reshape a raw internal final state back to match x0's own declared container type, for inter-phase handoff inside a multi-phase state flow.

Notes

This is deliberately not CTFlows.Systems._coerce_state: that function also collapses a length-1 AbstractVector/SVector to a scalar (the "1-D = scalar" convention, issue #357), which is the right call for a user-facing accessor but wrong for this internal handoff — it would silently turn a length-1-vector-sourced multi-phase state into a scalar mid-chain, producing a phase 2 segment with a different x0 container type than phase 1's, which CTSolvers.Integrators.merge cannot concatenate. A bare Number x0 still collapses the raw result (needed because some flows, e.g. Flow(ocp, law), may integrate on an internally-promoted vector even when the caller declared a scalar x0); any AbstractVector/AbstractMatrix x0, length-1 included, is returned as-is.

julia
_reshape_to_x0(x0, raw) -> Any

Fallback for AbstractVector/AbstractMatrix x0: return raw unchanged.

Unlike the Number method, no collapsing is needed — the container type already matches what CTSolvers.Integrators.merge expects.

_right_law [Function] ​

CTFlows.MultiPhase._right_law Function
julia
_right_law(
    pl::CTFlows.MultiPhase._PiecewiseControlLaw,
    i::Integer
) -> Any

Return the law of the phase that starts at the i-th switching time: the law that gives the right limit of the control there.

_shared_ocp [Function] ​

CTFlows.MultiPhase._shared_ocp Function
julia
_shared_ocp(phases) -> Any

Return the OCP shared by every phase. Flow(fc, law) phases carry no OCP (nothing), which compare equal under ===.

Arguments

  • phases: The tuple of phase flows (each carrying an ocp field).

Returns

  • The single OCP object (or nothing) common to all phases.

Throws

_sub [Function] ​

CTFlows.MultiPhase._sub Function
julia
_sub(
    mpf::CTFlows.MultiPhase.MultiPhaseFlow,
    r::UnitRange{Int64}
) -> CTFlows.MultiPhase.MultiPhaseFlow

The multi-phase flow made of the phases r of mpf (a range of consecutive phases), with the switching times and jumps between them: the flow of the phases met by a horizon, or integrated before an early stop. It is mpf itself when r covers every phase.

Arguments

  • mpf::MultiPhaseFlow: The multi-phase flow.

  • r::UnitRange{Int}: The phases kept, 1 ≤ first(r) ≤ last(r) ≤ n_phases(mpf).

Returns

  • MultiPhaseFlow: the flow of the phases r.

See also: CTFlows.MultiPhase._phase_plan.

_switching_time_eltype [Function] ​

CTFlows.MultiPhase._switching_time_eltype Function
julia
_switching_time_eltype(
    _::Type{Real},
    _::Type{B},
    _::Type{Real}
) -> Type

Return the concrete common element type for switching times from two flows and a new time.

The empty switching-time vector returned by a single-phase flow has element type Real, so vcat alone would promote a concrete switching-time vector to Vector{Real}.


From CTFlows.TrajectoryPlots ​

_BUILD_KEYS [Constant] ​

CTFlows.TrajectoryPlots._BUILD_KEYS Constant

Keyword-argument names consumed by build_figure; every other keyword a user passes to plot(sol; …) is forwarded to the CTBase.Plotting rendering backend.

_SWITCHING_STYLE [Constant] ​

CTFlows.TrajectoryPlots._SWITCHING_STYLE Constant

Default style of the vertical lines at the switching times: dashed black lines behind the curves, as the initial/final time markers of a CTModels.Solution plot.

_assemble [Function] ​

CTFlows.TrajectoryPlots._assemble Function
julia
_assemble(
    sol,
    panels,
    placement;
    layout,
    time,
    vlines,
    annotations
)

Lower each panel and assemble the CTBase.Plotting layout tree from (layout, placement):

  • :group → one cell per panel, laid out in a horizontal row;

  • :split, :paired → one column per panel (components stacked), columns side by side (e.g. state | costate) when they have equal heights;

  • :split, :stacked → all component cells in a single vertical column.

vlines are drawn in every cell; annotations[k] are the texts of the k-th panel. A lone panel needs no combinator. An invalid layout / time is reported by CTBase.Plotting.lower as a CTBase.Exceptions.IncorrectArgument.

_check_jumps [Function] ​

CTFlows.TrajectoryPlots._check_jumps Function
julia
_check_jumps(jumps::Symbol)

Check the drawing of the jumps: :segment or :none.

Throws

  • CTBase.Exceptions.IncorrectArgument: for any other value.

_check_phase_labels [Function] ​

CTFlows.TrajectoryPlots._check_phase_labels Function
julia
_check_phase_labels(phase_labels::Symbol)

Check the placement of the phase labels: :control, :all or :none.

Throws

  • CTBase.Exceptions.IncorrectArgument: for any other value.

_control_name [Function] ​

CTFlows.TrajectoryPlots._control_name Function
julia
_control_name(sol) -> String

Name of the control as a whole (for the label of its norm): from the OCP model, else "u".

_control_names [Function] ​

CTFlows.TrajectoryPlots._control_names Function
julia
_control_names(sol, m) -> Any

Names of the m control components: from the OCP model when the trajectory carries one, else generated (u, u₁, …).

_control_panel [Function] ​

CTFlows.TrajectoryPlots._control_panel Function
julia
_control_panel(
    sol,
    ts,
    control::Symbol,
    style::NamedTuple;
    connect
) -> CTBase.Plotting.Panel

The control panel: control(sol) sampled at ts, drawn as its components (control=:components), its norm (:norm) or both (:all).

Throws

  • CTBase.Exceptions.IncorrectArgument: for any other value of control.

_control_shown [Function] ​

CTFlows.TrajectoryPlots._control_shown Function
julia
_control_shown(description, control_style) -> Bool

Return whether the control panel is drawn: :control is in the description and the control is not styled :none.

_costate_panel [Function] ​

CTFlows.TrajectoryPlots._costate_panel Function
julia
_costate_panel(
    sol,
    ts,
    style::NamedTuple;
    state_shown,
    connect
)

The costate panel: costate(sol) sampled at ts. When the state is drawn alongside (paired columns), the state labels name the rows, so the costate curves carry no label, as in CTModels.

_default_description [Function] ​

CTFlows.TrajectoryPlots._default_description Function
julia
_default_description(
    _::CTFlows.Trajectories.AbstractVectorFieldTrajectory
) -> Tuple{Symbol, Symbol}

Contract: the default panels for a trajectory when the user gives no description. Defined on the abstract trajectory types and specialized where a subtype exposes more (a StateFlowTrajectory also has a control).

  • AbstractVectorFieldTrajectory → (:state,)

  • StateFlowTrajectory → (:state, :control)

  • AbstractHamiltonianVectorFieldTrajectory → (:state, :costate)

_gen_names [Function] ​

CTFlows.TrajectoryPlots._gen_names Function
julia
_gen_names(sym::AbstractString, n::Integer) -> Any

Generated component names, used when the trajectory carries no model: ["x"] for one component, ["x₁", "x₂", …] otherwise.

_limits [Function] ​

CTFlows.TrajectoryPlots._limits Function
julia
_limits(sol, component::Symbol) -> Tuple{Any, Any}

Return the limits of component at the switching times of sol as the (left, right) matrices of CTBase.Plotting.splice_jumps: one row per switching time, one column per component. They are read with CTFlows.Trajectories.left_limit and CTFlows.Trajectories.right_limit.

_nothing_to_plot [Function] ​

CTFlows.TrajectoryPlots._nothing_to_plot Function
julia
_nothing_to_plot()

Throw a CTBase.Exceptions.IncorrectArgument for the empty case: an empty description, or every drawn group styled :none, leaves nothing to plot.

_panels [Function] ​

CTFlows.TrajectoryPlots._panels Function
julia
_panels(
    sol,
    description;
    control,
    state_style,
    costate_style,
    control_style,
    connect
)

Turn a trajectory and a cleaned description into (times, panels, placement). Panels are emitted in the canonical order state → costate → control; a group whose style is :none is skipped. placement is :paired when both state and costate are drawn (they sit side by side), otherwise :stacked.

_phase_label_panels [Function] ​

CTFlows.TrajectoryPlots._phase_label_panels Function
julia
_phase_label_panels(
    phase_labels::Symbol,
    n::Int64,
    control_shown::Bool
) -> Vector{Bool}

Return, for each of the n drawn panels, whether it receives the phase labels: every panel for phase_labels = :all, none for :none; for :control, the control panel when it is drawn (the last panel, see CTFlows.TrajectoryPlots._panels), the first panel otherwise.

_rownorm [Function] ​

CTFlows.TrajectoryPlots._rownorm Function
julia
_rownorm(row) -> Any

Euclidean norm of a row, written out to avoid a LinearAlgebra dependency.

_sample [Function] ​

CTFlows.TrajectoryPlots._sample Function
julia
_sample(f, ts) -> Any

Sample a callable f over the times ts into an (n_times × n_components) matrix. A scalar (1-D) and a vector-valued f are handled alike.

_series_defaults [Function] ​

CTFlows.TrajectoryPlots._series_defaults Function
julia
_series_defaults() -> @NamedTuple{linewidth::Int64}

The defaults of every curve drawn from a trajectory: a line width of 2, as in CTModels.

They go to the defaults of the panels, apart from the group style of the user (state_style, …), so that the backend applies the precedence of CTBase: defaults < keywords of plot < group style. plot(sol; linewidth=3) overrides the width of 2, state_style=(linewidth=4,) overrides both.

_spliced_samples [Function] ​

CTFlows.TrajectoryPlots._spliced_samples Function
julia
_spliced_samples(
    sol,
    ts::AbstractVector,
    M::AbstractMatrix,
    component::Symbol;
    connect
) -> Tuple{Any, Any}

Insert the left and right limits of component at the switching times of sol into the samples (ts, M) of that component, with CTBase.Plotting.splice_jumps: a jump is drawn as a vertical segment, or, with connect = false, the curve is broken between the two limits. The samples are returned unchanged when the trajectory has no switching time.

Returns

  • (ts, M): the time grid (each switching time twice) and the matrix of samples.

_state_names [Function] ​

CTFlows.TrajectoryPlots._state_names Function
julia
_state_names(sol, n) -> Any

Names of the n state components: from the OCP model when the trajectory carries one, else generated (x, x₁, …).

_state_panel [Function] ​

CTFlows.TrajectoryPlots._state_panel Function
julia
_state_panel(
    sol,
    ts,
    style::NamedTuple;
    connect
) -> CTBase.Plotting.Panel

The state panel: state(sol) sampled at ts, one curve per component, with the jumps at the switching times drawn as vertical segments.

_sub [Function] ​

CTFlows.TrajectoryPlots._sub Function
julia
_sub(i::Integer) -> String

Subscript form of a component index: 1 → "₁", 12 → "₁₂".

_time_name [Function] ​

CTFlows.TrajectoryPlots._time_name Function
julia
_time_name(sol) -> String

Time-axis name for a trajectory: the OCP's time name when available, else "t".

_traj_model [Function] ​

CTFlows.TrajectoryPlots._traj_model Function
julia
_traj_model(sol) -> Any

The OCP model a trajectory carries, or nothing. Only a StateFlowTrajectory built from an OCP (Flow(ocp, law)) carries one.

build_figure [Function] ​

CTFlows.TrajectoryPlots.build_figure Function
julia
build_figure(
    sol,
    description::Symbol...;
    layout,
    control,
    time,
    state_style,
    costate_style,
    control_style,
    switching_style,
    phase_labels,
    phase_labels_style,
    jumps,
    size
) -> CTBase.Plotting.Figure

Build the CTBase.Plotting.Figure for a CTFlows trajectory sol and a description.

Resolves the description (the _default_description contract default when none is given), builds the state / costate / control CTBase.Plotting.Panels via the semantic accessors, and assembles the layout tree. This is the single backend-agnostic entry point: the CTFlowsPlots / CTFlowsMakie extensions call it and render the result through a CTBase.Plotting.render backend.

Arguments

  • sol: a VectorFieldTrajectory, HamiltonianVectorFieldTrajectory or StateFlowTrajectory.

  • description: any of :state, :costate, :control; empty ⇒ the per-type default.

Keyword arguments

  • layout::Symbol = :split: :split (one subplot per component) or :group.

  • control::Symbol = :components: :components, :norm or :all.

  • time::Symbol = :default: :default or :normalize / :normalise.

  • state_style / costate_style / control_style: a NamedTuple of attributes or :none to hide the group.

  • switching_style = NamedTuple(): style of the vertical lines at the switching times of a multi-phase trajectory (dashed black lines by default, merged with this style); :none hides them.

  • phase_labels::Symbol = :control: where to write the phase labels (see CTFlows.Trajectories.phase_labels): :control (the control panel, or the first drawn panel when the control is not drawn), :all (every panel) or :none.

  • phase_labels_style::NamedTuple = NamedTuple(): style of the labels (color, fontsize, halign, valign).

  • jumps::Symbol = :segment: a jump at a switching time is drawn as a vertical segment from the left to the right limit (:segment), or the curve is broken between the two limits (:none), so that no segment suggests values the trajectory does not take.

  • size: figure size; nothing defers to the engine heuristic.

At every switching time, a jump of the state, costate or control is drawn as a vertical segment, from the left to the right limit, or as a break in the curve with jumps=:none. The whole trajectory is one curve per component, so it keeps one color across phases.

Returns

  • CTBase.Plotting.Figure.

Throws

  • CTBase.Exceptions.IncorrectArgument: nothing to draw (empty description, or every drawn group styled :none); an invalid control / layout / time / phase_labels / jumps.

clean [Function] ​

CTFlows.TrajectoryPlots.clean Function
julia
clean(description) -> Tuple

Standardize a description tuple: map plural forms to singular and drop duplicates. The canonical symbols are :state, :costate, :control.

split_plot_kwargs [Function] ​

CTFlows.TrajectoryPlots.split_plot_kwargs Function
julia
split_plot_kwargs(kwargs) -> Tuple{NamedTuple, NamedTuple}

Split the user keyword arguments of plot(sol; …) into the pair (build, render): build holds the _BUILD_KEYS consumed by build_figure, render holds everything else (forwarded to the CTBase.Plotting backend). The size keyword is handled explicitly by the extensions and is not part of _BUILD_KEYS.


From CTFlows.Systems ​

HVFIpFunctor [Struct] ​

CTFlows.Systems.HVFIpFunctor Type
julia
struct HVFIpFunctor{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend} <: Function

In-place Hamiltonian vector field functor: writes X_H = (∂H/∂p, -∂H/∂x) into the preallocated buffers dx, dp.

Fields

  • h::H: the scalar Hamiltonian.

  • backend::B: the AD backend used to compute the gradients.

Call signatures

Dispatched on the Hamiltonian's time/variable-dependence traits:

  • Autonomous/Fixed — (dx, dp, x, p) -> nothing

  • NonAutonomous/Fixed — (dx, dp, t, x, p) -> nothing

  • Autonomous/NonFixed — (dx, dp, x, p, v; dpv=nothing, variable_costate=false) -> nothing

  • NonAutonomous/NonFixed — (dx, dp, t, x, p, v; dpv=nothing, variable_costate=false) -> nothing

When variable_costate=true, the preallocated buffer dpv (matching the shape of v) is filled with -∂H/∂v; it must be provided or a PreconditionError is thrown.

Throws

  • Exceptions.PreconditionError: when variable_costate=true and dpv is nothing.

See also: CTFlows.Systems.HVFOoPFunctor, CTFlows.Systems.hamiltonian_vector_field.

HVFOoPFunctor [Struct] ​

CTFlows.Systems.HVFOoPFunctor Type
julia
struct HVFOoPFunctor{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend} <: Function

Out-of-place Hamiltonian vector field functor: computes X_H = (∂H/∂p, -∂H/∂x) from a scalar Hamiltonian by automatic differentiation, allocating and returning the result.

Fields

  • h::H: the scalar Hamiltonian.

  • backend::B: the AD backend used to compute the gradients.

Call signatures

Dispatched on the Hamiltonian's time/variable-dependence traits:

  • Autonomous/Fixed — (x, p) -> (∂p, -∂x)

  • NonAutonomous/Fixed — (t, x, p) -> (∂p, -∂x)

  • Autonomous/NonFixed — (x, p, v; variable_costate=false) -> (∂p, -∂x), or (∂p, -∂x, -∂v) when variable_costate=true

  • NonAutonomous/NonFixed — (t, x, p, v; variable_costate=false) -> (∂p, -∂x), or (∂p, -∂x, -∂v) when variable_costate=true

See also: CTFlows.Systems.HVFIpFunctor, CTFlows.Systems.hamiltonian_vector_field.

HamIpAugRHS [Struct] ​

CTFlows.Systems.HamIpAugRHS Type
julia
struct HamIpAugRHS{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPHamRHS

In-place augmented RHS functor for Hamiltonian systems with variable costate.

This functor extends the standard Hamiltonian equations to include the variable costate evolution, used in sensitivity analysis and optimal control:

julia
ẋ =  ∂H/∂p
ṗ = -∂H/∂x
ṽ = -∂H/∂v

The state vector is augmented as [x; p; v] where v is the variable costate.

Fields

  • h::H: The Hamiltonian function (any Data.AbstractHamiltonian).

  • backend::B: The AD backend for gradient computation.

  • n_x::Int: State dimension (number of state variables).

  • n_v::Int: Variable dimension.

  • cache::C: Pre-allocated AD cache (or nothing for systems without AD).

Call Signature

julia
(f::HamIpAugRHS)(du, u, λ, t)
  • du: Output vector (mutated in-place).

  • u: Augmented state vector [x; p; v].

  • λ: ODE parameters containing the variable value.

  • t: Time (for non-autonomous systems).

Notes

  • Supports batch mode with matrix inputs (checks batch size compatibility).

  • The AD cache is embedded in the functor for better composability.

  • This functor is created by build_rhs_augmented for Hamiltonian systems.

See also: CTFlows.Systems.HamIpRHS, CTFlows.Systems.HamOoPRHS.

HamIpRHS [Struct] ​

CTFlows.Systems.HamIpRHS Type
julia
struct HamIpRHS{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPHamRHS

In-place RHS functor for Hamiltonian systems with automatic differentiation.

This functor wraps a Hamiltonian and AD backend to compute the Hamiltonian gradient in-place, following the canonical Hamiltonian equations:

julia
ẋ =  ∂H/∂p
ṗ = -∂H/∂x

Fields

  • h::H: The Hamiltonian function (any Data.AbstractHamiltonian).

  • backend::B: The AD backend for gradient computation.

  • N::Int: State dimension (number of state variables).

  • cx::CX: State conversion function.

  • cp::CP: Costate conversion function.

  • cache::C: Pre-allocated AD cache (or nothing for systems without AD).

Call Signature

julia
(f::HamIpRHS)(du, u, λ, t)
  • du: Output vector (mutated in-place).

  • u: State vector [x; p] (concatenated state and costate).

  • λ: ODE parameters containing the variable value.

  • t: Time (for non-autonomous systems).

Notes

  • The AD cache is embedded in the functor for better composability.

  • This functor is created by build_rhs for Hamiltonian systems.

See also: CTFlows.Systems.HamOoPRHS, CTFlows.Systems.HamIpAugRHS.

HamOoPRHS [Struct] ​

CTFlows.Systems.HamOoPRHS Type
julia
struct HamOoPRHS{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPHamRHS

Out-of-place RHS functor for Hamiltonian systems with automatic differentiation.

This functor wraps a Hamiltonian and AD backend to compute the Hamiltonian gradient out-of-place, following the canonical Hamiltonian equations:

julia
ẋ =  ∂H/∂p
ṗ = -∂H/∂x

Fields

  • h::H: The Hamiltonian function (any Data.AbstractHamiltonian).

  • backend::B: The AD backend for gradient computation.

  • N::Int: State dimension (number of state variables).

  • cx::CX: State conversion function.

  • cp::CP: Costate conversion function.

  • cache::C: Pre-allocated AD cache (or nothing for systems without AD).

Call Signature

julia
(f::HamOoPRHS)(u, λ, t) -> du
  • u: State vector [x; p] (concatenated state and costate).

  • λ: ODE parameters containing the variable value.

  • t: Time (for non-autonomous systems).

  • Returns: Output vector du = [∂p; -∂x].

Notes

  • The AD cache is embedded in the functor for better composability.

  • This functor is created by build_oop_rhs for Hamiltonian systems.

See also: CTFlows.Systems.HamIpRHS, CTFlows.Systems.HamIpAugRHS.

IPHVFIpAugRHS [Struct] ​

CTFlows.Systems.IPHVFIpAugRHS Type
julia
IPHVFIpAugRHS{F,TD,VD} <: AbstractIPHVFRHS

In-place augmented RHS functor for an in-place HamiltonianVectorField.

Wraps an in-place HamiltonianVectorField and provides an in-place interface for the augmented system (state + costate + variable costate).

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.InPlace}: The wrapped vector field.

  • n_x::Int: State dimension.

  • n_v::Int: Variable costate dimension.

Call signature

(f::IPHVFIpAugRHS)(du, u, λ, t) -> nothing

IPHVFIpRHS [Struct] ​

CTFlows.Systems.IPHVFIpRHS Type
julia
IPHVFIpRHS{F,TD,VD,CX,CP} <: AbstractIPHVFRHS

In-place RHS functor for an in-place HamiltonianVectorField.

Wraps an in-place HamiltonianVectorField and provides an in-place interface by directly calling the function with pre-allocated buffers.

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.InPlace}: The wrapped vector field.

  • N::Int: State dimension.

  • cx::CX: Coercion function for state (e.g., identity or only).

  • cp::CP: Coercion function for costate (e.g., identity or only).

Call signature

(f::IPHVFIpRHS)(du, u, λ, t) -> nothing

IPHVFOoPAugRHS [Struct] ​

CTFlows.Systems.IPHVFOoPAugRHS Type
julia
IPHVFOoPAugRHS{F,TD,VD} <: AbstractIPHVFRHS

In-place augmented RHS functor for an out-of-place HamiltonianVectorField.

Wraps an out-of-place HamiltonianVectorField and provides an in-place interface for the augmented system (state + costate + variable costate).

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: The wrapped vector field.

  • n_x::Int: State dimension.

  • n_v::Int: Variable costate dimension.

Call signature

(f::IPHVFOoPAugRHS)(du, u, λ, t) -> nothing

IPHVFOoPRHS [Struct] ​

CTFlows.Systems.IPHVFOoPRHS Type
julia
IPHVFOoPRHS{F,TD,VD,CX,CP} <: AbstractIPHVFRHS

In-place RHS functor for an out-of-place HamiltonianVectorField.

Wraps an out-of-place HamiltonianVectorField and provides an in-place interface by allocating the result into the pre-allocated du buffer.

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: The wrapped vector field.

  • N::Int: State dimension.

  • cx::CX: Coercion function for state (e.g., identity or only).

  • cp::CP: Coercion function for costate (e.g., identity or only).

Call signature

(f::IPHVFOoPRHS)(du, u, λ, t) -> nothing

IPPseudoHVFIpAugRHS [Struct] ​

CTFlows.Systems.IPPseudoHVFIpAugRHS Type
julia
struct IPPseudoHVFIpAugRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHS

In-place augmented RHS functor for an in-place PseudoHamiltonianVectorField with variable costate. Extends CTFlows.Systems.IPPseudoHVFIpRHS with ṗv = -∂H̃/∂v (supplied directly by h̃vf at u_ = law(t,x,p,v), no AD). The augmented state is [x; p; pv].

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • n_x::Int: state dimension.

  • n_v::Int: variable dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::IPPseudoHVFIpAugRHS)(du, u, λ, t) -> nothing

See also: CTFlows.Systems.IPPseudoHVFOoPAugRHS.

IPPseudoHVFIpRHS [Struct] ​

CTFlows.Systems.IPPseudoHVFIpRHS Type
julia
struct IPPseudoHVFIpRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHS

In-place RHS functor for an in-place PseudoHamiltonianVectorField. Evaluates the feedback control u_ = law(t, x, p, v) and then calls the wrapped in-place vector field directly with the pre-allocated dx/dp buffers.

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • N::Int: state dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::IPPseudoHVFIpRHS)(du, u, λ, t) -> nothing

See also: CTFlows.Systems.IPPseudoHVFOoPRHS.

IPPseudoHVFOoPAugRHS [Struct] ​

CTFlows.Systems.IPPseudoHVFOoPAugRHS Type
julia
struct IPPseudoHVFOoPAugRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHS

In-place augmented RHS functor for an out-of-place PseudoHamiltonianVectorField with variable costate. Evaluates u_ = law(t, x, p, v), then calls h̃vf(t, x, p, u_, v; variable_costate=true) to get (dx, dp, dpv). The augmented state is [x; p; pv].

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • n_x::Int: state dimension.

  • n_v::Int: variable dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::IPPseudoHVFOoPAugRHS)(du, u, λ, t) -> nothing

See also: CTFlows.Systems.IPPseudoHVFIpAugRHS.

IPPseudoHVFOoPRHS [Struct] ​

CTFlows.Systems.IPPseudoHVFOoPRHS Type
julia
struct IPPseudoHVFOoPRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHS

In-place RHS functor for an out-of-place PseudoHamiltonianVectorField. Evaluates the feedback control u_ = law(t, x, p, v) and then computes (dx, dp) = h̃vf(t, x, p, u_, v) directly (no AD), writing the result into the pre-allocated du buffer.

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • N::Int: state dimension.

  • cx::CX: coercion function for state (e.g., identity or _safe_only).

  • cp::CP: coercion function for costate (e.g., identity or _safe_only).

Call signature

(f::IPPseudoHVFOoPRHS)(du, u, λ, t) -> nothing

See also: CTFlows.Systems.OoPPseudoHVFOoPRHS, CTFlows.Systems.IPPseudoHVFIpRHS.

IPVFIpRHS [Struct] ​

CTFlows.Systems.IPVFIpRHS Type
julia
IPVFIpRHS{F,TD,VD,CX} <: AbstractIPRHS

In-place RHS functor for an in-place VectorField.

Wraps an in-place VectorField and provides an in-place interface by directly calling the VectorField.

Fields

  • vf::Data.VectorField{F,TD,VD,Traits.InPlace}: The wrapped VectorField

  • cx::CX: coercion applied to the state before calling vf.

Call signature

(f::IPVFIpRHS)(du, u, λ, t) -> nothing

IPVFOoPRHS [Struct] ​

CTFlows.Systems.IPVFOoPRHS Type
julia
IPVFOoPRHS{VF<:Data.AbstractVectorField,CX} <: AbstractIPRHS

In-place RHS functor for an out-of-place vector field.

Wraps an out-of-place CTBase.Data.AbstractVectorField and provides an in-place interface by allocating the result into the pre-allocated du buffer.

Fields

  • vf::VF: the wrapped out-of-place vector field (any Data.AbstractVectorField).

  • cx::CX: coercion applied to the state before calling vf (_safe_only for a 1-D state, identity otherwise) — see CTFlows.Systems._coerce_state.

Call signature

(f::IPVFOoPRHS)(du, u, λ, t) -> nothing

Notes

  • du is always the pre-allocated buffer supplied by the integrator, matching u's actual (uncoerced) shape — broadcasting a coerced-scalar result into it is safe regardless of cx (the "in-place buffer stays a vector" exception, ct-conventions DIM2).

OoPHVFIpFinalizeRHS [Struct] ​

CTFlows.Systems.OoPHVFIpFinalizeRHS Type
julia
OoPHVFIpFinalizeRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHS

Out-of-place RHS functor for an in-place HamiltonianVectorField with type conversion.

Wraps an in-place HamiltonianVectorField and provides an out-of-place interface that converts the result to match the input type (e.g., Vector → SVector).

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.InPlace}: The wrapped vector field.

  • N::Int: State dimension.

  • cx::CX: Coercion function for state (e.g., identity or only).

  • cp::CP: Coercion function for costate (e.g., identity or only).

Call signature

(f::OoPHVFIpFinalizeRHS)(u, λ, t) -> du

OoPHVFIpRHS [Struct] ​

CTFlows.Systems.OoPHVFIpRHS Type
julia
OoPHVFIpRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHS

Out-of-place RHS functor for an in-place HamiltonianVectorField.

Wraps an in-place HamiltonianVectorField and provides an out-of-place interface by allocating temporary buffers on each call.

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.InPlace}: The wrapped vector field.

  • N::Int: State dimension.

  • cx::CX: Coercion function for state (e.g., identity or only).

  • cp::CP: Coercion function for costate (e.g., identity or only).

Call signature

(f::OoPHVFIpRHS)(u, λ, t) -> du

OoPHVFOoPRHS [Struct] ​

CTFlows.Systems.OoPHVFOoPRHS Type
julia
OoPHVFOoPRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHS

Out-of-place RHS functor for an out-of-place HamiltonianVectorField.

Wraps an out-of-place HamiltonianVectorField and provides an out-of-place interface by directly calling the function and concatenating the results.

Fields

  • hvf::HamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: The wrapped vector field.

  • N::Int: State dimension.

  • cx::CX: Coercion function for state (e.g., identity or only).

  • cp::CP: Coercion function for costate (e.g., identity or only).

Call signature

(f::OoPHVFOoPRHS)(u, λ, t) -> du

OoPPseudoHVFIpFinalizeRHS [Struct] ​

CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS Type
julia
struct OoPPseudoHVFIpFinalizeRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHS

Out-of-place RHS functor for an in-place PseudoHamiltonianVectorField, converting the result back to the input array type (e.g. Vector → SVector) for immutable initial conditions.

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • N::Int: state dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::OoPPseudoHVFIpFinalizeRHS)(u, λ, t) -> du

See also: CTFlows.Systems.OoPPseudoHVFIpRHS.

OoPPseudoHVFIpRHS [Struct] ​

CTFlows.Systems.OoPPseudoHVFIpRHS Type
julia
struct OoPPseudoHVFIpRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHS

Out-of-place RHS functor for an in-place PseudoHamiltonianVectorField; allocates temporary dx/dp buffers on each call via similar.

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • N::Int: state dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::OoPPseudoHVFIpRHS)(u, λ, t) -> du

See also: CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS.

OoPPseudoHVFOoPRHS [Struct] ​

CTFlows.Systems.OoPPseudoHVFOoPRHS Type
julia
struct OoPPseudoHVFOoPRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHS

Out-of-place RHS functor for an out-of-place PseudoHamiltonianVectorField; see CTFlows.Systems.IPPseudoHVFOoPRHS for the computation. Returns vcat(dx, dp).

Fields

  • h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.

  • law::L: the dynamic closed-loop control law u(t, x, p, v).

  • N::Int: state dimension.

  • cx::CX: coercion function for state.

  • cp::CP: coercion function for costate.

Call signature

(f::OoPPseudoHVFOoPRHS)(u, λ, t) -> du

See also: CTFlows.Systems.IPPseudoHVFOoPRHS.

OoPVFIpFinalizeRHS [Struct] ​

CTFlows.Systems.OoPVFIpFinalizeRHS Type
julia
OoPVFIpFinalizeRHS{F,TD,VD,CX} <: AbstractOoPRHS

Out-of-place RHS functor for an in-place VectorField with type conversion.

Wraps an in-place VectorField and provides an out-of-place interface that converts the result to match the input type (e.g., Vector → SVector).

Fields

  • vf::Data.VectorField{F,TD,VD,Traits.InPlace}: The wrapped VectorField

  • cx::CX: coercion applied to the state before calling vf.

Call signature

(f::OoPVFIpFinalizeRHS)(u, λ, t) -> du

OoPVFIpRHS [Struct] ​

CTFlows.Systems.OoPVFIpRHS Type
julia
OoPVFIpRHS{F,TD,VD,CX} <: AbstractOoPRHS

Out-of-place RHS functor for an in-place VectorField.

Wraps an in-place VectorField and provides an out-of-place interface by allocating a temporary buffer on each call.

Fields

  • vf::Data.VectorField{F,TD,VD,Traits.InPlace}: The wrapped VectorField

  • cx::CX: coercion applied to the state before calling vf.

Call signature

(f::OoPVFIpRHS)(u, λ, t) -> du

Notes

  • dx = similar(u) already matches u's actual (uncoerced) shape, so no reshaping is needed here even when cx collapses the CALL argument to a scalar — the in-place vf call still writes into the properly-shaped buffer.

OoPVFOoPRHS [Struct] ​

CTFlows.Systems.OoPVFOoPRHS Type
julia
OoPVFOoPRHS{VF<:Data.AbstractVectorField,CX} <: AbstractOoPRHS

Out-of-place RHS functor for an out-of-place vector field.

Wraps an out-of-place CTBase.Data.AbstractVectorField and provides an out-of-place interface by directly calling the vector field.

Fields

  • vf::VF: the wrapped out-of-place vector field (any Data.AbstractVectorField).

  • cx::CX: coercion applied to the state before calling vf.

Call signature

(f::OoPVFOoPRHS)(u, λ, t) -> du

Notes

  • Unlike the Hamiltonian-family out-of-place functors (which always reassemble their return value via vcat of a state and a costate block, safe for either shape), this functor has a single block and nothing to reassemble: when cx collapses u to a scalar for the call, vf may return a bare scalar too, which does not match u's own (uncoerced) container shape. That case is reshaped back explicitly so the returned derivative always matches u's actual type, as SciML's out-of-place interface requires.

__hvf_ad_backend [Function] ​

CTFlows.Systems.__hvf_ad_backend Function
julia
__hvf_ad_backend(

) -> CTBase.Differentiation.DifferentiationInterface{CTBase.Strategies.CPU, CTBase.Strategies.StrategyOptions{NT}} where NT<:NamedTuple

Default AD backend for the hamiltonian_vector_field(h::Data.AbstractHamiltonian; ...) getter.

Returns Differentiation.DifferentiationInterface(), the CPU-default strategy. Callers that need a device-specific backend (e.g. GPU) must build and pass one explicitly — this default is not device-aware.

See also: CTFlows.Systems.hamiltonian_vector_field, CTBase.Differentiation.DifferentiationInterface.

_accessor_hint [Function] ​

CTFlows.Systems._accessor_hint Function
julia
_accessor_hint(
    sys::CTFlows.Systems.AbstractSystem
) -> Tuple{String, String}

Describe what a system holds and which accessors apply to it, as a (got, suggestion) pair of strings for CTFlows.Systems._unavailable.

_aug_assign! [Function] ​

CTFlows.Systems._aug_assign! Function
julia
_aug_assign!(
    du::AbstractVector,
    dx,
    dp,
    dpv,
    n_x::Int64,
    n_v::Int64
)

Assign derivatives to the augmented derivative vector for Hamiltonian systems with variable costate.

The augmented derivative vector has the form [dx; dp; dpv] where:

  • dx is the state derivative (first n_x elements)

  • dp is the costate derivative (next n_x elements)

  • dpv is the variable costate derivative (last n_v elements)

Arguments

  • du::AbstractVector: Augmented derivative vector to fill [dx; dp; dpv].

  • dx: State derivative.

  • dp: Costate derivative.

  • dpv: Variable costate derivative.

  • n_x::Int: State dimension.

  • n_v::Int: Variable dimension.

Returns

  • nothing.

Notes

  • Performs in-place assignment using broadcasting.

  • For matrix inputs, broadcasts over columns.

  • Used internally by CTFlows.Systems.HamIpAugRHS.

See also: CTFlows.Systems._aug_split, CTFlows.Systems.HamIpAugRHS.

julia
_aug_assign!(
    du::AbstractMatrix,
    dx,
    dp,
    dpv,
    n_x::Int64,
    n_v::Int64
)

Matrix variant of CTFlows.Systems._aug_assign!: assigns state, costate, and variable-costate derivatives into the corresponding row-blocks of each column.

See also: CTFlows.Systems._aug_assign!.

_aug_split [Function] ​

CTFlows.Systems._aug_split Function
julia
_aug_split(
    u::AbstractVector,
    n_x::Int64,
    n_v::Int64
) -> Tuple{Any, Any, Any}

Split an augmented state vector into state, costate, and variable costate components.

The augmented state vector has the form [x; p; pv] where:

  • x is the state (first n_x elements)

  • p is the costate (next n_x elements)

  • pv is the variable costate (last n_v elements)

Arguments

  • u::AbstractVector: Augmented state vector [x; p; pv].

  • n_x::Int: State dimension.

  • n_v::Int: Variable dimension.

Returns

  • Tuple: (x, p, pv) where each component is a @view slice.

Notes

  • Always returns views (never scalars), consistent with _ham_split.

  • For matrix inputs, returns column views.

  • Used internally by CTFlows.Systems.HamIpAugRHS.

See also: CTFlows.Systems._aug_assign!, CTFlows.Systems.HamIpAugRHS.

julia
_aug_split(
    u::AbstractMatrix,
    n_x::Int64,
    n_v::Int64
) -> Tuple{Any, Any, Any}

Matrix variant of CTFlows.Systems._aug_split: splits each column of u into state, costate, and variable-costate row-block views.

See also: CTFlows.Systems._aug_split.

_buffer_like [Function] ​

CTFlows.Systems._buffer_like Function
julia
_buffer_like(
    template::AbstractArray,
    _::Type{T},
    n::Int64
) -> Any

Allocate an uninitialised length-n buffer of eltype T in template's array type.

Arguments

  • template: an array or scalar whose type determines the buffer's array backend.

  • T: the element type of the buffer.

  • n::Int: the length of the buffer.

Returns

  • For template::AbstractArray: similar(template, T, n) — same array backend as template.

  • For any other template (e.g. Number): Vector{T}(undef, n) — a host vector.

Notes

  • The OCP right-hand sides fill a length-n_x buffer through the in-place dynamics dynamics!(r, t, x, u, v), plus empty u/v buffers for control-free / Fixed problems. Allocating those as a host Vector pins the whole OCP hot path to the CPU; deriving them from the state instead keeps the buffer on whichever device the state already lives on.

  • The Number fallback is required, not defensive: under the "1-D = scalar" convention the coerced state is a scalar (via CTFlows.Systems._safe_only for a declared dimension of 1), and similar is undefined for Number. A scalar state is a host scalar even on GPU, so a host Vector is the correct buffer there.

  • This generalises the same isa AbstractArray branch already used for pv0 in CTFlows.Flows augmented initial conditions.

  • Dispatch is on the value actually received at the call site, so CPU behaviour is byte-for-byte unchanged and no run-time type test enters the hot path.

See also: CTFlows.Systems._device_like, CTFlows.Systems._safe_only.

julia
_buffer_like(_, _::Type{T}, n::Int64) -> Any

Scalar fallback: allocate a host Vector{T}(undef, n) — similar is undefined for Number.

See also: CTFlows.Systems._buffer_like.

julia
_buffer_like(
    template::AbstractMatrix,
    _::Type{T},
    n::Int64
) -> Any

Allocate an uninitialised n × batch buffer of eltype T when template is itself a batched Matrix state (each column an independent trajectory) — batch = size(template, 2).

More specific than the AbstractArray method above, so it is selected automatically for a Matrix/MMatrix/SMatrix template; no call site needs to change.

See also: CTFlows.Systems._buffer_like.

_check_aug_batch_compat [Function] ​

CTFlows.Systems._check_aug_batch_compat Function

Check batch size compatibility for augmented Hamiltonian RHS with matrix inputs.

When using batch mode with matrix inputs, ensures that the state matrix u and variable matrix v have compatible batch sizes (same number of columns).

Arguments

  • u::AbstractMatrix: State matrix with shape (n, batch_size).

  • v::AbstractMatrix: Variable matrix with shape (m, batch_size).

Returns

  • nothing if batch sizes match.

Throws

  • Exceptions.PreconditionError: If size(u, 2) ≠ size(v, 2).

Notes

See also: CTFlows.Systems.HamIpAugRHS, CTFlows.Systems._aug_split.

No-op version of batch compatibility check for non-matrix inputs.

Arguments

  • u: State input (vector or scalar).

  • v: Variable input (vector or scalar).

Returns

  • nothing.

Notes

_coerce_state [Function] ​

CTFlows.Systems._coerce_state Function
julia
_coerce_state(
    _::Number
) -> typeof(CTFlows.Systems._safe_only)

Return the coercion applied to a 1-D quantity (state, costate, variable costate, control) so that it is represented as a scalar when it has length 1, and left untouched otherwise.

Methods

  • _coerce_state(::Number) = _safe_only

  • _coerce_state(::AbstractMatrix) = identity

  • _coerce_state(x::AbstractVector) = length(x) == 1 ? _safe_only : identity

This enforces the ecosystem convention "a 1-dimensional quantity is a scalar": both 2.0 and [2.0] collapse to the scalar 2.0 via _safe_only, regardless of how the user supplied the initial condition. Vectors of length ≥ 2 and matrices (batch mode) are left untouched via identity.

Notes

  • Scope (issue control-toolbox/CTFlows.jl#357): applied on every control-toolbox-sourced flow — HamiltonianSystem, HamiltonianVectorFieldSystem, PseudoHamiltonianSystem, ConstrainedPseudoHamiltonianSystem, PseudoHamiltonianVectorFieldSystem, VectorFieldSystem, and CTFlowsSciMLFlows.SciMLFunctionSystem (which shares VectorFieldSystem's Systems/Trajectories dispatch). CTFlowsSciMLFlows.SciMLProblemFlow (built directly from an SciMLBase.AbstractODEProblem) genuinely bypasses this dispatch (remake+solve only) and stays shape-preserving instead — it never calls _coerce_state.

  • Differs from CTBase.Core.make_coerce in that a length-1 vector also collapses to a scalar (_safe_only, the GPU-safe only), not only a bare Number.

See also: CTFlows.Systems._safe_only.

julia
_coerce_state(_::AbstractMatrix) -> typeof(identity)

Batched Matrix states are always left untouched (identity): batch mode never collapses to a scalar.

See also: CTFlows.Systems._coerce_state.

julia
_coerce_state(
    x::AbstractVector
) -> Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}

Vector states: _safe_only for length 1 (1-D = scalar convention), identity otherwise.

See also: CTFlows.Systems._coerce_state, CTFlows.Systems._safe_only.

julia
_coerce_state(
    _::CTBase.Core.NotProvidedType
) -> typeof(identity)

No-op fallback for when the initial state is unknown (Core.NotProvided), e.g. a trajectory container built directly from a raw integration result without going through a Configs.AbstractConfig (tests, low-level plumbing). Safe default: apply no coercion rather than guess.

_device_like [Function] ​

CTFlows.Systems._device_like Function
julia
_device_like(_::AbstractArray, src) -> Number

Return src in a form that can be broadcast into dst without a device/host mismatch.

Arguments

  • dst: the destination array whose device determines the required location.

  • src: the source block to broadcast into dst.

Returns

  • src itself when it is already compatible with dst (host/host, device/device, or scalar).

  • A device-resident copy of src when dst is a device array and src is a host array.

Notes

  • Augmented Hamiltonian flows split into [∂p; -∂x; -∂pv]; on GPU the state blocks ∂x/∂p are device-resident but ∂pv = -∂H/∂v is host (the variable v transits host-side), so broadcasting it into a device du slice wraps a non-isbits host Vector in a Broadcasted and fails to compile (GPUCompiler.KernelError).

  • _device_like copies only that host block onto the device matching dst; on host, and for already-device blocks, it is the identity (no copy).

  • Dispatch is on the array actually received at the call site, so CPU behaviour is byte-for-byte unchanged and only the degenerate device-dst/host-src case pays a tiny O(n_v) H2D copy.

  • Backend-agnostic (GPUArraysCore.AbstractGPUArray covers CUDA/AMDGPU/Metal).

See also: CTFlows.Systems._aug_assign!, CTFlows.Systems._safe_only.

julia
_device_like(
    _::GPUArraysCore.AbstractGPUArray,
    src::Number
) -> Number

Scalar source is always compatible with any destination: return src as-is.

See also: CTFlows.Systems._device_like.

julia
_device_like(
    _::GPUArraysCore.AbstractGPUArray,
    src::GPUArraysCore.AbstractGPUArray
) -> GPUArraysCore.AbstractGPUArray

Device-resident source on a matching device destination: return src as-is (no copy).

See also: CTFlows.Systems._device_like.

_ham_assign! [Function] ​

CTFlows.Systems._ham_assign! Function
julia
_ham_assign!(du::AbstractVector, dx, dp, N::Int64) -> Any

Assign derivatives dx and dp to the combined derivative du for Hamiltonian systems.

Dispatches on the array type (AbstractVector or AbstractMatrix) and the known dimension N (or nothing for runtime inference).

Arguments

  • du::AbstractVector or AbstractMatrix: Combined derivative to fill [dx; dp].

  • dx: State derivative (same shape as state part of du).

  • dp: Costate derivative (same shape as costate part of du).

  • N::Int or nothing: State dimension. If nothing, infers as size(du, 1) ÷ 2.

Returns

  • nothing

Notes

  • Internal helper used by RHS builders for Hamiltonian systems.

  • Performs in-place assignment using broadcasting.

julia
_ham_assign!(du::AbstractMatrix, dx, dp, N::Int64) -> Any

Matrix variant of CTFlows.Systems._ham_assign!: assigns state and costate derivatives into the corresponding row-blocks of each column.

See also: CTFlows.Systems._ham_assign!.

_ham_split [Function] ​

CTFlows.Systems._ham_split Function
julia
_ham_split(u::AbstractVector, N::Int64) -> Tuple{Any, Any}

Split a combined state u into state x and costate p views for Hamiltonian systems.

Dispatches on the array type (AbstractVector or AbstractMatrix) and the known dimension N (or nothing for runtime inference).

Arguments

  • u::AbstractVector or AbstractMatrix: Combined state vector/matrix [x; p].

  • N::Int or nothing: State dimension. If nothing, infers as size(u, 1) ÷ 2.

Returns

  • Tuple: Tuple of views (x_view, p_view) where:
    • For vectors: x_view = @view(u[1:N]), p_view = @view(u[N+1:2N])

    • For matrices: x_view = @view(u[1:N, :]), p_view = @view(u[N+1:2N, :])

Notes

  • Internal helper used by RHS builders for Hamiltonian systems.

  • The CTFlowsStaticArrays extension provides a type-stable method for StaticVector.

julia
_ham_split(u::AbstractMatrix, N::Int64) -> Tuple{Any, Any}

Matrix variant of CTFlows.Systems._ham_split: splits each column of u into state and costate row-block views.

See also: CTFlows.Systems._ham_split.

Type-stable split of a SVector into state and costate components.

Arguments

  • u::SVector: Combined state vector [x; p].

  • N::Int: Known state dimension (compile-time).

Returns

  • Tuple{SVector{N}, SVector{N}}: Tuple of (x, p) as SVectors.

Notes

  • This method provides type stability for SciML's out-of-place ODE solvers when using StaticArrays.

  • Used automatically when the CTFlowsStaticArrays extension is loaded.

Type-stable split of a SMatrix into state and costate components.

Arguments

  • u::SMatrix{NN,M,T}: Combined state matrix stacked vertically [X; P].

  • N::Int: Known state dimension.

Returns

  • Tuple{SMatrix{N,M,T}, SMatrix{N,M,T}}: Tuple of (X, P) as SMatrixs.

Notes

  • This method provides type stability for SciML's out-of-place ODE solvers when using StaticArrays for matrix initial conditions.

  • Constructs new SMatrix objects since views don't work with immutable static arrays.

  • Uses 1D column-major linear indexing to enumerate elements: for result element k (1-based), row = (k-1) % N + 1, col = (k-1) ÷ N + 1.

  • Used automatically when the CTFlowsStaticArrays extension is loaded.

_hamiltonian_vector_field_by_ad [Function] ​

CTFlows.Systems._hamiltonian_vector_field_by_ad Function
julia
_hamiltonian_vector_field_by_ad(
    ::Type{CTBase.Traits.WithAD},
    sys::CTFlows.Systems.AbstractHamiltonianSystem;
    inplace
) -> Any

Compute the Hamiltonian vector field for a WithAD system via automatic differentiation.

Delegates to hamiltonian_vector_field(hamiltonian(sys); ...) using the AD backend stored in the system.

See also: CTFlows.Systems.hamiltonian_vector_field, CTFlows.Systems.HamiltonianSystem.

julia
_hamiltonian_vector_field_by_ad(
    ::Type{CTBase.Traits.WithoutAD},
    sys::CTFlows.Systems.AbstractHamiltonianSystem;
    kwargs...
)

Throw NotImplemented for a WithoutAD system that does not provide a specialized hamiltonian_vector_field overload.

Throws

  • Exceptions.NotImplemented: always, with a suggestion to implement hamiltonian_vector_field for the system type or use HamiltonianVectorFieldSystem.

See also: CTFlows.Systems.hamiltonian_vector_field, CTFlows.Systems.HamiltonianVectorFieldSystem.

_pseudo_gradient [Function] ​

CTFlows.Systems._pseudo_gradient Function
julia
_pseudo_gradient(
    h̃::CTBase.Data.AbstractPseudoHamiltonian,
    b
) -> CTFlows.Systems.PseudoHamiltonianGradient

The gradient functor of the pseudo-Hamiltonian h: a CTFlows.Systems.PseudoHamiltonianGradient for H̃(t, x, p, u, v), a CTFlows.Systems.ConstrainedPseudoHamiltonianGradient for a constrained H(t, x, p, u, μ, v) (multiplier explicit, as returned by pseudo_hamiltonian(sys) on a constrained flow).

See also: CTFlows.Systems.pseudo_hamiltonian_gradient.

_pseudo_variable_gradient [Function] ​

CTFlows.Systems._pseudo_variable_gradient Function
julia
_pseudo_variable_gradient(
    h̃::CTBase.Data.AbstractPseudoHamiltonian,
    b
) -> CTFlows.Systems.PseudoHamiltonianVariableGradient

The variable-gradient functor of the pseudo-Hamiltonian h, unconstrained or constrained; see CTFlows.Systems._pseudo_gradient.

See also: CTFlows.Systems.pseudo_variable_gradient.

_rhs_conversion_label [Function] ​

CTFlows.Systems._rhs_conversion_label Function
julia
_rhs_conversion_label(
    f::CTFlows.Systems.IPVFOoPRHS
) -> String

Return a descriptive label for the RHS conversion performed by a vector-field functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractRHS.

julia
_rhs_conversion_label(
    f::CTFlows.Systems.IPVFIpRHS
) -> String

In-place VF wrapped as in-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    f::CTFlows.Systems.OoPVFOoPRHS
) -> String

Out-of-place VF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    f::CTFlows.Systems.OoPVFIpRHS
) -> String

In-place VF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    f::CTFlows.Systems.OoPVFIpFinalizeRHS
) -> String

In-place VF wrapped as out-of-place interface with type-finalize conversion.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPHVFOoPRHS
) -> String

Return a descriptive label for the RHS conversion performed by a Hamiltonian vector field functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractHVFRHS.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPHVFIpRHS
) -> String

In-place HVF wrapped as in-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPHVFOoPRHS
) -> String

Out-of-place HVF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPHVFIpRHS
) -> String

In-place HVF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPHVFIpFinalizeRHS
) -> String

In-place HVF wrapped as out-of-place interface with type-finalize conversion.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPHVFOoPAugRHS
) -> String

Out-of-place HVF wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPHVFIpAugRHS
) -> String

In-place HVF wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(_::CTFlows.Systems.HamIpRHS) -> String

Return a descriptive label for the RHS conversion performed by a Hamiltonian functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractHamRHS.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.HamOoPRHS
) -> String

Hamiltonian AD wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.HamIpAugRHS
) -> String

Hamiltonian AD wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.PseudoHamIpRHS
) -> String

Return a descriptive label for the RHS conversion performed by a pseudo-Hamiltonian functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractPseudoHamRHS.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.PseudoHamOoPRHS
) -> String

Pseudo-Hamiltonian AD wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.PseudoHamIpAugRHS
) -> String

Pseudo-Hamiltonian AD wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPPseudoHVFOoPRHS
) -> String

Return a descriptive label for the RHS conversion performed by a pseudo-Hamiltonian vector field functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractPseudoHVFRHS.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPPseudoHVFIpRHS
) -> String

In-place PHVF wrapped as in-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPPseudoHVFOoPRHS
) -> String

Out-of-place PHVF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPPseudoHVFIpRHS
) -> String

In-place PHVF wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS
) -> String

In-place PHVF wrapped as out-of-place interface with type-finalize conversion.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPPseudoHVFOoPAugRHS
) -> String

Out-of-place PHVF wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.IPPseudoHVFIpAugRHS
) -> String

In-place PHVF wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.ConstrainedPseudoHamIpRHS
) -> String

Return a descriptive label for the RHS conversion performed by a constrained pseudo-Hamiltonian functor.

Used internally by Base.show for display.

See also: CTFlows.Systems.AbstractPseudoHamRHS.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.ConstrainedPseudoHamOoPRHS
) -> String

Constrained pseudo-Hamiltonian AD wrapped as out-of-place interface.

See also: CTFlows.Systems._rhs_conversion_label.

julia
_rhs_conversion_label(
    _::CTFlows.Systems.ConstrainedPseudoHamIpAugRHS
) -> String

Constrained pseudo-Hamiltonian AD wrapped as in-place augmented interface.

See also: CTFlows.Systems._rhs_conversion_label.

_safe_only [Function] ​

CTFlows.Systems._safe_only Function
julia
_safe_only(x::GPUArraysCore.AbstractGPUArray)

Collapse a length-1 array to its single scalar element, GPU-safely.

Arguments

  • x::GPUArraysCore.AbstractGPUArray: device-resident array whose single element is extracted.

  • x: any other length-1 collection (host arrays, etc.).

Returns

  • The single scalar element of x (a host scalar on both CPU and GPU).

Notes

  • On host arrays this is exactly only(x).

  • On device arrays, only would resolve via iterate → getindex, which GPUArraysCore blocks by default (scalar indexing of device memory). Since this is a single, deliberate, O(1) terminal extraction — not a scalar loop — it is wrapped in @allowscalar.

  • Dispatch is on the array actually received at the call site, so the "1-D = scalar" convention returns an identical host scalar on CPU and GPU (never a device 1-vector).

  • Backend-agnostic (AbstractGPUArray covers CUDA/AMDGPU/Metal).

  • On the RHS hot path, only ever runs for the degenerate length-1-on-GPU case (real GPU workloads have length ≥ 2, where CTFlows.Systems._coerce_state returns identity at zero cost).

See also: CTFlows.Systems._coerce_state.

julia
_safe_only(x)

Host-array fallback: exactly only(x).

See also: CTFlows.Systems._safe_only.

_state_dim [Function] ​

CTFlows.Systems._state_dim Function
julia
_state_dim(_::Number) -> Int64

Infer the state dimension from the initial condition shape.

Methods

  • _state_dim(x0::Number) = 1

  • _state_dim(x0::AbstractVector) = length(x0)

  • _state_dim(x0::AbstractMatrix) = size(x0, 1)

julia
_state_dim(x::AbstractVector) -> Any

State dimension of a vector initial condition: length(x).

See also: CTFlows.Systems._state_dim.

julia
_state_dim(x::AbstractMatrix) -> Any

State dimension of a batched Matrix initial condition: size(x, 1) (per-column batch).

See also: CTFlows.Systems._state_dim.

_unavailable [Function] ​

CTFlows.Systems._unavailable Function
julia
_unavailable(
    accessor::Symbol,
    what::String,
    sys::CTFlows.Systems.AbstractSystem
)

Throw the IncorrectArgument raised by an accessor that does not apply to sys.

Arguments

  • accessor::Symbol: the name of the accessor, e.g. :hamiltonian.

  • what::String: what the accessor returns, e.g. "Hamiltonian".

  • sys::AbstractSystem: the system of the flow.

Throws

  • CTBase.Exceptions.IncorrectArgument: always.

From CTFlowsSciMLIntegrator ​

_check_dyn_config [Function] ​

CTFlowsSciMLIntegrator._check_dyn_config Function
julia
_check_dyn_config(
    _::Type{CTBase.Traits.StateDynamics},
    _::CTFlows.Configs.AbstractConfig
)

Compatibility guard between system dynamics and config type.

Validates that the dynamics trait of the system matches the expected config type:

  • StateDynamics ↔ AbstractConfig

  • HamiltonianDynamics ↔ AbstractHamiltonianConfig or AbstractAugmentedHamiltonianConfig

Throws PreconditionError if the pair is incompatible.

See also: CTFlows.Configs.AbstractConfig, CTFlows.Configs.AbstractHamiltonianConfig.

_with_output_grid [Function] ​

CTFlowsSciMLIntegrator._with_output_grid Function
julia
_with_output_grid(
    options,
    _::Union{Nothing, CTFlows.Configs.AbstractGrid}
) -> Any

No grid of times imposed at the call (none, or a generated grid built after the integration): the cached trajectory options are used as they are.

julia
_with_output_grid(options, grid::AbstractVector) -> Any

Grid of times imposed at the call: a copy of the trajectory options whose saveat is the grid (a call that also has the integrator's saveat is rejected upstream). saveat only shapes the output; the integration stays dense (see CommonSolve.solve for Integrators.SciML).


From CTFlows.Flows ​

OCPControlledVectorFieldFunction [Struct] ​

CTFlows.Flows.OCPControlledVectorFieldFunction Type
julia
struct OCPControlledVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: Function

Internal callable representing the controlled dynamics of an OCP, out-of-place: fc(t,x,u,v) = f(t,x,u,v). Wraps the OCP in-place dynamics; used (composed with an open-loop or closed-loop control law) to build the state flow of the closed-loop system.

Type Parameters

  • TD, VD: time- and variable-dependence traits (compile-time dispatch on arity).

  • DF: type of the in-place dynamics function.

Fields

  • dynamics!::DF: in-place dynamics f!(r, t, x, u, v) from the OCP.

  • n::Int: state dimension.

  • cx::CX, cu::CU, cv::CV: state / control / variable coercions (only for a 1-D quantity, identity otherwise), precomputed once from the OCP dimensions so the hot RHS path never tests a length at run time.

See also: CTBase.Data.ControlledVectorField, _ocp_controlled_vector_field.

OCPStateVectorFieldFunction [Struct] ​

CTFlows.Flows.OCPStateVectorFieldFunction Type
julia
struct OCPStateVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: Function

Internal callable representing the state dynamics of a control-free OCP, out-of-place: g(t,x,v) = f(t,x,∅,v). Used to build the basic state flow of Flow(ocp) for a control-free problem — point evaluation and trajectory calls with no costate.

Type Parameters

  • TD, VD: time- and variable-dependence traits (compile-time dispatch on arity).

  • DF: type of the in-place dynamics function.

Fields

  • dynamics!::DF: in-place dynamics f!(r, t, x, u, v) from the OCP (called with an empty u).

  • n::Int: state dimension.

  • cx::CX, cv::CV: state / variable coercions (only for a 1-D quantity, identity otherwise), precomputed once from the OCP dimensions.

See also: CTBase.Data.VectorField, CTFlows.Flows._ocp_state_vector_field, CTFlows.Flows.OCPControlledVectorFieldFunction.

_AdjoinedConstraint [Struct] ​

CTFlows.Flows._AdjoinedConstraint Type
julia
struct _AdjoinedConstraint{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H, G} <: Function

The constrained pseudo-Hamiltonian of a flow, with the multiplier as an explicit argument: H(t,x,p,u,μ,v) = H̃(t,x,p,u,v) + μ·g(t,x,u,v), where H̃ is the pseudo-Hamiltonian of the OCP (CTBase.Data.pseudo_hamiltonian) and g the constraint given to the flow (uniform call g(t,x,u,v)). Wrapped in a CTBase.Data.ConstrainedPseudoHamiltonian by CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.

Type Parameters

  • TD, VD: time- and variable-dependence traits of the OCP (natural-arity dispatch).

  • H: type of the pseudo-Hamiltonian H̃.

  • G: type of the constraint carrier.

Fields

  • h̃::H: pseudo-Hamiltonian H̃, called uniformly as H̃(t,x,p,u,v).

  • g::G: constraint g(t,x,u,v).

See also: CTFlows.Flows._resolve_constraint.

_CombinedConstraint [Struct] ​

CTFlows.Flows._CombinedConstraint Type
julia
struct _CombinedConstraint{G<:Tuple}

Carrier for a tuple of simultaneous path constraints. Its uniform call concatenates the per-constraint values gᵢ(t,x,u,v), so the downstream sum(μ .* g) pairing computes Σᵢ μᵢ·gᵢ with no change to the pseudo-Hamiltonian functors. Paired element-wise with a CTFlows.Flows._CombinedMultiplier built from the matching multiplier tuple.

Type Parameters

  • G <: Tuple: type of the tuple of resolved per-constraint carriers.

Fields

See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._CombinedMultiplier.

_CombinedMultiplier [Struct] ​

CTFlows.Flows._CombinedMultiplier Type
julia
struct _CombinedMultiplier{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, M<:Tuple} <: Function

Carrier for a tuple of multipliers, paired element-wise with a CTFlows.Flows._CombinedConstraint. Its value concatenates the per-multiplier values μᵢ(t,x,p,v) in the same order, so sum(μ .* g) = Σᵢ μᵢ·gᵢ. The traits are those of the parts joined: non-autonomous if one part is, variable-dependent if one part is; the natural calls follow them.

Type Parameters

  • TD, VD: joined time- and variable-dependence traits.

  • M <: Tuple: type of the tuple of resolved per-multiplier carriers.

Fields

  • parts::M: the resolved per-multiplier carriers (each a CTBase.Data.Multiplier).

  • labels::Vector{Symbol}: the label of each constraint, for error messages; Symbol("") for a constraint given as a function.

  • dims::Vector{Int}: the number of components of each constraint, checked against the value of its multiplier; 0 when it is not known (a constraint given as a function), then not checked.

See also: CTFlows.Flows._resolve_multiplier, CTFlows.Flows._CombinedConstraint.

_FLOW_DESCRIPTION [Constant] ​

CTFlows.Flows._FLOW_DESCRIPTION Constant

Strategy family description for flow construction.

This constant identifies the strategy families used in flow construction:

  • :di - DifferentiationInterface family for AD backends

  • :sciml - SciML family for ODE integrators

Type

  • Tuple{Symbol, Symbol}: Tuple of strategy family identifiers.

Notes

See also: CTFlows.Flows._route_flow_options, CTFlows.Flows._build_flow_components, CTFlows.Flows._flow_families.

_FLOW_REGISTRY [Constant] ​

CTFlows.Flows._FLOW_REGISTRY Constant

Strategy registry for flow construction.

This constant holds the precomputed strategy registry that maps abstract strategy types to their concrete implementations for flow construction:

  • Differentiation.AbstractADBackend → Differentiation.DifferentiationInterface

  • Integrators.AbstractIntegrator → Integrators.SciML

Type

  • CTBase.Strategies.StrategyRegistry: Registry mapping abstract types to concrete implementations.

Notes

See also: CTFlows.Flows.flow_registry, CTFlows.Flows._route_flow_options, CTBase.Strategies.create_registry.

_FlowDuals [Struct] ​

CTFlows.Flows._FlowDuals Type
julia
struct _FlowDuals{P<:Tuple}

Duals of the constraints of the model along the arc of a flow, by label: the labelled constraints adjoined to the pseudo-Hamiltonian (parts), and the path labels of the model that are not adjoined, whose dual is zero. An unconstrained flow has no part.

Fields

  • parts::P: a tuple of CTFlows.Flows._LabelledDual.

  • labels::Vector{Symbol}: every label with a known dual: the adjoined labels, then the other path labels.

  • dims::Dict{Symbol,Int}: the number of rows (or components) of each label.

_LabelDualFunction [Struct] ​

CTFlows.Flows._LabelDualFunction Type
julia
struct _LabelDualFunction{D, X, P, V} <: Function

The dual of the constraint label of a solution as a function of time, t -> y(t), passed to CTModels.Solutions.build_solution in duals.

Fields

  • duals::D: the duals of the flow (CTFlows.Flows._FlowDuals, or the piecewise duals of a multi-phase flow).

  • label::Symbol: the label of the constraint.

  • x::X, p::P: the state and costate, callables t -> x(t), t -> p(t).

  • v::V: the variable.

_LabelledDual [Struct] ​

CTFlows.Flows._LabelledDual Type
julia
struct _LabelledDual{M}

Dual of one labelled constraint on the arc of a flow: its label and the multiplier μ given to the flow, which is the dual itself.

Fields

  • label::Symbol: the label of the constraint in the model.

  • μ::M: the resolved multiplier, called uniformly as μ(t, x, p, v).

_TimedFlow [Struct] ​

CTFlows.Flows._TimedFlow Type
julia
struct _TimedFlow{TD, VD, D, F<:CTFlows.Flows.AbstractFlow{TD, VD, D}} <: CTFlows.Flows.AbstractFlow{TD, VD, D}

A flow whose point call also reports the time the solver reached. It wraps flow and shares its traits, so that CTFlows.Flows._invoke_flow validates the variable as for flow, then returns (value, t_reached) instead of value. An integration that a callback (terminate!) or a failure with unsafe=true stops early reaches a time other than the requested final time, which the call of a flow alone does not tell.

Fields

  • flow::F: the wrapped flow.

See also: CTFlows.Flows._timed.

_UnlabelledPathDuals [Struct] ​

CTFlows.Flows._UnlabelledPathDuals Type
julia
struct _UnlabelledPathDuals

Constraint duals that cannot be rebuilt: a constraint was given to the flow as a function (or as a CTBase.Data.PathConstraint), with no label to place its multiplier in the model.

__grid [Function] ​

CTFlows.Flows.__grid Function
julia
__grid() -> CTBase.Core.NotProvidedType

Default value for the grid keyword of a top-level trajectory call.

Returns CTBase.Core.NotProvided by default, meaning no output grid is imposed: the call then generates an CTFlows.Configs.AutomaticGrid (AdaptiveGrid(250) when the solver returns fewer than 250 times), unless a grid of times or the integrator's saveat already shapes the output. grid=nothing keeps the solver steps. Internal calls (the inner flow of a decorator, a phase of a multi-phase flow) pass grid=nothing.

See also: CTFlows.Flows._default_grid.

_adjoined_H [Function] ​

CTFlows.Flows._adjoined_H Function
julia
_adjoined_H(
    h::CTFlows.Flows._AdjoinedConstraint,
    t,
    x,
    p,
    u,
    μ,
    v
) -> Any

Value H̃(t,x,p,u,v) + μ·g(t,x,u,v). The pairing μ·g uses sum(μ .* g), for a scalar or a vector constraint. When v === nothing (Fixed problems) an empty variable vector is forwarded; the Fixed-trait uniform calls ignore it.

See also: CTFlows.Flows._AdjoinedConstraint.

_adtypes_backend [Function] ​

CTFlows.Flows._adtypes_backend Function
julia
_adtypes_backend(
    backend::CTBase.Differentiation.DifferentiationInterface
) -> Any

The ADTypes backend wrapped by an AD backend strategy: only the DifferentiationInterface strategy wraps one (any other strategy, e.g. a user-defined one, gives nothing).

_apply_dim_coerce [Function] ​

CTFlows.Flows._apply_dim_coerce Function
julia
_apply_dim_coerce(
    coerce,
    x::AbstractMatrix
) -> AbstractMatrix

Apply a precomputed per-dimension coercion (_dim_coerce), except on a batched Matrix value, which is always left untouched regardless of the declared dimension. _dim_coerce is baked in once from the OCP's declared dimension, at flow-construction time, before the shape of any future call-site value is known — it cannot itself special-case Matrix. This guard is the runtime check that closes that gap, mirroring Systems._coerce_state(::AbstractMatrix) = identity.

See also: CTFlows.Flows._dim_coerce.

julia
_apply_dim_coerce(coerce, x) -> AbstractMatrix

Apply a precomputed per-dimension coercion to a non-batched value: returns coerce(x) (only for 1-D, identity otherwise).

See also: CTFlows.Flows._apply_dim_coerce, CTFlows.Flows._dim_coerce.

_arity_issue [Function] ​

CTFlows.Flows._arity_issue Function
julia
_arity_issue(
    f::Function,
    ocp,
    label::AbstractString,
    second::AbstractString,
    kind::AbstractString
) -> Union{Nothing, String}

Check the arity of a raw convenience function f against the natural arity expected for an OCP with the given time/variable dependence.

Mirrors the mutability-detection pattern used for vector fields (CTBase.Data._detect_mutability_vf): a single-method guard makes arity detection unambiguous via first(methods(f)).nargs. Unlike that pattern, this check skips (returns nothing) rather than throws when f has more than one method — the caller cannot tell which arity the user intended, so no diagnostic is possible.

Arguments

  • f::Function: the raw function to inspect (control law, constraint, or multiplier).

  • ocp::CTModels.Models.Model: the OCP, used to infer the expected arity.

  • label::AbstractString: the symbol name used in the natural-syntax example (e.g. "u").

  • second::AbstractString: the name of the second natural argument ("p" for a control law/multiplier, "u" for a constraint).

  • kind::AbstractString: a human-readable description of the role (e.g. "control law"), used in the diagnostic message.

Returns

  • Nothing: if the arity matches, or if f has more than one method (ambiguous).

  • String: a one-line diagnostic naming the expected natural syntax, otherwise.

See also: CTFlows.Flows._expected_arity, CTFlows.Flows._natural_syntax.

_as_method_tokens [Function] ​

CTFlows.Flows._as_method_tokens Function
julia
_as_method_tokens(_::Nothing)

Normalize a user-supplied method into a token tuple, or return nothing when no method was given (the default). A bare Symbol (e.g. :gpu) is wrapped into a single-element tuple; a tuple of Symbols is returned as-is.

See also: CTFlows.Flows._flow_description

julia
_as_method_tokens(m::Symbol) -> Tuple{Symbol}

Wrap a bare Symbol (e.g. :gpu) into a single-element tuple.

See also: CTFlows.Flows._as_method_tokens, CTFlows.Flows._flow_description.

julia
_as_method_tokens(
    m::Tuple{Vararg{Symbol}}
) -> Tuple{Vararg{Symbol}}

Return a tuple of Symbols as-is — already in the normalized form.

See also: CTFlows.Flows._as_method_tokens, CTFlows.Flows._flow_description.

_available_flow_methods [Function] ​

CTFlows.Flows._available_flow_methods Function
julia
_available_flow_methods(
    _::Type{CTBase.Traits.WithAD}
) -> Tuple{Tuple{Symbol, Symbol, Symbol}, Tuple{Symbol, Symbol, Symbol}}

Candidate descriptions (the :cpu/:gpu device variants) against which a user method is completed via CTBase.Descriptions.complete.

julia
_available_flow_methods(
    _::Type{CTBase.Traits.WithoutAD}
) -> Tuple{Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol}}

Candidate descriptions for an AD-free flow: only the :sciml integrator with :cpu/:gpu device variants (no :di backend).

See also: CTFlows.Flows._available_flow_methods, CTBase.Descriptions.complete.

_build_flow_components [Function] ​

CTFlows.Flows._build_flow_components Function
julia
_build_flow_components(
    ad_trait,
    routed;
    method
) -> NamedTuple

Build concrete strategy instances from routed options.

Each strategy is constructed via CTBase.Orchestration.build_strategy_from_resolved using the options that were routed to its family by CTFlows.Flows._route_flow_options.

Arguments

  • ad_trait: Traits.WithAD (builds :di backend + :sciml integrator) or Traits.WithoutAD (builds only the :sciml integrator).

  • routed: Result of CTFlows.Flows._route_flow_options containing routed option values.

  • method: Optional device selection (Symbol/token tuple, e.g. :gpu) threaded into the resolved global strategy parameter (CPU/GPU) for all families at once.

Returns

  • NamedTuple: concrete strategy instances keyed by family — (integrator,) for WithoutAD, (backend, integrator) for WithAD.

Example

julia
routed = Flows._route_flow_options(Traits.WithAD, (; reltol=1e-8))
components = Flows._build_flow_components(Traits.WithAD, routed)
# components.backend isa CTBase.Differentiation.DifferentiationInterface
# components.integrator isa CTFlows.Integrators.SciML

See also: CTFlows.Flows._route_flow_options, CTFlows.Flows.flow_registry, CTBase.Orchestration.build_strategy_from_resolved

julia
_build_flow_components(routed) -> NamedTuple

Back-compat alias: build flow components using the WithAD plan (backend + integrator).

See also: CTFlows.Flows._build_flow_components.

_build_integrator [Function] ​

CTFlows.Flows._build_integrator Function
julia
_build_integrator(
    opts
) -> NamedTuple{(:integrator, :label), <:Tuple{Any, String}}

Build the SciML integrator for an AD-free flow (Traits.WithoutAD) directly from a flow constructor's keyword arguments, honouring a method=:gpu device selection popped from them. Return (integrator, label): the integrator and the routed label action option (see CTFlows.Flows._routed_label).

Shared by the AD-free constructors (Flow(VectorField), Flow(HamiltonianVectorField), controlled-vector-field flows, Flow(ODEFunction), Flow(ODEProblem)), which build only an integrator (no :di AD backend). Routing through the WithoutAD plan means an ad_backend option is correctly rejected here as unknown (there is no AD backend to configure).

See also: CTFlows.Flows._build_flow_components, CTFlows.Flows._pop_method.

_build_ocp_pseudo_flow [Function] ​

CTFlows.Flows._build_ocp_pseudo_flow Function
julia
_build_ocp_pseudo_flow(
    ::Val{:total},
    ocp,
    law,
    components,
    cspec,
    mspec;
    p0
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedConstrainedHamiltonian{TD, VD}))}}

Build the inner Hamiltonian flow of an OCP + control-law flow, dispatching on the hamiltonian_type and on the presence of constraints (the (cspec, mspec) of CTFlows.Flows._multiplier_specs).

Both modes share the same objects: the constrained pseudo-Hamiltonian H(t,x,p,u,μ,v) (CTFlows.Flows._constrained_pseudo_hamiltonian: by label from CTModels, with μ the dual of the solution, or H̃ + μ·g for a constraint given as a function), the law and the multiplier.

See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier, CTFlows.Flows._build_pseudo_flow.

julia
_build_ocp_pseudo_flow(
    ::Val{:partial},
    ocp,
    law,
    components,
    cspec,
    mspec;
    p0
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.ConstrainedPseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.ConstrainedPseudoHamiltonian{<:Function, TD, VD}))}}

Build the inner flow for the :partial mode from an OCP pseudo-Hamiltonian and a control law. When a constraint spec (cspec) is provided, resolve it together with the multiplier spec (mspec) and build a CTFlows.Systems.ConstrainedPseudoHamiltonianSystem on the constrained pseudo-Hamiltonian; otherwise delegate to CTFlows.Flows._build_pseudo_flow.

See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.ConstrainedPseudoHamiltonianSystem, CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier.

julia
_build_ocp_pseudo_flow(
    ::Val{ht},
    ocp,
    law,
    components,
    cspec,
    mspec;
    p0
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedConstrainedHamiltonian{TD, VD}))}}

Unknown hamiltonian_type: delegate to the (throwing) unconstrained fallback so the error message and type match Flow(h̃, law; hamiltonian_type=…).

See also: CTFlows.Flows._build_pseudo_flow.

_build_ocp_solution [Function] ​

CTFlows.Flows._build_ocp_solution Function
julia
_build_ocp_solution(
    ocp,
    sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
    variable,
    integ;
    ...
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(identity)}}, CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(only)}}}, VariableModelType<:Union{CTModels.Components.VariableModelSolution{Vector{Float64}}, CTModels.Components.VariableModelSolution{Float64}}, ModelType<:(CTModels.Models.Model{<:CTBase.Traits.TimeDependence, T} where T<:CTModels.Components.TimesModel), CostateModelType<:CTModels.Components.CoercedTrajectory, DualModelType<:Union{CTModels.Solutions.EmptyDualModel, CTModels.Solutions.DualModel{PC_Dual, BC_Dual, SC_LB_Dual, SC_UB_Dual, CC_LB_Dual, CC_UB_Dual, VC_LB_Dual, VC_UB_Dual} where {PC_Dual<:Union{Nothing, CTModels.Components.CoercedTrajectory{_A, typeof(identity)} where _A, CTModels.Components.CoercedTrajectory{_A, typeof(only)} where _A}, BC_Dual<:Union{Nothing, Vector{Float64}}, SC_LB_Dual<:Union{Nothing, CTModels.Components.CoercedTrajectory{_A, typeof(identity)} where _A, CTModels.Components.CoercedTrajectory{_A, typeof(only)} where _A}, SC_UB_Dual<:Union{Nothing, CTModels.Components.CoercedTrajectory{_A, typeof(identity)} where _A, CTModels.Components.CoercedTrajectory{_A, typeof(only)} where _A}, CC_LB_Dual<:Union{Nothing, CTModels.Components.CoercedTrajectory{_A, typeof(identity)} where _A, CTModels.Components.CoercedTrajectory{_A, typeof(only)} where _A}, CC_UB_Dual<:Union{Nothing, CTModels.Components.CoercedTrajectory{_A, typeof(identity)} where _A, CTModels.Components.CoercedTrajectory{_A, typeof(only)} where _A}, VC_LB_Dual<:Union{Nothing, Float64, Vector{Float64}}, VC_UB_Dual<:Union{Nothing, Float64, Vector{Float64}}}}}
_build_ocp_solution(
    ocp,
    sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
    variable,
    integ,
    law;
    switching,
    duals
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:CTModels.Solutions.AbstractTimeGridModel, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, ModelType<:CTModels.Models.AbstractModel, CostateModelType<:Function, DualModelType<:CTModels.Solutions.AbstractDualModel}

Build a CTModels.Solution from a HamiltonianVectorFieldTrajectory.

Extracts the time grid, state/costate projections, and variable vector from the trajectory, computes the objective via CTFlows.Flows._flow_objective, and assembles a full CTModels.Solution with empty control (control-free OCP).

See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows._flow_objective, CTFlows.Flows._control_of, CTFlows.Flows._variable_vector, CTModels.Solutions.Solution.

_build_pseudo_flow [Function] ​

CTFlows.Flows._build_pseudo_flow Function
julia
_build_pseudo_flow(
    _::Val{:total},
    h̃,
    law,
    components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}

Build the inner Hamiltonian flow for the :total mode: compose the pseudo-Hamiltonian H̃ with the control law u(t,x,p,v) into a CTBase.Data.ComposedHamiltonian H(t,x,p,v) = H̃(t,x,p,u(t,x,p,v),v), wrap it in a CTFlows.Systems.HamiltonianSystem, and build the flow.

See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.HamiltonianSystem, CTBase.Data.ComposedHamiltonian.

julia
_build_pseudo_flow(
    _::Val{:partial},
    h̃,
    law,
    components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}

Build the inner Hamiltonian flow for the :partial mode: wrap the pseudo-Hamiltonian and control law in a CTFlows.Systems.PseudoHamiltonianSystem (AD at fixed u).

See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.PseudoHamiltonianSystem.

julia
_build_pseudo_flow(
    _::Val{ht},
    h̃,
    law,
    components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}

Throw an CTBase.Exceptions.IncorrectArgument for an unknown hamiltonian_type value. Only :total and :partial are supported.

Throws

See also: CTFlows.Flows._build_pseudo_flow.

_call_arrays [Function] ​

CTFlows.Flows._call_arrays Function
julia
_call_arrays(
    config::CTFlows.Configs.AbstractStateConfig
) -> Tuple{Any}

Initial arrays of a call configuration whose placement is checked: the state, and the costate of a Hamiltonian configuration (the variable costate is a host object by design).

_call_grid_spec [Function] ​

CTFlows.Flows._call_grid_spec Function
julia
_call_grid_spec(tspan, grid, flow) -> Any

Validate the grid keyword of a decorated trajectory call and return the generated grid spec (or nothing). A grid of times given in place of the span is left to the inner flow.

Throws

  • CTBase.Exceptions.IncorrectArgument: If a grid of times and grid= are both given, or if the integrator sets saveat while grid= is given.

_call_kind [Function] ​

CTFlows.Flows._call_kind Function
julia
_call_kind(
    _::CTFlows.Configs.AbstractEndPointConfig
) -> String

The name of a flow call in an error, from its configuration: "point call", "trajectory call", or "call" for a call without configuration.

_check_ad_eltypes [Function] ​

CTFlows.Flows._check_ad_eltypes Function
julia
_check_ad_eltypes(_, values)

Reject, for the AutoMooncake backend ad, the values of the call (state, costate, times, variable) whose element type Mooncake cannot differentiate through (see CTFlows.Flows._mooncake_eltype). Other backends accept every element type here.

_check_backend_parameter [Function] ​

CTFlows.Flows._check_backend_parameter Function
julia
_check_backend_parameter(b, built, method)

Check that a ready-built AD backend strategy b, given as ad_backend=b to a flow constructor, runs on the device of the flow: its parameter (CPU or GPU) must be the one of the backend the flow builds from method (:cpu by default). A strategy without a parameter (nothing) is not checked.

Throws

See also: CTFlows.Flows._pop_backend_instance.

_check_call [Function] ​

CTFlows.Flows._check_call Function
julia
_check_call(
    flow::CTFlows.Flows.AbstractFlow,
    config::CTFlows.Configs.AbstractConfig;
    variable
)

Check a flow call before the integration:

  • a GPU flow (method=:gpu) needs device arrays, not host arrays;

  • the AutoMooncake backend needs IEEE floats in the state, the costate, the times and the variable (no outer ForwardDiff through the flow);

  • the package of the AD backend of the system is loaded (see CTBase.Differentiation.check_backend).

Each check raises a structured error at the call, instead of a raw error from the AD backend deep inside the integration. variable is the variable of the call (nothing if none).

Throws

  • CTBase.Exceptions.PreconditionError: For a host array under method=:gpu, or a non-IEEE element type with the AutoMooncake backend.

  • CTBase.Exceptions.ExtensionError: If the package of the AD backend is not loaded.

See also: CTFlows.Flows._core_invoke_flow.

_check_convenience_arities [Function] ​

CTFlows.Flows._check_convenience_arities Function
julia
_check_convenience_arities(ocp, u, cspec, mspec)

Check the arities of the raw functions passed to an OCP convenience constructor — the control law u, and (if given as raw Functions) the constraints and multipliers of the multipliers pairs — against the OCP's time/variable dependence.

Collects every mismatch (a function with a single method and a wrong arity) into one CTBase.Exceptions.IncorrectArgument, naming the expected natural syntax for each and suggesting the explicit constructors as an escape hatch. Functions with more than one method are skipped (arity cannot be determined); several constraints and multipliers are checked element-wise; nothing is skipped (no spec given).

Arguments

  • ocp::CTModels.Models.Model: the OCP.

  • u: the control-law spec (nothing or a raw Function).

  • cspec: the constraints of the multipliers pairs, from CTFlows.Flows._multiplier_specs (nothing, Symbol, Function, Tuple, or CTBase.Data.PathConstraint).

  • mspec: their multipliers (nothing, Function, Tuple, or CTBase.Data.Multiplier).

A control-free OCP is skipped entirely (no throw): a control law's arity is only meaningful relative to an OCP that actually has a control, and a control-free OCP is already rejected with a clearer, more fundamental PreconditionError downstream.

Throws

See also: CTFlows.Flows._arity_issue, CTFlows.Flows._spec_arity_issues!.

_check_host_arrays [Function] ​

CTFlows.Flows._check_host_arrays Function
julia
_check_host_arrays(device, host)

Reject host arrays when the flow is a GPU flow. device is the device parameter of the integrator, host the host arrays of the call.

_check_output_grid [Function] ​

CTFlows.Flows._check_output_grid Function
julia
_check_output_grid(flow, config)

Reject an output grid given at the call (grid of times or generated) when the flow's integrator sets saveat (the integrator is only queried when a grid is given).

_checked_multiplier_part [Function] ​

CTFlows.Flows._checked_multiplier_part Function
julia
_checked_multiplier_part(
    m::CTFlows.Flows._CombinedMultiplier,
    k::Int64,
    y
) -> Any

Value of the k-th multiplier of a CTFlows.Flows._CombinedMultiplier, checked against the dimension of its constraint when it is known: a number or one component for a one-dimensional constraint, d components otherwise.

Throws

_combined_value [Function] ​

CTFlows.Flows._combined_value Function
julia
_combined_value(
    m::CTFlows.Flows._CombinedMultiplier,
    t,
    x,
    p,
    v
) -> Any

Value: concatenate (vcat) the per-multiplier values μᵢ(t,x,p,v) in tuple order, each checked against the dimension of its constraint (see CTFlows.Flows._checked_multiplier_part).

_computed_until_failure [Function] ​

CTFlows.Flows._computed_until_failure Function
julia
_computed_until_failure(
    _::CTFlows.Configs.AbstractEndPointConfig
) -> String

What a flow call returns with unsafe=true when the integration fails, from its configuration: the state reached for a point call, the trajectory otherwise.

_constrained_pseudo_hamiltonian [Function] ​

CTFlows.Flows._constrained_pseudo_hamiltonian Function
julia
_constrained_pseudo_hamiltonian(
    ocp,
    cspec;
    p0
) -> Union{CTBase.Data.ConstrainedPseudoHamiltonian, CTBase.Data.PseudoHamiltonian}

The constrained pseudo-Hamiltonian H(t,x,p,u,μ,v) of a flow, from its constraint specification:

See also: CTFlows.Flows._is_labelled.

_constraint_kind [Function] ​

CTFlows.Flows._constraint_kind Function
julia
_constraint_kind(ocp, label::Symbol) -> Symbol

The kind of the constraint label of ocp: :path, :state, :control, :boundary or :variable.

_constraint_labels_dims [Function] ​

CTFlows.Flows._constraint_labels_dims Function
julia
_constraint_labels_dims(
    ocp,
    cspec,
    n::Int64
) -> Tuple{Any, Any}

The labels and the numbers of rows of the n constraints of the spec cspec, paired element-wise with a tuple of n multipliers: those of a constraint given by its label, and Symbol("") and 0 (unknown, not checked) for a constraint given as a function, or when cspec is not a tuple of n constraints.

_control_of [Function] ​

CTFlows.Flows._control_of Function
julia
_control_of(
    _::Nothing,
    x,
    v
) -> CTFlows.Flows.var"#_control_of##0#_control_of##1"

Reconstruct the control along a trajectory as a callable t -> u(t).

Dispatched on the control law and the available data:

  • nothing → t -> Float64[] (control-free OCP), for both the state (x, v) and the Hamiltonian (x, p, v) call shapes.

  • a law with the state and costate projections (x, p, v) → t -> law(t, x(t), p(t), v) (the DynClosedLoop / Hamiltonian path, which uses the costate).

  • a law with only the state projection (x, v) → t -> u(t) via CTFlows.Trajectories._controlled_u (the OpenLoop / ClosedLoop state path, no costate).

x and p are callables t -> x(t) / t -> p(t); v is the variable.

See also: CTFlows.Flows._flow_objective, CTFlows.Trajectories._controlled_u.

julia
_control_of(
    _::Nothing,
    x,
    p,
    v
) -> CTFlows.Flows.var"#_control_of##2#_control_of##3"

Control-free OCP with costate projection: returns t -> Float64[] (no control to reconstruct).

See also: CTFlows.Flows._control_of.

julia
_control_of(
    law,
    x,
    p,
    v
) -> CTFlows.Flows.var"#_control_of##2#_control_of##3"

DynClosedLoop law with costate: returns t -> law(t, x(t), p(t), v) (Hamiltonian path).

See also: CTFlows.Flows._control_of.

julia
_control_of(
    law,
    x,
    v
) -> CTFlows.Flows.var"#_control_of##0#_control_of##1"

OpenLoop/ClosedLoop law with state only: returns t -> u(t) via CTFlows.Trajectories._controlled_u (state path, no costate).

See also: CTFlows.Flows._control_of, CTFlows.Trajectories._controlled_u.

_controlled_flow [Function] ​

CTFlows.Flows._controlled_flow Function
julia
_controlled_flow(
    fc::CTBase.Data.ControlledVectorField,
    law::CTBase.Data.ControlLaw,
    ocp;
    kwargs...
) -> CTFlows.Flows.ControlledFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, _A, CTBase.Data.ControlLaw{F, FB, TD2, VD2}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, _A, F<:Function, FB<:CTBase.Traits.AbstractFeedback, TD2<:CTBase.Traits.TimeDependence, VD2<:CTBase.Traits.VariableDependence}

Build a CTFlows.Flows.ControlledFlow from a controlled vector field, an open-loop/closed-loop control law, and an optional OCP (for the objective): compose into a CTBase.Data.ComposedVectorField, build a VectorFieldSystem, and wrap the resulting state flow together with the OCP reference (or nothing) and the law.

_core_invoke_flow [Function] ​

CTFlows.Flows._core_invoke_flow Function
julia
_core_invoke_flow(
    flow::CTFlows.Flows.AbstractFlow,
    config::CTFlows.Configs.AbstractConfig;
    variable,
    unsafe
)

Internal implementation body for flow integration.

This function performs the actual ODE integration workflow after trait-based dispatch has validated the variable parameter. It extracts the system and integrator from the flow, prepares cache, builds the ODE problem, solves it, and constructs the solution.

Arguments

  • flow::CTFlows.Flows.AbstractFlow: The flow to solve.

  • config::CTFlows.Configs.AbstractConfig: The integration configuration.

  • variable: The variable parameter value (may be nothing for Fixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • The packaged solution (type varies by config type).

Notes

This is an internal function called by the trait-dispatch overloads of _invoke_flow. Users should call the public _invoke_flow function instead.

See also: CTFlows.Flows._invoke_flow, CTFlows.Integrators.build_problem, CommonSolve.solve, CTFlows.Trajectories.build_trajectory.

julia
_core_invoke_flow(
    timed::CTFlows.Flows._TimedFlow,
    config::CTFlows.Configs.AbstractEndPointConfig;
    variable,
    unsafe
)

Point call of a CTFlows.Flows._TimedFlow: the value of the plain call of the wrapped flow and the time the solver reached.

Returns

  • Tuple: (value, t_reached).

_default_grid [Function] ​

CTFlows.Flows._default_grid Function
julia
_default_grid(
    grid,
    tspan,
    flows...
) -> Union{Nothing, CTFlows.Configs.AutomaticGrid}

Resolve the grid keyword of a top-level trajectory call. An explicit grid (nothing, an integer, a generated grid) is returned as given. Core.NotProvided becomes CTFlows.Configs.AutomaticGrid when the call sets a time span and none of the flows (every phase of a multi-phase flow) has an integrator with saveat, and nothing otherwise: a grid of times or a saveat already shapes the output.

See also: CTFlows.Flows.__grid.

_dim_coerce [Function] ​

CTFlows.Flows._dim_coerce Function
julia
_dim_coerce(
    dim::Int64
) -> Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}

Precomputed coercion from a declared dimension: only collapses a 1-D quantity to a scalar (accepting both a scalar and a length-1 vector), identity leaves n-D untouched.

_dual_labels [Function] ​

CTFlows.Flows._dual_labels Function
julia
_dual_labels(d::CTFlows.Flows._FlowDuals) -> Vector{Symbol}

The labels with a known dual (see CTFlows.Flows._FlowDuals); none when the duals cannot be rebuilt or the problem is control-free.

_dual_value [Function] ​

CTFlows.Flows._dual_value Function
julia
_dual_value(
    d::CTFlows.Flows._FlowDuals,
    label::Symbol,
    t,
    x,
    p,
    v
) -> Any

Dual of the constraint label at time t, from the state x, the costate p and the variable v there: the multiplier given to the flow when label is adjoined, zero otherwise.

julia
_dual_value(
    pd::CTFlows.MultiPhase._PiecewiseDuals,
    label::Symbol,
    t,
    x,
    p,
    v
) -> Any

Dual of label at time t: that of the phase active at t.

_expected_arity [Function] ​

CTFlows.Flows._expected_arity Function
julia
_expected_arity(ocp) -> Int64

Natural arity expected of a raw convenience function (control law, constraint, or multiplier) for an OCP with the given time/variable dependence.

The natural signatures of a control law u(x,p), a constraint g(x,u) and a multiplier μ(x,p) all share the same shape: 2 fixed arguments, plus t if the OCP is non-autonomous, plus v if the OCP is non-fixed (is_variable).

Arguments

  • ocp::CTModels.Models.Model: the OCP, used to read its time/variable dependence.

Returns

  • Int: the expected number of positional arguments.

See also: CTFlows.Flows._arity_issue.

_finalize_vf [Function] ​

CTFlows.Flows._finalize_vf Function
julia
_finalize_vf(r, _::Number) -> Any

Collapse a length-1 result buffer to a scalar (1-D state convention).

julia
_finalize_vf(r, _::Vector) -> Any

Return the result buffer as-is for a Vector state — r already has this exact type (see CTFlows.Systems._buffer_like), so this is an identity, no-allocation path.

julia
_finalize_vf(r, xs::AbstractVector) -> Any

Reconstruct the result buffer in the state's own container type (e.g. Vector → SVector/MVector), mirroring Systems.OoPVFIpFinalizeRHS. The internal buffer r is always a plain Vector (see CTFlows.Systems._buffer_like); for an immutable state container this conversion is required for OrdinaryDiffEq's out-of-place type-constancy.

julia
_finalize_vf(r, _::Matrix) -> Any

Return the result buffer as-is for a batched Matrix state (each column an independent trajectory) — r already has this exact type (see CTFlows.Systems._buffer_like), so this is an identity, no-allocation path.

julia
_finalize_vf(r, xs::AbstractMatrix) -> Any

Reconstruct the result buffer in the state's own container type (e.g. Matrix → SMatrix/MMatrix) for a batched immutable-matrix state, for the same out-of-place type-constancy reason as the AbstractVector method above.

_flow_action_defs [Function] ​

CTFlows.Flows._flow_action_defs Function
julia
_flow_action_defs(

) -> Vector{CTBase.Options.OptionDefinition}

Return the action-level option definitions for control flows: hamiltonian_type (:total or :partial), and multipliers, the constraint => multiplier pairs that turn the flow into a constrained pseudo-Hamiltonian flow. Both are routed as first-class action options so they are accepted only where meaningful (the control-law flow constructors) and rejected as unknown options elsewhere.

See also: CTFlows.Flows._route_flow_options, CTFlows.Flows._unwrap_option.

_flow_base_description [Function] ​

CTFlows.Flows._flow_base_description Function
julia
_flow_base_description(
    _::Type{CTBase.Traits.WithAD}
) -> Tuple{Symbol, Symbol, Symbol}

Base method description for a flow plan, per AD trait. The device token (:cpu) is explicit: the flow registry is parameterized ([CPU, GPU]), so a device token is required — CTBase.Strategies.extract_global_parameter_from_method throws otherwise. The bare :cpu reproduces the pre-parameterization CPU behaviour exactly (SciML{CPU} metadata ≡ old).

See also: CTFlows.Flows._flow_base_description, CTFlows.Flows._available_flow_methods.

julia
_flow_base_description(
    _::Type{CTBase.Traits.WithoutAD}
) -> Tuple{Symbol, Symbol}

Base method description for an AD-free flow plan: no :di backend token (no scalar Hamiltonian is differentiated), only the :sciml integrator and :cpu device.

See also: CTFlows.Flows._flow_base_description, CTFlows.Flows._available_flow_methods.

_flow_description [Function] ​

CTFlows.Flows._flow_description Function
julia
_flow_description(
    ad_trait,
    method
) -> Union{Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol, Symbol}}

Resolve the effective method description for a flow from its AD trait and an optional user method (a Symbol such as :gpu, or a token tuple). method === nothing yields the base (CPU) description; otherwise the tokens are completed against CTFlows.Flows._available_flow_methods.

_flow_duals [Function] ​

CTFlows.Flows._flow_duals Function
julia
_flow_duals(
    ocp,
    cspec,
    mspec
) -> Union{CTFlows.Flows._UnlabelledPathDuals, CTFlows.Flows._FlowDuals}

Build the duals of a flow from its constraint and multiplier specifications (already validated): a CTFlows.Flows._FlowDuals when there is no constraint or when every constraint is given by its label, a CTFlows.Flows._UnlabelledPathDuals otherwise.

_flow_families [Function] ​

CTFlows.Flows._flow_families Function
julia
_flow_families(
    _::Type{CTBase.Traits.WithAD}
) -> @NamedTuple{backend::DataType, integrator::DataType}

Return the strategy families used for option routing in flow construction.

The returned NamedTuple maps family names to their abstract types, as expected by CTBase.Orchestration.route_all_options.

Returns

  • NamedTuple: (backend, integrator) mapped to their abstract types

Example

julia
# Get the strategy families for flow construction
fam = Flows._flow_families()
# Returns: (backend = CTBase.Differentiation.AbstractADBackend, integrator = CTFlows.Integrators.AbstractIntegrator)

See also: CTFlows.Flows._route_flow_options, CTFlows.Flows.flow_registry

julia
_flow_families(
    _::Type{CTBase.Traits.WithoutAD}
) -> @NamedTuple{integrator::DataType}

Strategy families for an AD-free flow: only the :sciml integrator (no :di backend, since no scalar Hamiltonian is differentiated).

julia
_flow_families(

) -> @NamedTuple{backend::DataType, integrator::DataType}

Back-compat alias: return the full (WithAD) strategy families — backend + integrator.

See also: CTFlows.Flows._flow_families.

_flow_from_controlled_vf [Function] ​

CTFlows.Flows._flow_from_controlled_vf Function
julia
_flow_from_controlled_vf(
    ::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
    fc::CTBase.Data.ControlledVectorField,
    law::CTBase.Data.ControlLaw;
    kwargs...
) -> CTFlows.Flows.ControlledFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, Nothing, CTBase.Data.ControlLaw{F, FB, TD2, VD2}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, F<:Function, FB<:CTBase.Traits.AbstractFeedback, TD2<:CTBase.Traits.TimeDependence, VD2<:CTBase.Traits.VariableDependence}

Dispatch helper for CTFlows.Flows.Flow(fc::CTBase.Data.ControlledVectorField, law::CTBase.Data.ControlLaw): compose fc with an OpenLoop/ClosedLoop law into a CTFlows.Flows.ControlledFlow with no OCP.

See also: CTFlows.Flows._controlled_flow.

julia
_flow_from_controlled_vf(
    ::Type{CTBase.Traits.DynClosedLoopFeedback},
    ::CTBase.Data.ControlledVectorField,
    ::CTBase.Data.ControlLaw;
    kwargs...
)

Reject a DynClosedLoop law in CTFlows.Flows.Flow(fc::CTBase.Data.ControlledVectorField, law::CTBase.Data.ControlLaw): a dynamic closed-loop law u(t,x,p,v) needs the costate p, which a state flow of a vector field does not have.

See also: CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw).

_flow_from_ocp [Function] ​

CTFlows.Flows._flow_from_ocp Function
julia
_flow_from_ocp(
    ::Type{CTBase.Traits.ControlFree},
    ocp::CTModels.Models.Model;
    kwargs...
) -> Union{CTFlows.Flows.OptimalControlFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, Nothing, CTFlows.Flows.StateFlow{TD3, CTBase.Traits.Fixed, S1, I1}, Nothing} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, TD3<:CTBase.Traits.TimeDependence, S1<:(CTFlows.Systems.VectorFieldSystem{TD3, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace, F} where F<:(CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD3, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}})), I1<:CTSolvers.Integrators.AbstractIntegrator}, CTFlows.Flows.OptimalControlFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, Nothing, CTFlows.Flows.StateFlow{TD3, CTBase.Traits.NonFixed, S1, I1}, Nothing} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, TD3<:CTBase.Traits.TimeDependence, S1<:(CTFlows.Systems.VectorFieldSystem{TD3, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace, F} where F<:(CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD3, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}})), I1<:CTSolvers.Integrators.AbstractIntegrator}}

Build an OptimalControlFlow from a control-free OCP.

Constructs the OCP Hamiltonian, builds the Hamiltonian system with the chosen AD backend, and wraps the resulting flow together with the OCP reference.

See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows.Flow, CTFlows.Flows._ocp_hamiltonian.

julia
_flow_from_ocp(
    ::Type{CTBase.Traits.WithControl},
    ::CTModels.Models.Model;
    kwargs...
)

Reject Flow(ocp) construction from a with-control OCP.

Throws PreconditionError because this path assumes no control input. Use Flow(ocp, law) to pass a control law that closes the loop.

See also: CTFlows.Flows.Flow, CTFlows.Flows._ocp_hamiltonian.

_flow_from_ocp_control [Function] ​

CTFlows.Flows._flow_from_ocp_control Function
julia
_flow_from_ocp_control(
    ::Type{CTBase.Traits.DynClosedLoopFeedback},
    ocp::CTModels.Models.Model,
    law::CTBase.Data.ControlLaw;
    kwargs...
) -> Union{CTFlows.Flows.OptimalControlFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, CTBase.Data.ControlLaw{F, FB, TD3, VD2}, Nothing, CTFlows.Flows._UnlabelledPathDuals} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, F<:Function, FB<:CTBase.Traits.AbstractFeedback, TD3<:CTBase.Traits.TimeDependence, VD2<:CTBase.Traits.VariableDependence}, CTFlows.Flows.OptimalControlFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, CTBase.Data.ControlLaw{F, FB, TD3, VD2}, Nothing, CTFlows.Flows._FlowDuals{P}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, F<:Function, FB<:CTBase.Traits.AbstractFeedback, TD3<:CTBase.Traits.TimeDependence, VD2<:CTBase.Traits.VariableDependence, P<:Tuple}}

Build an CTFlows.Flows.OptimalControlFlow from the OCP pseudo-Hamiltonian and a DynClosedLoop law, dispatching on the hamiltonian_type action option.

If the constraints or multipliers of multipliers are raw Functions with a single method, their arity is checked against the OCP's time/variable dependence — see CTFlows.Flows._check_convenience_arities. law itself is not checked here: it may have been built explicitly with traits that deliberately differ from the OCP's (the arity of a raw u is only checked in CTFlows.Flows.Flow(ocp::CTModels.Models.Model, u::Function), which builds the law itself from the OCP's traits).

Throws

See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Flows._ocp_pseudo_hamiltonian, CTFlows.Flows._check_convenience_arities.

julia
_flow_from_ocp_control(
    ::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
    ocp::CTModels.Models.Model,
    law::CTBase.Data.ControlLaw;
    kwargs...
) -> CTFlows.Flows.ControlledFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, CTBase.Data.ControlLaw{F, FB, TD3, VD2}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, F<:Function, FB<:CTBase.Traits.AbstractFeedback, TD3<:CTBase.Traits.TimeDependence, VD2<:CTBase.Traits.VariableDependence}

Build a CTFlows.Flows.ControlledFlow (state flow) from the OCP controlled dynamics and an OpenLoop/ClosedLoop law.

See also: CTFlows.Flows._controlled_flow, CTFlows.Flows._ocp_controlled_vector_field.

_flow_from_pseudo_hamiltonian [Function] ​

CTFlows.Flows._flow_from_pseudo_hamiltonian Function
julia
_flow_from_pseudo_hamiltonian(
    ::Type{CTBase.Traits.DynClosedLoopFeedback},
    h̃::CTBase.Data.PseudoHamiltonian,
    law::CTBase.Data.ControlLaw;
    kwargs...
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}}

Dispatch helper for CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw): build a Hamiltonian flow from a DynClosedLoop law, routing on the hamiltonian_type action option.

See also: CTFlows.Flows._build_pseudo_flow.

julia
_flow_from_pseudo_hamiltonian(
    ::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
    ::CTBase.Data.PseudoHamiltonian,
    ::CTBase.Data.ControlLaw;
    kwargs...
)

Reject OpenLoop/ClosedLoop laws in CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw): a pseudo-Hamiltonian H̃(t,x,p,u,v) depends on the costate p, which OpenLoop/ClosedLoop laws do not provide.

See also: CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw).

_flow_from_pseudo_hamiltonian_vf [Function] ​

CTFlows.Flows._flow_from_pseudo_hamiltonian_vf Function
julia
_flow_from_pseudo_hamiltonian_vf(
    ::Type{CTBase.Traits.DynClosedLoopFeedback},
    h̃vf::CTBase.Data.PseudoHamiltonianVectorField,
    law::CTBase.Data.ControlLaw;
    opts...
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianVectorFieldSystem{F, TD, VD} where F<:Function)}

Dispatch helper for CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw): build a PseudoHamiltonianVectorFieldSystem-backed Hamiltonian flow from a DynClosedLoop law.

See also: CTFlows.Systems.build_system.

julia
_flow_from_pseudo_hamiltonian_vf(
    ::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
    ::CTBase.Data.PseudoHamiltonianVectorField,
    ::CTBase.Data.ControlLaw;
    opts...
)

Reject OpenLoop/ClosedLoop laws in CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw): a pseudo-Hamiltonian vector field h̃vf(t,x,p,u,v) depends on the costate p, which OpenLoop/ClosedLoop laws do not provide.

See also: CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw).

_flow_objective [Function] ​

CTFlows.Flows._flow_objective Function
julia
_flow_objective(ocp, x, u, v, t0, tf, integ) -> Any

Compute the objective value (Mayer + Lagrange) of an OCP along a trajectory, given callable state x(t) and control u(t) and the variable v.

The Mayer term is evaluated at the endpoints x(t0) and x(tf). The Lagrange term is integrated by flowing ℓ̇(t) = ℓ(t, x(t), u(t), v) from t0 to tf on a scalar cost state: under the "1-D = scalar" convention the out-of-place right-hand side is wrapped in an IPVFOoPRHS, and that wrapper — not the state — supplies SciML's mutable in-place buffer. Shared core of both the Hamiltonian (OptimalControlFlow) and state (ControlledFlow) objective paths; each caller builds its own x, u, v and delegates here.

See also: CTFlows.Flows._control_of, CTFlows.Flows._build_ocp_solution, CTFlows.Flows._state_flow_objective.

_flow_state_coerce [Function] ​

CTFlows.Flows._flow_state_coerce Function
julia
_flow_state_coerce(
    ocp,
    _::AbstractMatrix
) -> typeof(identity)

Precomputed state coercion (only for a 1-D state, identity otherwise) from the OCP's declared state dimension. Unlike CTFlows.Flows._dim_coerce alone, this also special-cases a batched Matrix x0 to always return identity, regardless of the declared dimension — _dim_coerce is baked in from the OCP's declared dimension and cannot see x0's runtime shape by itself. Fixing it here (the single source of coerce) covers every later application of the returned function, including inside CTFlows.Trajectories.StateFlowTrajectory.

julia
_flow_state_coerce(ocp, x0) -> typeof(identity)

State coercion from the OCP's declared state dimension for a non-batched x0: only for a 1-D state, identity otherwise.

See also: CTFlows.Flows._flow_state_coerce, CTFlows.Flows._dim_coerce.

julia
_flow_state_coerce(
    _::Nothing,
    _::AbstractMatrix
) -> typeof(identity)

Precomputed state coercion (only for a 1-D state, identity otherwise) inferred from x0 when there is no OCP (Flow(fc, law)); a batched Matrix x0 always yields identity — see CTFlows.Flows._flow_state_coerce.

julia
_flow_state_coerce(_::Nothing, x0) -> typeof(identity)

Precomputed state coercion (only for a 1-D state, identity otherwise) inferred from x0 when there is no OCP (Flow(fc, law)): a Matrix x0 always yields identity (see CTFlows.Flows._flow_state_coerce).

See also: CTFlows.Flows._flow_state_coerce, CTFlows.Flows._dim_coerce.

_integrator_device [Function] ​

CTFlows.Flows._integrator_device Function
julia
_integrator_device(_::CTSolvers.Integrators.SciML{P}) -> Any

Device parameter (CTBase.Strategies.CPU or CTBase.Strategies.GPU) of an integrator, or nothing for an integrator that is not device-parameterized.

_invoke_flow [Function] ​

CTFlows.Flows._invoke_flow Function
julia
_invoke_flow(
    flow::CTFlows.Flows.AbstractFlow,
    config::CTFlows.Configs.AbstractConfig;
    variable,
    unsafe
)

Solve an ODE problem using a flow with trait-based dispatch on the variable parameter.

This function dispatches to one of four specialized implementations based on:

  • The flow's VariableDependence trait (Fixed or NonFixed)

  • Whether the variable parameter was provided (NotProvided vs any other type)

Dispatch Rules

  • Fixed + NotProvided: Variable not required, proceeds with variable=nothing.

  • Fixed + provided: Throws PreconditionError (Fixed systems must not receive a variable).

  • NonFixed + provided: Variable required, proceeds with the provided value.

  • NonFixed + NotProvided: Throws PreconditionError (NonFixed systems require a variable).

Arguments

  • flow::CTFlows.Flows.AbstractFlow: The flow to solve.

  • config::CTFlows.Configs.AbstractConfig: The integration configuration (e.g., StateEndPointConfig, StateTrajectoryConfig).

  • variable: The variable parameter value (required for NonFixed systems, must be omitted for Fixed systems).

  • unsafe: If true, bypass ODE solver retcode checking and return what was computed up to an integration failure; if false, throw SolverFailure on integration failure, with the call in its context and a suggestion to call the flow with unsafe=true.

Returns

  • The packaged solution (type varies by config type).

Throws

  • CTBase.Exceptions.PreconditionError: If the variable parameter violates the flow's trait contract.

Example

julia
# Fixed flow: no variable parameter allowed
flow_fixed = Flow(system_fixed, integrator)
config = CTFlows.Configs.StateTrajectoryConfig((0.0, 1.0), [1.0, 0.0])
sol = _invoke_flow(flow_fixed, config; unsafe=false)  # OK, no variable

# NonFixed flow: variable parameter required
flow_nonfixed = Flow(system_nonfixed, integrator)
sol = _invoke_flow(flow_nonfixed, config; variable=0.5, unsafe=false)  # OK, variable provided

See also: CTFlows.Flows.AbstractFlow, CTBase.Traits.VariableDependence, CTBase.Core.NotProvided, CTFlows.Integrators.build_problem, CommonSolve.solve, CTFlows.Trajectories.build_trajectory.

julia
_invoke_flow(
    ::Type{CTBase.Traits.NonFixed},
    ::Type{CTBase.Core.NotProvidedType},
    flow,
    config;
    unsafe,
    variable
)

Dispatch for NonFixed flows when the variable parameter was not provided.

This overload is selected when a NonFixed flow (which requires a variable) is called without providing the variable argument. It throws a PreconditionError to enforce the contract that NonFixed systems must receive a variable parameter.

Throws

  • CTBase.Exceptions.PreconditionError: Always, with message explaining that a variable is required.

See also

CTBase.Traits.NonFixed, CTBase.Core.NotProvided.

julia
_invoke_flow(
    ::Type{CTBase.Traits.Fixed},
    ::Type{CTBase.Core.NotProvidedType},
    flow,
    config;
    unsafe,
    variable
)

Dispatch for Fixed flows when the variable parameter was not provided.

This overload is selected when a Fixed flow (which does not require a variable) is called without providing the variable argument. This is the expected and valid case, so it forwards to _core_invoke_flow with variable=nothing.

Returns

  • The result of _core_invoke_flow.

See also

CTBase.Traits.Fixed, CTBase.Core.NotProvided, CTFlows.Flows._core_invoke_flow.

julia
_invoke_flow(
    ::Type{CTBase.Traits.NonFixed},
    ::Type{VT},
    flow,
    config;
    unsafe,
    variable
)

Dispatch for NonFixed flows when a variable parameter is provided.

This overload is selected when a NonFixed flow (which requires a variable) is called with a provided variable parameter. This is the expected and valid case, so it forwards to _core_invoke_flow with the provided variable value.

Returns

  • The result of _core_invoke_flow.

See also

CTBase.Traits.NonFixed, CTFlows.Flows._core_invoke_flow.

julia
_invoke_flow(
    ::Type{CTBase.Traits.Fixed},
    ::Type{VT},
    flow,
    config;
    unsafe,
    variable
)

Dispatch for Fixed flows when a variable parameter is provided.

This overload is selected when a Fixed flow (which does not require a variable) is called with a provided variable parameter. This violates the contract that Fixed systems must not receive a variable parameter, so it throws a PreconditionError.

Throws

  • CTBase.Exceptions.PreconditionError: Always, with message explaining that variables must not be provided to Fixed flows.

See also

CTBase.Traits.Fixed.

julia
_invoke_flow(
    VD::Type{<:CTBase.Traits.VariableDependence},
    ::Type{VT},
    flow,
    config;
    unsafe,
    variable
)

Catch-all fallback for an unforeseen VariableDependence trait value.

The four overloads above form a dispatch table that is exhaustive for the closed set {Fixed, NonFixed}. This fallback exists only so a hypothetical third tag fails with a clean CTBase.Exceptions.PreconditionError instead of a raw MethodError.

Throws

_invoke_flow_variable_costate [Function] ​

CTFlows.Flows._invoke_flow_variable_costate Function
julia
_invoke_flow_variable_costate(
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.AbstractHamiltonianConfig;
    variable,
    unsafe
)

Call a Hamiltonian flow with variable costate integration.

Dispatches on the flow's variable_costate_trait to determine if augmented integration is supported.

Arguments

  • flow::AbstractHamiltonianFlow: The Hamiltonian flow.

  • config::Configs.AbstractHamiltonianConfig: The Hamiltonian point configuration.

  • variable: The variable parameter value.

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • The augmented solution (xf, pf, pvf) if supported, or throws an error.

Throws

  • CTBase.Exceptions.IncorrectArgument: If the flow does not support variable costate.

See also: CTBase.Traits.variable_costate_trait, CTBase.Traits.SupportsVariableCostate, CTBase.Traits.NoVariableCostate.

julia
_invoke_flow_variable_costate(
    ::Type{CTBase.Traits.NoVariableCostate},
    ::Type{VT},
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.HamiltonianEndPointConfig;
    variable,
    unsafe
)

Variable costate call for flows that do not support it.

This method handles the error case where a flow does not support variable costate computation (typically because the Hamiltonian is not variable-dependent).

Throws

  • CTBase.Exceptions.PreconditionError: Always, with a descriptive message indicating that the flow does not support variable costate.

See also: CTBase.Traits.NoVariableCostate.

julia
_invoke_flow_variable_costate(
    ::Type{CTBase.Traits.SupportsVariableCostate},
    ::Type{VT},
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.HamiltonianEndPointConfig;
    variable,
    unsafe
)

Variable costate call for flows that support it.

Constructs an AugmentedHamiltonianEndPointConfig with zero initial variable costate and calls the flow with it.

Arguments

  • ::Type{Traits.SupportsVariableCostate}: The capability trait.

  • flow::AbstractHamiltonianFlow: The Hamiltonian flow.

  • config::Configs.HamiltonianEndPointConfig: The base Hamiltonian point configuration.

  • variable: The variable parameter value.

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • Tuple{AbstractVector, AbstractVector, AbstractVector}: The augmented solution (xf, pf, pvf).

See also: CTBase.Traits.SupportsVariableCostate, CTFlows.Configs.AugmentedHamiltonianEndPointConfig.

julia
_invoke_flow_variable_costate(
    ::Type{CTBase.Traits.SupportsVariableCostate},
    ::Type{CTBase.Core.NotProvidedType},
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.HamiltonianEndPointConfig;
    variable,
    unsafe
)

Variable costate call when the variable parameter is not provided.

This method handles the error case where a flow supports variable costate computation but the user did not provide the required variable parameter.

Throws

  • CTBase.Exceptions.PreconditionError: Always, with a descriptive message indicating that the variable parameter must be provided.

See also: CTBase.Traits.SupportsVariableCostate, CTBase.Core.NotProvided.

julia
_invoke_flow_variable_costate(
    ::Type{<:CTBase.Traits.AbstractVariableCostateCapability},
    ::Type{VT},
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.HamiltonianTrajectoryConfig;
    variable,
    unsafe
)

Variable costate call for trajectory configurations.

Variable costate computation is only supported for point configurations, not trajectory configurations. This method throws an error when attempting to use variable_costate=true with a trajectory configuration, whatever the flow's variable-costate capability (SupportsVariableCostate or NoVariableCostate): the call form is rejected first.

Throws

  • CTBase.Exceptions.PreconditionError: Always, with a descriptive message indicating that variable_costate is only supported for point configurations.

See also: CTBase.Traits.AbstractVariableCostateCapability, CTFlows.Configs.HamiltonianTrajectoryConfig.

julia
_invoke_flow_variable_costate(
    cap::Type{<:CTBase.Traits.AbstractVariableCostateCapability},
    ::Type{VT},
    flow::CTFlows.Flows.AbstractHamiltonianFlow,
    config::CTFlows.Configs.AbstractHamiltonianConfig;
    variable,
    unsafe
)

Catch-all fallback for an unforeseen variable-costate capability trait value.

The overloads above form a dispatch table that is exhaustive for the closed set {SupportsVariableCostate, NoVariableCostate}. This fallback exists only so a hypothetical third capability tag fails with a clean CTBase.Exceptions.PreconditionError instead of a raw MethodError.

Throws

_is_host_array [Function] ​

CTFlows.Flows._is_host_array Function
julia
_is_host_array(x) -> Bool

Whether x is a dense host array. Numbers (a 1-D state is a scalar) and device arrays are not.

_is_labelled [Function] ​

CTFlows.Flows._is_labelled Function
julia
_is_labelled(_::Symbol) -> Bool

Whether a constraint specification gives the constraints by their label: a Symbol, or a tuple of Symbols. Labelled constraints are adjoined by CTModels (CTBase.Data.pseudo_hamiltonian(ocp; constraints=labels)), with the multiplier in the dual convention of the solution, and their duals are placed in the solution. A constraint given as a function (or a CTBase.Data.PathConstraint) is adjoined here as μ·g with g ≥ 0, and has no dual in the solution.

Throws

See also: CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.

_label_action_def [Function] ​

CTFlows.Flows._label_action_def Function
julia
_label_action_def(

) -> CTBase.Options.OptionDefinition{String}

Return the definition of the label action option, accepted by every flow constructor: the label of the phase the flow integrates (e.g. "bang"), default CTFlows.Flows.__label (no label).

It is routed as an action option, like hamiltonian_type, so it is checked by the orchestration (type, unknown or misplaced options) and never mistaken for a strategy option; CTFlows.Flows._route_flow_options adds it to every routing.

See also: CTFlows.Flows._routed_label, CTFlows.Flows.label.

_labels [Function] ​

CTFlows.Flows._labels Function
julia
_labels(spec::Symbol) -> Tuple{Symbol}

The labels of a labelled constraint specification, as a tuple.

_limit_rows [Function] ​

CTFlows.Flows._limit_rows Function
julia
_limit_rows(values::AbstractVector) -> Matrix{Float64}

Stack values (scalars for one component, vectors otherwise) as the rows of a matrix: one row per switching time. No value gives a 0 × 0 matrix.

_missing_duals_note [Function] ​

CTFlows.Flows._missing_duals_note Function
julia
_missing_duals_note(
    _::CTFlows.Flows._UnlabelledPathDuals
) -> String

The note stored in infos(sol)[:missing_duals] of the solution of a flow: CTModels uses it as the suggestion of the PreconditionError that dual(sol, ocp, :label) throws for a dual the flow did not rebuild. It says why the dual is missing and how to get it.

_mooncake_eltype [Function] ​

CTFlows.Flows._mooncake_eltype Function
julia
_mooncake_eltype(
    _::Type{<:Union{Float16, Float32, Float64, Integer}}
) -> Bool

Whether AutoMooncake can differentiate through a value of element type T: an IEEE float or an integer (an integer time is promoted by the integrator). A ForwardDiff.Dual (the flow differentiated by an outer ForwardDiff) or a BigFloat is refused by Mooncake.

_multiplier_rows [Function] ​

CTFlows.Flows._multiplier_rows Function
julia
_multiplier_rows(y::Number) -> Int64

The number of components of the value of a multiplier: 1 for a number, its length for a vector, its number of rows for a batched value (a Matrix, one column per point).

_multiplier_specs [Function] ​

CTFlows.Flows._multiplier_specs Function
julia
_multiplier_specs(_::Nothing) -> Tuple{Nothing, Nothing}

Split the value of the keyword multipliers into the constraints and the multipliers the flow builders take, (cspec, mspec): (nothing, nothing) for no constraint, the constraint and the multiplier of a single pair, or two tuples, element i of one paired with element i of the other, for several pairs.

Arguments

  • multipliers: nothing, an empty collection, a Pair constraint => multiplier, a Tuple or an AbstractVector of such pairs, a NamedTuple (label = multiplier) or an AbstractDict.

Returns

  • Tuple{Any,Any}: (cspec, mspec).

Throws

See also: CTFlows.Flows._reject_removed_constraint_keywords, CTFlows.Flows._build_ocp_pseudo_flow.

_natural_syntax [Function] ​

CTFlows.Flows._natural_syntax Function
julia
_natural_syntax(
    label::AbstractString,
    second::AbstractString,
    ocp
) -> String

Natural-syntax example for a raw convenience function, given its symbol and second argument name and an OCP's time/variable dependence — used in arity-mismatch messages.

Arguments

  • label::AbstractString: the symbol name shown in the example (e.g. "u").

  • second::AbstractString: the name of the second natural argument ("p" for a control law/multiplier, "u" for a constraint).

  • ocp::CTModels.Models.Model: the OCP, used to read its time/variable dependence.

Returns

  • String: e.g. "u(t, x, p)".

See also: CTFlows.Flows._arity_issue.

_not_a_pair [Function] ​

CTFlows.Flows._not_a_pair Function
julia
_not_a_pair(x, where::AbstractString)

Throw the error of a multipliers value (or of one of its elements, named by where) that is not a constraint => multiplier pair.

Throws

_ocp_constrained_pseudo_hamiltonian [Function] ​

CTFlows.Flows._ocp_constrained_pseudo_hamiltonian Function
julia
_ocp_constrained_pseudo_hamiltonian(
    ocp,
    g;
    p0
) -> CTBase.Data.ConstrainedPseudoHamiltonian{CTFlows.Flows._AdjoinedConstraint{TD, VD, H, G}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H, G}

The constrained pseudo-Hamiltonian H(t,x,p,u,μ,v) = H̃(t,x,p,u,v) + μ·g(t,x,u,v) of an OCP and a resolved constraint g, as a CTBase.Data.ConstrainedPseudoHamiltonian with the traits of the OCP. The :partial mode freezes the multiplier in it; the :total mode composes it with the law and the multiplier.

See also: CTFlows.Flows._AdjoinedConstraint, CTFlows.Flows._resolve_constraint.

_ocp_controlled_vector_field [Function] ​

CTFlows.Flows._ocp_controlled_vector_field Function
julia
_ocp_controlled_vector_field(
    ocp
) -> Union{CTBase.Data.ControlledVectorField{CTFlows.Flows.OCPControlledVectorFieldFunction{TD, VD, DF, CX, CU, CV}, TD1, CTBase.Traits.Fixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}, CTBase.Data.ControlledVectorField{CTFlows.Flows.OCPControlledVectorFieldFunction{TD, VD, DF, CX, CU, CV}, TD1, CTBase.Traits.NonFixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}}

Build an CTFlows.Flows.OCPControlledVectorFieldFunction from an OCP and wrap it in a CTBase.Data.ControlledVectorField.

See also: CTFlows.Flows.OCPControlledVectorFieldFunction, CTFlows.Flows._ocp_pseudo_hamiltonian.

_ocp_controlled_vf [Function] ​

CTFlows.Flows._ocp_controlled_vf Function
julia
_ocp_controlled_vf(
    h::CTFlows.Flows.OCPControlledVectorFieldFunction,
    t,
    x,
    u,
    v
) -> Any

Core computation of the OCP controlled dynamics fc(t,x,u,v): coerce x/u/v with the precomputed per-dimension coercions (scalar for 1-D; a batched Matrix is always left untouched via CTFlows.Flows._apply_dim_coerce), fill a buffer with the in-place dynamics (n_x × batch for a Matrix state — see CTFlows.Systems._buffer_like), and return it (scalar for a 1-D state).

See also: CTFlows.Flows.OCPControlledVectorFieldFunction.

_ocp_hamiltonian [Function] ​

CTFlows.Flows._ocp_hamiltonian Function
julia
_ocp_hamiltonian(ocp; p0) -> Any

The Hamiltonian of a control-free OCP, a Data.Hamiltonian with the uniform (t, x, p, v) interface: built by CTBase.Data.hamiltonian (control-toolbox/CTModels.jl#532).

See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows.Flow.

_ocp_pseudo_hamiltonian [Function] ​

CTFlows.Flows._ocp_pseudo_hamiltonian Function
julia
_ocp_pseudo_hamiltonian(ocp; p0) -> Any

The pseudo-Hamiltonian of an OCP, a CTBase.Data.PseudoHamiltonian with the uniform (t, x, p, u, v) interface used by the pseudo-Hamiltonian AD pipeline: built by CTBase.Data.pseudo_hamiltonian (control-toolbox/CTModels.jl#532).

See also: CTFlows.Flows._ocp_hamiltonian.

_ocp_state_vector_field [Function] ​

CTFlows.Flows._ocp_state_vector_field Function
julia
_ocp_state_vector_field(
    ocp
) -> Union{CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD1, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}, CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD1, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}}

Build an CTFlows.Flows.OCPStateVectorFieldFunction from a control-free OCP and wrap it in a CTBase.Data.VectorField (out-of-place).

See also: CTFlows.Flows.OCPStateVectorFieldFunction, CTFlows.Flows._ocp_controlled_vector_field.

_ocp_state_vf [Function] ​

CTFlows.Flows._ocp_state_vf Function
julia
_ocp_state_vf(
    h::CTFlows.Flows.OCPStateVectorFieldFunction,
    t,
    x,
    v
) -> Any

Core computation of the control-free OCP state dynamics g(t,x,v) = f(t,x,∅,v): coerce x/v with the precomputed per-dimension coercions (scalar for 1-D; a batched Matrix is always left untouched via CTFlows.Flows._apply_dim_coerce), fill a buffer with the in-place dynamics called with an empty control (n_x × batch for a Matrix state), and return it (scalar for a 1-D state).

See also: CTFlows.Flows.OCPStateVectorFieldFunction.

_ocp_switching_model [Function] ​

CTFlows.Flows._ocp_switching_model Function
julia
_ocp_switching_model(
    sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
    law,
    variable,
    labels::AbstractVector{<:AbstractString};
    duals
) -> Union{CTModels.Solutions.EmptySwitchingModel, CTModels.Solutions.SwitchingModel}

Build the switching structure of the Solution of an OCP flow from its Hamiltonian trajectory: the switching times of the trajectory, the phase labels labels (one per phase), and the left and right limits of the state, costate and control at every switching time. The control limits come from the law: the left limit from the law of the phase that ends (at the values before the jump), the right one from the law of the next phase (at the values after it), see CTFlows.Flows._right_ocp_control. The limits of the duals of the constraints, by label, come from the duals of the flow in the same way, see CTFlows.Flows._switching_duals.

Returns an CTModels.Solutions.EmptySwitchingModel when there is no switching time and no label.

_p0_kwargs [Function] ​

CTFlows.Flows._p0_kwargs Function
julia
_p0_kwargs(
    p0
) -> Union{@NamedTuple{}, NamedTuple{(:p0,), <:Tuple{Any}}}

The keyword arguments (; p0) for the CTModels getters, or none when p0 is nothing: the getter then uses its default, p⁰ = -1 for a minimisation and +1 for a maximisation (ct-conventions SGN4). p0 = 0 is the abnormal case.

_path_labels [Function] ​

CTFlows.Flows._path_labels Function
julia
_path_labels(ocp) -> Any

The path labels of ocp, in the order of the stacked path constraint, with their number of rows.

_pop_backend_instance [Function] ​

CTFlows.Flows._pop_backend_instance Function
julia
_pop_backend_instance(
    _::Type{CTBase.Traits.WithAD},
    kwargs
) -> Union{Tuple{Nothing, Any}, Tuple{CTBase.Differentiation.AbstractADBackend, NamedTuple}}

Split a ready-built AD backend strategy off a flow constructor's keyword arguments, giving (backend, rest). With an AD-backed plan (Traits.WithAD), ad_backend=b where b is a CTBase.Differentiation.AbstractADBackend is the strategy itself (explicit mode, as a typed component of solve), not a value of the :ad_backend option of the :di strategy: it is popped before routing, and CTFlows.Flows._build_flow_components uses it in place of the backend it builds. An ADTypes value is left in place and routed as the option, as before (control-toolbox/CTBase.jl#676).

Returns (nothing, rest) when there is no such strategy, and always for an AD-free plan (Traits.WithoutAD), where ad_backend stays an unknown option.

See also: CTFlows.Flows._route_flow_options, CTFlows.Flows._check_backend_parameter.

_pop_method [Function] ​

CTFlows.Flows._pop_method Function
julia
_pop_method(kwargs) -> Tuple{Any, NamedTuple}

Split a flow constructor's keyword arguments into (method, rest): the device selection (method=:gpu, a Symbol or token tuple; nothing if absent) and the remaining strategy options. method rides along in every constructor's kwargs... and is popped here, at the routing boundary, so it is never mistaken for a strategy option.

See also: CTFlows.Flows._flow_description, CTFlows.Flows._route_flow_options.

_pop_p0 [Function] ​

CTFlows.Flows._pop_p0 Function
julia
_pop_p0(kwargs) -> Tuple{Any, NamedTuple}

Split the cost multiplier p0 off a flow constructor's keyword arguments, giving (p0, rest) (p0 = nothing if absent): it is an option of the Hamiltonian of the OCP, not a strategy option, so it is popped before routing, like method.

See also: CTFlows.Flows._pop_method.

_regrid_hamiltonian [Function] ​

CTFlows.Flows._regrid_hamiltonian Function
julia
_regrid_hamiltonian(
    sol,
    _::Union{Nothing, AbstractVector},
    law,
    variable,
    bounds
) -> Any

No generated grid: the Hamiltonian trajectory is returned unchanged.

julia
_regrid_hamiltonian(
    sol,
    spec::CTFlows.Configs.AbstractGrid,
    law,
    variable,
    bounds
) -> Union{CTFlows.Trajectories.HamiltonianVectorFieldTrajectory, CTFlows.Trajectories.StateFlowTrajectory}

Regrid a Hamiltonian trajectory on the generated grid spec, whose plotted curves are the state, the costate and, when there is a law, the reconstructed control.

See also: CTFlows.Trajectories.apply_generated_grid.

_regrid_state [Function] ​

CTFlows.Flows._regrid_state Function
julia
_regrid_state(
    traj,
    _::Union{Nothing, AbstractVector},
    law,
    variable,
    coerce,
    bounds
) -> Any

No generated grid: the state trajectory is returned unchanged.

julia
_regrid_state(
    traj,
    spec::CTFlows.Configs.AbstractGrid,
    law,
    variable,
    coerce,
    bounds
) -> CTFlows.Trajectories.VectorFieldTrajectory

Regrid a state trajectory on the generated grid spec, whose plotted curves are the state and, when there is a law, the reconstructed control.

See also: CTFlows.Trajectories.apply_generated_grid.

_reject_control_free_constraint [Function] ​

CTFlows.Flows._reject_control_free_constraint Function
julia
_reject_control_free_constraint(kwargs)

Reject a multipliers keyword on a control-free Flow(ocp).

Constrained flows are only defined for the with-control case Flow(ocp, law; …), where the constraint term μ·g enters the pseudo-Hamiltonian H̃ + μ·g alongside the control. With no control law there is no pseudo-Hamiltonian to augment, so a state constraint has no well-defined place in the control-free OCP Hamiltonian flow. Throws CTBase.Exceptions.PreconditionError.

See also: CTFlows.Flows.Flow.

_reject_removed_constraint_keywords [Function] ​

CTFlows.Flows._reject_removed_constraint_keywords Function
julia
_reject_removed_constraint_keywords(kwargs)

Reject the keywords constraint and multiplier, replaced by multipliers (control-toolbox/CTFlows.jl#543): a constraint and its multiplier are given together, as a constraint => multiplier pair, the shape of CTBase.Data.hamiltonian(ocp, u; multipliers).

Throws

See also: CTFlows.Flows._multiplier_specs.

_reject_saveat [Function] ​

CTFlows.Flows._reject_saveat Function
julia
_reject_saveat(integ)

Reject an output grid imposed at the call when the integrator already sets saveat.

Throws

  • CTBase.Exceptions.IncorrectArgument: If Integrators.has_saveat(integ).

_require_state_flow [Function] ​

CTFlows.Flows._require_state_flow Function
julia
_require_state_flow(
    F::CTFlows.Flows.OptimalControlFlow
) -> Any

Return F.state_flow, or throw a CTBase.Exceptions.PreconditionError when the flow was not built from a control-free OCP (Flow(ocp)) — a flow built with a DynClosedLoop control law (Flow(ocp, law)) has no state-only flow, since its dynamics depend on the costate p(t).

See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows._ocp_state_vector_field.

_resolve_constraint [Function] ​

CTFlows.Flows._resolve_constraint Function
julia
_resolve_constraint(
    _,
    spec::CTBase.Data.PathConstraint
) -> CTBase.Data.PathConstraint

Return a PathConstraint spec as-is — it is already a resolved CTBase.Data.PathConstraint.

See also: CTFlows.Flows._resolve_constraint, CTBase.Data.PathConstraint.

julia
_resolve_constraint(
    ocp,
    spec::Function
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:Function

Resolve a Function constraint spec into a CTBase.Data.MixedConstraint, inferring autonomy and variable-dependence from the OCP.

See also: CTFlows.Flows._resolve_constraint, CTBase.Data.MixedConstraint.

julia
_resolve_constraint(
    ocp,
    spec::Tuple
) -> CTFlows.Flows._CombinedConstraint

Resolve a Tuple of constraint specs into a CTFlows.Flows._CombinedConstraint, rejecting an empty tuple with CTBase.Exceptions.IncorrectArgument.

Throws

See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._CombinedConstraint.

julia
_resolve_constraint(_, spec) -> CTBase.Data.PathConstraint

Throw an CTBase.Exceptions.IncorrectArgument for an unsupported constraint spec type. Only a Function, a Tuple of them, or a CTBase.Data.PathConstraint reach this resolution; labels go to CTModels (see CTFlows.Flows._is_labelled).

Throws

See also: CTFlows.Flows._resolve_constraint.

_resolve_multiplier [Function] ​

CTFlows.Flows._resolve_multiplier Function
julia
_resolve_multiplier(
    _,
    spec::CTBase.Data.Multiplier
) -> CTBase.Data.Multiplier

Resolve a multiplier specification into a CTBase.Data.Multiplier.

  • spec::CTBase.Data.Multiplier is used as-is.

  • spec::Function is a raw function with the OCP's natural arity ((x,p), (t,x,p), (x,p,v) or (t,x,p,v)), wrapped in a CTBase.Data.Multiplier with the OCP's time/variable dependence.

  • spec::Tuple is a non-empty tuple of multipliers, each resolved recursively and wrapped in a CTFlows.Flows._CombinedMultiplier — matched element-wise with the constraint tuple (empty tuple rejected with CTBase.Exceptions.IncorrectArgument).

See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.

julia
_resolve_multiplier(
    ocp,
    spec::Function
) -> CTBase.Data.Multiplier

Resolve a Function multiplier spec into a CTBase.Data.Multiplier, inferring autonomy and variable-dependence from the OCP.

See also: CTFlows.Flows._resolve_multiplier, CTBase.Data.Multiplier.

julia
_resolve_multiplier(
    ocp,
    spec::Tuple
) -> CTBase.Data.Multiplier{CTFlows.Flows._CombinedMultiplier{TD, VD, M}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, M<:Tuple}

Resolve a Tuple of multiplier specs without a constraint spec: no dimension check of the multipliers. See CTFlows.Flows._resolve_multiplier(ocp, spec, cspec).

julia
_resolve_multiplier(
    ocp,
    spec,
    cspec
) -> CTBase.Data.Multiplier{CTFlows.Flows._CombinedMultiplier{TD, VD, M}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, M<:Tuple}

Resolve a multiplier spec knowing the constraint spec it is paired with: only a Tuple uses it, to check each multiplier against the dimension of its constraint. Any other spec is resolved as by CTFlows.Flows._resolve_multiplier(ocp, spec).

julia
_resolve_multiplier(
    ocp,
    spec::Tuple,
    cspec
) -> CTBase.Data.Multiplier{CTFlows.Flows._CombinedMultiplier{TD, VD, M}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, M<:Tuple}

Resolve a Tuple of multiplier specs into a CTBase.Data.Multiplier wrapping a CTFlows.Flows._CombinedMultiplier, with the joined traits; rejects an empty tuple with CTBase.Exceptions.IncorrectArgument. When the constraint spec cspec is a tuple of the same length, the value of each multiplier is checked against the dimension of its constraint given by its label (see CTFlows.Flows._checked_multiplier_part).

Throws

See also: CTFlows.Flows._resolve_multiplier, CTFlows.Flows._CombinedMultiplier.

julia
_resolve_multiplier(_, spec) -> CTBase.Data.Multiplier

Throw an CTBase.Exceptions.IncorrectArgument for an unsupported multiplier spec type. Only Function, Tuple, and CTBase.Data.Multiplier are accepted.

Throws

See also: CTFlows.Flows._resolve_multiplier.

_right_dual_value [Function] ​

CTFlows.Flows._right_dual_value Function
julia
_right_dual_value(
    d,
    label::Symbol,
    _::Integer,
    t,
    x,
    p,
    v
) -> Any

Dual of the constraint label just after the i-th switching time t, from the state x and costate p after the jump. A single flow has one set of duals; CTFlows.MultiPhase adds the method of the piecewise duals of a multi-phase flow (those of the next phase).

julia
_right_dual_value(
    pd::CTFlows.MultiPhase._PiecewiseDuals,
    label::Symbol,
    i::Integer,
    t,
    x,
    p,
    v
) -> Any

Dual of label just after the i-th switching time: that of the next phase, at the state x and costate p after the jump.

_right_ocp_control [Function] ​

CTFlows.Flows._right_ocp_control Function
julia
_right_ocp_control(law, _::Integer, t, x, p, v) -> Any

Control just after the i-th switching time t, from the state x and costate p after the jump. A single law has no phase, so it is the law itself; CTFlows.MultiPhase adds the method of the piecewise law of a multi-phase flow (the law of the next phase).

julia
_right_ocp_control(
    pl::CTFlows.MultiPhase._PiecewiseControlLaw,
    i::Integer,
    t,
    x,
    p,
    v
) -> Any

Control just after the i-th switching time t, from the state x and costate p after the jump: the law of the next phase. Used to build the switching structure of the Solution of a multi-phase OCP flow.

_route_flow_options [Function] ​

CTFlows.Flows._route_flow_options Function
julia
_route_flow_options(
    ad_trait,
    kwargs;
    method,
    action_defs
) -> NamedTuple

Route all keyword options to the appropriate strategy families for flow construction.

This function wraps CTBase.Orchestration.route_all_options with the families specific to CTFlows flow construction. Options are routed to either the backend family (:di) or the integrator family (:sciml).

Arguments

  • kwargs: All keyword arguments from the user's Flow call (action and strategy options mixed, method already popped).

  • action_defs: the action options of the constructor, on top of the label option that every flow constructor accepts (see CTFlows.Flows._label_action_def).

Returns

  • NamedTuple with fields:
    • action: action-level options (label, plus those of action_defs)

    • strategies: NamedTuple with backend and integrator sub-tuples

Throws

Example

julia
# Route options to backend and integrator
routed = Flows._route_flow_options((; reltol=1e-8, ad_backend=ADTypes.AutoForwardDiff()))
# routed.strategies.integrator contains (reltol = 1e-8,)
# routed.strategies.backend contains (ad_backend = AutoForwardDiff(),)

Notes

  • This function uses :description source mode for user-friendly error messages.

  • An action option shadows a strategy option of the same name (an info message is emitted); route_to passes a value to the strategy instead.

See also: CTFlows.Flows._flow_families, CTFlows.Flows._build_flow_components, CTBase.Orchestration.route_all_options

julia
_route_flow_options(kwargs; action_defs) -> NamedTuple

Back-compat alias: route options using the WithAD plan (the full :di/:sciml families).

See also: CTFlows.Flows._route_flow_options.

_routed_label [Function] ​

CTFlows.Flows._routed_label Function
julia
_routed_label(routed) -> String

Return the label action option of a routing result, as a String (CTFlows.Flows.__label when it is not set).

See also: CTFlows.Flows._label_action_def, CTFlows.Flows._route_flow_options.

_side_removed [Function] ​

CTFlows.Flows._side_removed Function
julia
_side_removed(spec::Pair)

Reject the former label => side form: the multiplier of a labelled constraint is now the dual of the solution, whose sign carries the active side of a two-sided or equality constraint (ct-conventions SGN2, SGN3).

Throws

_solution_duals [Function] ​

CTFlows.Flows._solution_duals Function
julia
_solution_duals(d, x, p, v) -> Dict{Symbol, Any}

The duals of a solution, by label: a CTFlows.Flows._LabelDualFunction for each label with a known dual; empty when the duals cannot be rebuilt.

_solve_flow [Function] ​

CTFlows.Flows._solve_flow Function
julia
_solve_flow(
    flow::CTFlows.Flows.AbstractFlow,
    config::CTFlows.Configs.AbstractConfig;
    variable,
    unsafe
)

Integrate the flow for the configuration config and return the raw integration result.

It checks the call (device and AD backend, issue #436), builds the problem and the options of the configuration, and solves. It is the common part of CTFlows.Flows._core_invoke_flow and of the call that also reports the time the solver reached (CTFlows.Flows._timed).

Arguments

  • flow::CTFlows.Flows.AbstractFlow: The flow to solve.

  • config::CTFlows.Configs.AbstractConfig: The integration configuration.

  • variable: The variable parameter value (may be nothing for Fixed systems).

  • unsafe: If true, bypass ODE solver retcode checking.

Returns

  • CTSolvers.Integrators.AbstractIntegrationResult: The raw integration result.

_spec_arity_issues! [Function] ​

CTFlows.Flows._spec_arity_issues! Function
julia
_spec_arity_issues!(
    issues,
    ocp,
    _::Nothing,
    label,
    second,
    kind
)

No arity issues for a nothing spec — skip the check.

See also: CTFlows.Flows._spec_arity_issues!.

julia
_spec_arity_issues!(
    issues,
    ocp,
    spec::Function,
    label::AbstractString,
    second::AbstractString,
    kind::AbstractString
)

Check the arity of a single Function spec against the OCP's expected arity and push an issue string into issues if they differ.

See also: CTFlows.Flows._check_convenience_arities, CTFlows.Flows._arity_issue.

julia
_spec_arity_issues!(
    issues,
    ocp,
    spec::Tuple,
    label::AbstractString,
    second::AbstractString,
    kind::AbstractString
)

Check the arity of each Function element in a Tuple spec against the OCP's expected arity, pushing an issue string per mismatch into issues. Non-Function elements are skipped.

See also: CTFlows.Flows._check_convenience_arities, CTFlows.Flows._arity_issue.

julia
_spec_arity_issues!(issues, ocp, spec, label, second, kind)

Fallback for an already-resolved spec (not a Function or Tuple): no arity check needed.

See also: CTFlows.Flows._check_convenience_arities.

_state_flow_objective [Function] ​

CTFlows.Flows._state_flow_objective Function
julia
_state_flow_objective(
    _::Nothing,
    traj,
    law,
    variable,
    integ,
    coerce
)

No objective when the state flow was not built from an OCP (e.g. Flow(fc, law)).

julia
_state_flow_objective(
    ocp,
    traj,
    law,
    variable,
    integ,
    coerce
)

Compute the objective (Mayer + Lagrange) of an OCP along a state-flow trajectory.

Builds the (1-D = scalar coerced) state projection x(t) and the reconstructed control u(t) from the law (empty when law === nothing), then delegates to the shared CTFlows.Flows._flow_objective core.

See also: CTFlows.Trajectories.StateFlowTrajectory, CTFlows.Flows._flow_objective, CTFlows.Flows._control_of.

_switching_duals [Function] ​

CTFlows.Flows._switching_duals Function
julia
_switching_duals(
    d,
    taus,
    xl,
    xr,
    pl,
    pr,
    v
) -> Dict{Symbol, Tuple{Matrix{Float64}, Matrix{Float64}}}

Left and right limits of the duals at the switching times taus, by label (one row per switching time), for the switching model of the solution: the left limit from the duals of the phase that ends, at the state xl and costate pl before the jump; the right limit from those of the next phase, at xr and pr after it (see CTFlows.Flows._right_dual_value). Empty when the duals are not known.

_system_ad_backend [Function] ​

CTFlows.Flows._system_ad_backend Function
julia
_system_ad_backend(sys) -> Any

The ADTypes backend of the system of a flow: the backend of an AD system, nothing for an AD-free one.

See also: CTBase.Traits.ad_trait, CTFlows.Systems.backend.

_timed [Function] ​

CTFlows.Flows._timed Function
julia
_timed(
    flow::CTFlows.Flows.AbstractFlow{TD, VD, D}
) -> CTFlows.Flows._TimedFlow

Wrap flow so that its point calls through CTFlows.Flows._invoke_flow return (value, t_reached): the value of the plain call and the last time of the integration, as a primal value.

Example

julia
julia> value, t_reached = Flows._invoke_flow(Flows._timed(flow), config; variable=nothing, unsafe=false)

See also: CTFlows.Flows._TimedFlow.

_traits [Function] ​

CTFlows.Flows._traits Function
julia
_traits(
    _::CTFlows.Flows._CombinedMultiplier{TD, VD}
) -> Tuple{Any, Any}

The joined traits (TD, VD) of a CTFlows.Flows._CombinedMultiplier.

_unsafe_failure [Function] ​

CTFlows.Flows._unsafe_failure Function
julia
_unsafe_failure(
    e::CTBase.Exceptions.SolverFailure,
    config
) -> CTBase.Exceptions.SolverFailure

The failure e of the integration of a flow call, with the context of the call and a suggestion that names unsafe=true: the message and the return code are kept, the suggestion of e is followed by the one on unsafe=true, and the context of e is preceded by the call ("point call of the flow (SciML solve)").

Arguments

  • e::CTBase.Exceptions.SolverFailure: The failure raised by the integrator.

  • config: The configuration of the call, or nothing.

Returns

  • CTBase.Exceptions.SolverFailure: The failure to raise from the flow call.

Example

julia
julia> e = Exceptions.SolverFailure("ODE integration failed"; retcode="Unstable", context="SciML solve");

julia> Flows._unsafe_failure(e, Configs.StateEndPointConfig(0.0, [1.0], 1.0)).context
"point call of the flow (SciML solve)"

See also: CTFlows.Flows._with_unsafe_hint.

_unwrap_option [Function] ​

CTFlows.Flows._unwrap_option Function
julia
_unwrap_option(
    opt::CTBase.Options.OptionValue,
    fallback
) -> Any

Read an action option value from a routed action NamedTuple entry: unwrap an CTBase.Options.OptionValue, or fall back when the entry is nothing.

See also: CTFlows.Flows._flow_action_defs, CTFlows.Flows._route_flow_options.

julia
_unwrap_option(opt, fallback) -> Any

Return opt directly when it is not nothing, or fallback otherwise.

See also: CTFlows.Flows._unwrap_option, CTFlows.Flows._route_flow_options.

_value_eltype [Function] ​

CTFlows.Flows._value_eltype Function
julia
_value_eltype(x::AbstractArray) -> Any

Element type of a value of the call: the element type of an array, the type of a number, nothing for anything else (no variable, NotProvided).

_variable_vector [Function] ​

CTFlows.Flows._variable_vector Function
julia
_variable_vector(
    _::CTBase.Core.NotProvidedType
) -> Vector{Float64}

Convert a variable argument into a Vector{Float64}.

Returns an empty vector when the variable was not provided (Core.NotProvided), a 1-element vector for scalars, and a copy for vectors.

See also: _build_ocp_solution, CTFlows.Flows._flow_objective.

julia
_variable_vector(v::Number) -> Vector

Wrap a scalar variable into a 1-element Vector{Float64}.

See also: CTFlows.Flows._variable_vector.

julia
_variable_vector(v::AbstractVector) -> Any

Copy a vector variable into a Vector{Float64}.

See also: CTFlows.Flows._variable_vector.

_warn_not_dense [Function] ​

CTFlows.Flows._warn_not_dense Function
julia
_warn_not_dense(traj)

Warn (once) when an OCP objective is about to be recomputed from a trajectory that has no dense interpolant (e.g. integrated with dense=false): the state is then only linearly interpolated between the saved points, so the objective — and the reconstructed control — are accurate to the grid spacing, not to the solver tolerances.

See also: CTFlows.Flows._flow_objective, CTSolvers.Integrators.is_dense.

_warn_unlabelled_constraint [Function] ​

CTFlows.Flows._warn_unlabelled_constraint Function
julia
_warn_unlabelled_constraint(ocp)

Warn (once per session) that a constraint given to Flow(ocp, law; multipliers=…) as a function, while the problem has labelled constraints, leaves the solution of the flow without duals: dual(sol, ocp, :label) will throw. The fix is to give the constraint by its label.

_with_flow_label [Function] ​

CTFlows.Flows._with_flow_label Function
julia
_with_flow_label(
    result,
    _::CTFlows.Flows.AbstractFlow
) -> Union{CTFlows.Trajectories.HamiltonianVectorFieldTrajectory, CTFlows.Trajectories.VectorFieldTrajectory}

Give a raw trajectory the label of the flow that computed it; any other result (a point evaluation) is returned as is.

_with_unsafe_hint [Function] ​

CTFlows.Flows._with_unsafe_hint Function
julia
_with_unsafe_hint(solve, config, unsafe::Bool) -> Any

Run the integration solve of a flow call and, when it raises a CTBase.Exceptions.SolverFailure with unsafe=false, raise it again with the context of the flow call and a suggestion that names unsafe=true (issue #523).

The integrator that raises the failure does not know it is called by a flow, so its message cannot mention the unsafe keyword of the flow call, which returns what was computed up to the failure instead of raising. With unsafe=true, solve is called as is. Any other exception is rethrown unchanged.

Arguments

  • solve: A function of no argument that integrates and returns the integration result.

  • config: The configuration of the call (a point or a trajectory configuration), or nothing for a call without configuration; it names the call in the error.

  • unsafe::Bool: The unsafe keyword of the flow call.

Returns

  • The value of solve().

Throws

See also: CTFlows.Flows._solve_flow.

_zero_dual [Function] ​

CTFlows.Flows._zero_dual Function
julia
_zero_dual(n::Int64) -> Union{Float64, Vector{Float64}}

The zero dual of a constraint of n rows: a scalar for one row, a vector otherwise.


From CTFlowsMakie ​

_plot [Function] ​

CTFlowsMakie._plot Function
julia
_plot(
    sol,
    description::Symbol...;
    size,
    kwargs...
) -> Makie.Figure

Internal implementation of Makie.plot for the CTFlows trajectory types.

Builds the figure with CTFlows.TrajectoryPlots.build_figure (which owns the user-facing defaults and throws on an empty description) and renders it via CTBase.Plotting.render on the Makie backend. Returns a Makie.Figure.

_plot! [Function] ​

CTFlowsMakie._plot! Function
julia
_plot!(
    f::Makie.Figure,
    sol,
    description::Symbol...;
    kwargs...
) -> Makie.Figure

Internal implementation of Makie.plot! for the CTFlows trajectory types: build the figure with CTFlows.TrajectoryPlots.build_figure and overlay it onto the existing Makie.Figure f via CTBase.Plotting.render! (Makie backend).


From CTFlows.Configs ​

_check_grid_size [Function] ​

CTFlows.Configs._check_grid_size Function
julia
_check_grid_size(n::Integer, context::String)

Check the number of times of a generated grid.

Throws

  • CTBase.Exceptions.IncorrectArgument: If n < 2.

_grid_spec [Function] ​

CTFlows.Configs._grid_spec Function
julia
_grid_spec(_::Nothing)

Normalize the grid keyword of a trajectory call: nothing (no generated grid), an integer n (uniform grid of n times) or an CTFlows.Configs.AbstractGrid.

Throws

  • CTBase.Exceptions.IncorrectArgument: For any other value (a vector of times is passed in place of the time span, not through grid).

_time_spec [Function] ​

CTFlows.Configs._time_spec Function
julia
_time_spec(
    tspan::Tuple{Real, Real}
) -> Tuple{Tuple{Any, Any}, Nothing}

Time span (t0, tf), no imposed output grid.

julia
_time_spec(
    times::Tuple{Vararg{Real}}
) -> Tuple{Tuple{Any, Any}, Nothing}

Imposed output grid given as a tuple of times.

julia
_time_spec(
    grid::AbstractVector{<:Real}
) -> Tuple{Tuple{Any, Any}, Any}

Imposed output grid: returns the span (first, last) and the grid as a vector of floats.

Throws

  • CTBase.Exceptions.IncorrectArgument: If the grid has fewer than two times or is not strictly monotone.
julia
_time_spec(
    times::Union{Tuple{Vararg{Real}}, AbstractVector{<:Real}},
    grid
) -> Tuple{Tuple{Any, Any}, Any}

Time specification of a trajectory call with a grid keyword: the span and the output grid (a vector of times, a generated grid spec, or nothing).

Throws

  • CTBase.Exceptions.IncorrectArgument: If both a grid of times and grid= are given.

From CTFlows.Display ​

BRANCH_END [Constant] ​

CTFlows.Display.BRANCH_END Constant

Tree-branch prefix for the last field in a list (└─), styled with the muted palette role at print time.

BRANCH_MID [Constant] ​

CTFlows.Display.BRANCH_MID Constant

Tree-branch prefix for a mid-list field (├─), styled with the muted palette role at print time.

format_codes [Function] ​

CTFlows.Display.format_codes Function
julia
format_codes(
    io::IO
) -> @NamedTuple{name::String, type::String, value::String, keyword::String, count::String, label::String, emphasis::String, muted::String, error::String, warning::String, success::String, reset::String, bold::String, dim::String}

Return the palette format codes for io.

Thin wrapper over CTBase.Core.get_format_codes; returns a NamedTuple of ANSI escape strings (name, type, value, keyword, count, label, muted, reset, …) that are empty when colour is disabled on io.

CTFlows.Display.print_field Function
julia
print_field(io::IO, label, value; last, fmt, value_style)

Print one tree branch ├─ label: value (or └─ when last) on its own line.

A leading newline is emitted so the caller prints the header first, then a sequence of fields; no trailing newline is emitted, keeping the standard "no newline after the last field" REPL convention. The branch character and label use the muted/label roles; the value uses value_style (the value role by default). Pass value_style = "" to leave the value unstyled.

When value renders on several lines (e.g. a nested object whose own show is multi-line), continuation lines are indented under the branch character and prefixed with a │ pipe (blanks when last). value is rendered through print (so strings/symbols keep their plain form and objects use their own show), preserving colour from io.

CTFlows.Display.print_fields Function
julia
print_fields(io::IO, fields; fmt)

Print a sequence of branches, automatically marking the last one with └─.

fields is an iterable of (label, value) or (label, value, value_style) tuples; the optional third element overrides the value style for that field (pass "" for plain). This is convenient when some fields are appended conditionally and the "last" field is only known at runtime.

CTFlows.Display.print_header Function
julia
print_header(io::IO, name; fmt)

Print the styled type-name header (no trailing newline).

The name is rendered with the name palette role (bold blue by default).


From CTFlows.Trajectories ​

ControlledStateProjection [Struct] ​

CTFlows.Trajectories.ControlledStateProjection Type
julia
struct ControlledStateProjection{T<:CTFlows.Trajectories.VectorFieldTrajectory, C} <: Function

Callable struct returning the (1-D = scalar coerced) state of a CTFlows.Trajectories.StateFlowTrajectory. The coercion (only/identity) is precomputed and stored, so no length is tested at run time.

_NEGLIGIBLE_CURVATURE [Constant] ​

CTFlows.Trajectories._NEGLIGIBLE_CURVATURE Constant

Curvature below which the scaled curves are considered straight. The curves are scaled to a unit range over a unit time, where a significant bend has a curvature of order one; the finite-difference rounding noise on a straight segment, amplified by the square roots of the density, would otherwise drive the whole grid.

_aug_split_solution [Function] ​

CTFlows.Trajectories._aug_split_solution Function
julia
_aug_split_solution(u, x0, pv0) -> Tuple{Any, Any, Any}

Split an augmented final state u into state x, costate p, and variable costate pv components.

For Hamiltonian systems, n_p = n_x always, so the augmented state is [x; p; pv] where n_pv = length(u) - 2 * n_x.

Arguments

  • u: Augmented final state [x; p; pv] from integration.

  • n::Int: The state dimension n_x = n_p.

Returns

  • Tuple{AbstractVector, AbstractVector, AbstractVector}: Tuple (x, p, pv).

Notes

  • Internal helper used by build_trajectory for AugmentedHamiltonianEndPointConfig.

  • Assumes n_p = n_x invariant for Hamiltonian systems.

_build_control_proj [Function] ​

CTFlows.Trajectories._build_control_proj Function
julia
_build_control_proj(_::Nothing, traj, variable, coerce)

No control projection when there is no control law (a basic control-free Flow(ocp)).

julia
_build_control_proj(law, traj, variable, coerce)

Build the (precomputed) CTFlows.Trajectories.ControlProjection from the law and the inner trajectory.

_cdf_table [Function] ​

CTFlows.Trajectories._cdf_table Function
julia
_cdf_table(
    _::CTFlows.Configs.UniformGrid,
    curve,
    steps,
    a,
    b
) -> NamedTuple{(:F, :T, :mass), <:Tuple{Vector{Float64}, Any, Any}}

Uniform cumulative distribution on the phase [a, b]; its mass is the duration.

julia
_cdf_table(
    spec::CTFlows.Configs.AdaptiveGrid,
    curve,
    steps,
    a,
    b
) -> NamedTuple{(:F, :T, :mass), <:Tuple{Any, Any, Any}}

Cumulative distribution on the phase [a, b] of the curvature density ρ ∝ ‖ỹ''‖^{1/2} of the scaled plotted curves, mixed with the uniform density, tabulated on the solver steps subdivided in 8. Components with a negligible range are ignored, and so are negligible curvatures (_NEGLIGIBLE_CURVATURE); with no curvature at all the distribution is uniform.

_check_switch_index [Function] ​

CTFlows.Trajectories._check_switch_index Function
julia
_check_switch_index(sol, i::Integer, context::String)

Check that i is the index of a switching time of sol.

Throws

_controlled_u [Function] ​

CTFlows.Trajectories._controlled_u Function
julia
_controlled_u(
    law::CTBase.Data.ControlLaw{<:Function, CTBase.Traits.OpenLoopFeedback},
    t,
    x,
    v
) -> Any

Reconstruct the control from an OpenLoop law: u(t, v) (the state is ignored).

julia
_controlled_u(
    law::CTBase.Data.ControlLaw{<:Function, CTBase.Traits.ClosedLoopFeedback},
    t,
    x,
    v
) -> Any

Reconstruct the control from a ClosedLoop law: u(t, x, v).

julia
_controlled_u(
    pl::CTFlows.MultiPhase._PiecewiseControlLaw,
    t,
    x,
    v
) -> Any

State (controlled) uniform call: delegate to the phase law active at time t, dispatched by CTFlows.Trajectories on that law's feedback trait (OpenLoop/ClosedLoop).

Arguments

  • pl::_PiecewiseControlLaw: The piecewise control law.

  • t: Time.

  • x: State.

  • v: Variable (or Core.NotProvided).

Returns

  • The control of the phase active at t, reconstructed by the feedback-dispatched call.

_cp_variable [Function] ​

CTFlows.Trajectories._cp_variable Function
julia
_cp_variable(v) -> Any

Unwrap the variable passed to the flow call: return nothing when it was not provided (Core.NotProvided), otherwise return it as-is.

_curve_in_phase [Function] ​

CTFlows.Trajectories._curve_in_phase Function
julia
_curve_in_phase(curve, t, a, b) -> Any

Evaluate the plotted curve inside the phase [a, b]: at the phase start, slightly inside, so that the right limit is read after a jump (the trajectory is left-continuous).

_effective_bounds [Function] ​

CTFlows.Trajectories._effective_bounds Function
julia
_effective_bounds(
    bounds::AbstractVector,
    steps::AbstractVector
) -> Any

Clamp bounds to the span actually covered by the solver steps, on both sides.

An early termination (a terminate! callback, a blow-up with unsafe=true) stops the integration before bounds[end] (issue #524): the stop time closes the list. A trajectory integrated backward and stopped early, then read in increasing time (issue #547), starts after bounds[1]: the first step opens the list. The bounds strictly inside the covered span are kept, which preserves the switching times of a multi-phase integration. When the steps cover [bounds[1], bounds[end]], the same vector bounds is returned.

The direction is read from bounds (increasing if bounds[end] ≥ bounds[1]); steps are in the same direction.

Arguments

  • bounds::AbstractVector: the requested times [t0, …, tf], one interval per phase.

  • steps::AbstractVector: the distinct primal times of the solver, in the direction of bounds (at least two).

Returns

  • AbstractVector: bounds itself, or the bounds clamped to the covered span.

See also: CTFlows.Trajectories.apply_generated_grid

_flat [Function] ​

CTFlows.Trajectories._flat Function
julia
_flat(v::Real) -> Vector

Flatten a plotted value (number or array) into a vector of floats; a complex value gives its real parts followed by its imaginary parts. A device array (e.g. CuArray) is first copied to the host: the plotted curve is host data and must not scalar-index the device. The primal value is taken (dual numbers of an automatic-differentiation pass only shape the grid through their value, see CTSolvers.Integrators.deepvalue).

_flat_part [Function] ​

CTFlows.Trajectories._flat_part Function
julia
_flat_part(part, v) -> Any

Primal values of the part (real or imag) of the entries of the complex array v, as a vector of floats.

_ham_split_solution [Function] ​

CTFlows.Trajectories._ham_split_solution Function
julia
_ham_split_solution(u::AbstractVector, x0::Number) = (_safe_only(u[1:1]), _safe_only(u[2:2]))
_ham_split_solution(u::AbstractVector, x0::AbstractVector) = (u[1:n], u[n+1:2n])
_ham_split_solution(u::AbstractMatrix, x0::AbstractMatrix) = (u[1:n, :], u[n+1:2n, :])

Split a combined state vector into state and costate components, preserving the shape of x0.

For scalar x0, extracts single elements and coerces them back to scalars (via the GPU-safe CTFlows.Systems._safe_only, consistent with every other 1-D=scalar split path). For vector/matrix x0, extracts views of the appropriate size.

julia
_ham_split_solution(
    u::AbstractVector,
    x0::AbstractVector
) -> Tuple{Any, Any}

Split a combined state–costate vector into two sub-vectors, using length(x0) as the state dimension n.

Returns

  • (u[1:n], u[(n+1):2n]): state and costate sub-vectors.
julia
_ham_split_solution(
    u::AbstractMatrix,
    x0::AbstractMatrix
) -> Tuple{Any, Any}

Split a combined state–costate matrix into two sub-matrices (column-wise), using size(x0, 1) as the state dimension n.

Returns

  • (u[1:n, :], u[(n+1):2n, :]): state and costate sub-matrices.

_invert_cdf [Function] ​

CTFlows.Trajectories._invert_cdf Function
julia
_invert_cdf(
    F::AbstractVector,
    T::AbstractVector,
    n::Int64
) -> Vector{Float64}

Invert the tabulated cumulative distribution F (non-decreasing, from 0 to 1) over the times T at n equally spaced levels; the bounds are exact.

_is_backward [Function] ​

CTFlows.Trajectories._is_backward Function
julia
_is_backward(
    result::CTSolvers.Integrators.AbstractIntegrationResult
) -> Any

Whether the time grid of an integration result decreases: the result of a backward integration, still in integration order.

_kept_labels [Function] ​

CTFlows.Trajectories._kept_labels Function
julia
_kept_labels(
    sol,
    labels::AbstractVector{<:AbstractString}
) -> Vector{String}

Return the labels of sol to keep: none when every label is empty, all of them otherwise.

Throws

_phase_sequence [Function] ​

CTFlows.Trajectories._phase_sequence Function
julia
_phase_sequence(
    labels::AbstractVector{<:AbstractString}
) -> String

Return the sequence of phase labels as written by the displays, e.g. "bang → · → singular": the labels joined by arrows, a phase with no label written · so that every phase keeps its place between the switching times.

See also: CTFlows.Trajectories.phase_labels.

_plotted_curve [Function] ​

CTFlows.Trajectories._plotted_curve Function
julia
_plotted_curve(
    fs...
) -> CTFlows.Trajectories.var"#_plotted_curve##0#_plotted_curve##1"{<:Tuple}

Plotted curve t -> [x(t); p(t); u(t)] from callables (nothing entries are skipped).

_pre_grid [Function] ​

CTFlows.Trajectories._pre_grid Function
julia
_pre_grid(steps, a, b, k::Int64) -> Any

Pre-grid of the phase [a, b]: the solver steps inside it, each interval subdivided in k, in integration order.

_right_controlled_u [Function] ​

CTFlows.Trajectories._right_controlled_u Function
julia
_right_controlled_u(law, _::Integer, t, x, v) -> Any

Control just after the i-th switching time t, from the state x after the jump: the law of the next phase. A single law has no phase, so it is the law itself; CTFlows.MultiPhase adds the method of the piecewise law of a multi-phase flow.

julia
_right_controlled_u(
    pl::CTFlows.MultiPhase._PiecewiseControlLaw,
    i::Integer,
    t,
    x,
    v
) -> Any

State (controlled) control just after the i-th switching time t, from the state x after the jump: the law of the next phase. Used by CTFlows.Trajectories.right_limit.

_scale_rows [Function] ​

CTFlows.Trajectories._scale_rows Function
julia
_scale_rows(Y::AbstractMatrix) -> Any

Scale every row (component) by its range; a component whose range is negligible with respect to its size is constant and gets a zero row (otherwise its rounding noise would dominate the density).

_sft_control [Function] ​

CTFlows.Trajectories._sft_control Function
julia
_sft_control(
    cp::CTFlows.Trajectories.ControlProjection
) -> CTFlows.Trajectories.ControlProjection

Return the stored CTFlows.Trajectories.ControlProjection as-is, or throw a CTBase.Exceptions.PreconditionError when the trajectory has no control projection (cp === nothing, a basic control-free Flow(ocp)). Dispatch helper for CTFlows.Trajectories.control.

julia
_sft_control(_::Nothing)

Throw a PreconditionError because the StateFlowTrajectory has no control projection (cp === nothing, a basic control-free Flow(ocp)).

This happens when the flow was built without a control law (e.g. for direct shooting), so there is no control to reconstruct.

_share_intervals [Function] ​

CTFlows.Trajectories._share_intervals Function
julia
_share_intervals(
    masses::AbstractVector,
    total::Int64
) -> Any

Share total intervals between phases in proportion to masses (largest remainder), at least one per phase.

_show_variable [Function] ​

CTFlows.Trajectories._show_variable Function
julia
_show_variable(v) -> Bool

Return true when the trajectory variable v is worth displaying, i.e. it is neither the Core.NotProvided sentinel nor nothing (the value Fixed flows thread through).

_switching_fields [Function] ​

CTFlows.Trajectories._switching_fields Function
julia
_switching_fields(sol, fmt) -> Vector{Any}

Return the display fields of the switching structure of a trajectory: the switching times when there are any, the sequence of phase labels when at least one phase is labelled (nothing is shown for an unlabelled trajectory).

See also: CTFlows.Trajectories._phase_sequence.

_switching_parts [Function] ​

CTFlows.Trajectories._switching_parts Function
julia
_switching_parts(sol) -> Vector{String}

Return the compact display parts of the switching structure of a trajectory (see CTFlows.Trajectories._switching_fields).

_throw_component [Function] ​

CTFlows.Trajectories._throw_component Function
julia
_throw_component(sol, component::Symbol, expected::String)

Throw the error of a component a trajectory does not have.

Throws

apply_generated_grid [Function] ​

CTFlows.Trajectories.apply_generated_grid Function
julia
apply_generated_grid(
    traj,
    _::Union{Nothing, AbstractVector},
    curve,
    bounds
) -> Any

Apply the output grid of a call to a trajectory (or integration result): unchanged without a generated grid; otherwise generate it from curve over bounds and regrid, with the solver times of traj as pre-grid (their primal values: under automatic differentiation the stop time of a callback depends on the differentiated parameters).

When the solver stops before bounds[end] (a terminate! callback), the grid ends at the stop time, not at bounds[end] (CTFlows.Trajectories._effective_bounds); a trajectory with a single time is returned unchanged.

julia
apply_generated_grid(
    traj,
    spec::CTFlows.Configs.AutomaticGrid,
    curve,
    bounds
) -> Any

Apply the default output grid of a call (issue #446): the adaptive grid is generated only when the trajectory is dense (the curvature of a linear interpolant is meaningless) and has fewer than spec.grid.n distinct times; otherwise traj is returned unchanged.

See also: CTFlows.Configs.AutomaticGrid.

generate_grid [Function] ​

CTFlows.Trajectories.generate_grid Function
julia
generate_grid(
    spec::CTFlows.Configs.AbstractGrid,
    curve,
    steps,
    bounds::AbstractVector
) -> Vector{Float64}

Generate the output grid spec on the phases delimited by bounds ([t0, t₁, …, tf], in integration order): exactly spec.n distinct times, every bound included once.

curve(t) returns the plotted values at t as a vector (state, costate, control); steps are the solver times, used as the pre-grid of an CTFlows.Configs.AdaptiveGrid. The n - 1 intervals are shared between the phases in proportion to their mass (duration for a uniform grid), at least one per phase.

Throws

  • CTBase.Exceptions.IncorrectArgument: If spec.n is smaller than the number of bounds.