Skip to content

Private API

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


From CTFlowsSciMLFlows

IPSciMLIpRHS [Struct]

CTFlowsSciMLFlows.IPSciMLIpRHS Type
julia
struct IPSciMLIpRHS{F<:SciMLBase.AbstractODEFunction{true}} <: 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

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}} <: 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

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}} <: 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

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}} <: 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

Call signature

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

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

OoPSciMLOoPRHS [Struct]

CTFlowsSciMLFlows.OoPSciMLOoPRHS Type
julia
struct OoPSciMLOoPRHS{F<:SciMLBase.AbstractODEFunction{false}} <: 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

Call signature

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

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

SciMLFunctionSystem [Struct]

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

Concrete AbstractStateSystem wrapping a SciMLBase.AbstractODEFunction.

Unlike CTFlows-native systems (VectorFieldSystem), 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

The system pre-computes cross-adapters for both in-place and out-of-place call modes, similar to VectorFieldSystem, ensuring compatibility with the generic build_problem which dispatches based on u0 mutability.

Type Parameters

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

  • RHS<:Systems.AbstractIPRHS: Pre-computed in-place RHS functor.

  • OOPROHS<:Systems.AbstractOoPRHS: Pre-computed out-of-place RHS functor.

  • FINRHS: Finalize functor for in-place functions with immutable u0, or Nothing.

Fields

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

  • rhs_fn::RHS: In-place RHS with signature (du, u, λ, t).

  • rhs_oop_fn::OOPROHS: Out-of-place RHS with signature (u, λ, t).

  • rhs_oop_finalize_fn::FINRHS: Out-of-place RHS for immutable u0 (iip only), or Nothing.

Example

julia
using SciMLBase, CTFlows

f = ODEFunction((du, u, p, t) -> du .= -p .* u)
sys = SciMLFunctionSystem(f)
# sys.rhs_fn is pre-computed in-place closure
# sys.rhs_oop_fn is pre-computed out-of-place closure (allocates buffer)

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).

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: _rhs_sciml_label, IPSciMLIpRHS, OoPSciMLIpRHS, OoPSciMLIpFinalizeRHS, IPSciMLOoPRHS, OoPSciMLOoPRHS.

_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: _AnySciMLRHS.


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 searchsortedlast 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 the next phase is selected — a measure-zero choice, irrelevant to plotting and to objective integration.

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.

_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_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.get_jump.

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_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.

_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.

Iterates through all phases sequentially, applying jumps at switching times.

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

  • Final state after all phases.

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.

Iterates through all phases sequentially, collecting segment results and applying jumps at switching times.

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

  • Merged trajectory solution after all phases.

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

_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,
    ::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,
    ::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.

_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.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.

_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 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

  • Concatenated vector [state; costate].

Notes

This is an internal dispatch method for the _format_final_output function.

_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.

_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 searchsortedlast over the switching times, clamped to the valid phase range.

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.

_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.

_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}, 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, _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}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, _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, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} 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{TS} where TS<:(CTModels.Components.CoercedTrajectory{F, typeof(identity)} where F<:(CTFlows.Flows.var"#_control_of##4#_control_of##5"{CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}} where {_A, S<:(Vector{<:Real})})), CTModels.Components.ControlModelSolution{TS} where TS<:(CTModels.Components.CoercedTrajectory{F, typeof(only)} where F<:(CTFlows.Flows.var"#_control_of##4#_control_of##5"{CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}} where {_A, S<:(Vector{<:Real})}))}, 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}

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.

_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


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

IPVFIpRHS [Struct]

CTFlows.Systems.IPVFIpRHS Type
julia
IPVFIpRHS{F,TD,VD} <: 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

Call signature

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

IPVFOoPRHS [Struct]

CTFlows.Systems.IPVFOoPRHS Type
julia
IPVFOoPRHS{VF<:Data.AbstractVectorField} <: 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).

Call signature

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

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

OoPVFIpFinalizeRHS [Struct]

CTFlows.Systems.OoPVFIpFinalizeRHS Type
julia
OoPVFIpFinalizeRHS{F,TD,VD} <: 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

Call signature

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

OoPVFIpRHS [Struct]

CTFlows.Systems.OoPVFIpRHS Type
julia
OoPVFIpRHS{F,TD,VD} <: 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

Call signature

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

OoPVFOoPRHS [Struct]

CTFlows.Systems.OoPVFOoPRHS Type
julia
OoPVFOoPRHS{VF<:Data.AbstractVectorField} <: 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).

Call signature

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

_aug_assign! [Function]

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

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.

_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.

_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

_check_vf_scalar_inplace [Function]

CTFlows.Systems._check_vf_scalar_inplace Function
julia
_check_vf_scalar_inplace(sys::VectorFieldSystem{F, TD, VD, Traits.InPlace}, u0::Number)

Raise an error if an in-place vector field is used with a scalar initial condition. This combination is unsupported because in-place functions require mutable arrays.

Arguments

  • sys::VectorFieldSystem: The vector field system.

  • u0: The initial condition.

Throws

  • ArgumentError if sys is in-place and u0 is a scalar.

_coerce_state [Function]

CTFlows.Systems._coerce_state Function
julia
_coerce_state(::Number) = only
_coerce_state(::AbstractMatrix) = identity
_coerce_state(x::AbstractVector) = length(x) == 1 ? only : identity

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

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

Scope: applied only on Hamiltonian paths (HamiltonianSystem, HamiltonianVectorFieldSystem, augmented variable-costate, and the HamiltonianDynamics trajectory builders). State-only flows (bare VectorField, SciMLBase ODE adapters) stay shape-preserving via CTBase.Core.make_coerce, because a raw ODE state carries no 1-D control convention — the user's array is the contract there.

Differs from CTBase.Core.make_coerce only in that a length-1 vector collapses to a scalar (_safe_only, the GPU-safe only) instead of being kept as a 1-vector (identity).

_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.

_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.

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
) -> Union{CTBase.Data.HamiltonianVectorField{CTFlows.Systems.HVFIpFunctor{H, B}} where {H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}, CTBase.Data.HamiltonianVectorField{CTFlows.Systems.HVFOoPFunctor{H, B}} where {H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}}

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.

_rhs_conversion_label [Function]

CTFlows.Systems._rhs_conversion_label Function

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

Arguments

  • f::AbstractHamRHS: The Hamiltonian RHS functor.

Returns

  • String: Description of the conversion (e.g., "Hamiltonian AD → in-place interface").

Notes

  • Used internally by Base.show for display.

  • Different functors have different conversion labels.

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

_state_dim [Function]

CTFlows.Systems._state_dim Function
julia
_state_dim(x0::Number) = 1
_state_dim(x0::AbstractVector) = length(x0)
_state_dim(x0::AbstractMatrix) = size(x0, 1)

Infer the state dimension from the initial condition shape.

constraint [Function]

CTFlows.Systems.constraint Function
julia
constraint(
    sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> Any

Return the path constraint g(t,x,u,v) of a ConstrainedPseudoHamiltonianSystem.

See also: CTFlows.Systems.multiplier, CTFlows.Systems.ConstrainedPseudoHamiltonianSystem.

multiplier [Function]

CTFlows.Systems.multiplier Function
julia
multiplier(
    sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> Any

Return the multiplier μ(t,x,p,v) of a ConstrainedPseudoHamiltonianSystem.

See also: CTFlows.Systems.constraint, CTFlows.Systems.ConstrainedPseudoHamiltonianSystem.


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:

  • StateDynamicsAbstractConfig

  • HamiltonianDynamicsAbstractHamiltonianConfig or AbstractAugmentedHamiltonianConfig

Throws PreconditionError if the pair is incompatible.

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


From CTFlows.Flows

ConstrainedPseudoHamiltonianFunction [Struct]

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

Internal callable representing the constrained pseudo-Hamiltonian of an OCP: H(t,x,p,u,v) = H̃(t,x,p,u,v) + μ(t,x,p,v)·g(t,x,u,v), where is an OCPPseudoHamiltonianFunction, g a CTBase.Data.PathConstraint (uniform call g(t,x,u,v)) and μ a CTBase.Data.Multiplier (uniform call μ(t,x,p,v)).

Used for the :total differentiation mode only: the whole functor is composed with the control law via CTBase.Data.ComposedHamiltonian, so AD differentiates through , μ, g and the law (total derivative). The (TD, VD) traits drive natural-arity dispatch exactly as for OCPPseudoHamiltonianFunction.

Type Parameters

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

  • H: type of the base pseudo-Hamiltonian functor.

  • G: type of the path-constraint carrier.

  • M: type of the multiplier carrier.

Fields

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

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

  • μ::M: multiplier μ(t,x,p,v).

See also: OCPPseudoHamiltonianFunction, CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.

OCPControlledVectorFieldFunction [Struct]

CTFlows.Flows.OCPControlledVectorFieldFunction Type
julia
struct OCPControlledVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(only)}, CU<:Union{typeof(identity), typeof(only)}, CV<:Union{typeof(identity), typeof(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.

OCPHamiltonianFunction [Struct]

CTFlows.Flows.OCPHamiltonianFunction Type
julia
struct OCPHamiltonianFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, LF<:Union{Nothing, Function}} <: Function

Internal callable representing the Hamiltonian of a control-free optimal control problem.

Computes H(t,x,p,v) = p·f(t,x,∅,v) + sp0·ℓ(t,x,∅,v) where sp0 = s·p⁰ with p⁰=-1 (sp0=-1 for :min, sp0=+1 for :max). The time-dependence (TD) and variable-dependence (VD) traits are compile-time parameters so that dispatch selects the correct natural-arity call signature without runtime branches.

Type Parameters

  • TD: time-dependence trait (Autonomous or NonAutonomous).

  • VD: variable-dependence trait (Fixed or NonFixed).

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

  • LF: type of the Lagrange cost function (or Nothing).

Fields

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

  • lagrange::LF: Lagrange cost ℓ(t, x, u, v) or nothing if absent.

  • sp0::Float64: sign-weighted multiplier s·p⁰.

  • n::Int: state dimension.

See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows._ocp_H, CTFlows.Flows._ocp_hamiltonian.

OCPPseudoHamiltonianFunction [Struct]

CTFlows.Flows.OCPPseudoHamiltonianFunction Type
julia
struct OCPPseudoHamiltonianFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, LF<:Union{Nothing, Function}} <: Function

Internal callable representing the pseudo-Hamiltonian of an optimal control problem: H̃(t,x,p,u,v) = p·f(t,x,u,v) + sp0·ℓ(t,x,u,v) with sp0 = s·p⁰ (p⁰=-1). Unlike OCPHamiltonianFunction, the control u is an explicit argument.

Type Parameters

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

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

  • LF: type of the Lagrange cost function (or Nothing).

Fields

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

  • lagrange::LF: Lagrange cost ℓ(t, x, u, v) or nothing.

  • sp0::Float64: sign-weighted multiplier s·p⁰.

  • n::Int: state dimension.

See also: CTFlows.Flows.OCPHamiltonianFunction, CTFlows.Flows._ocp_pseudo_hamiltonian, CTBase.Data.PseudoHamiltonian.

OCPStateVectorFieldFunction [Struct]

CTFlows.Flows.OCPStateVectorFieldFunction Type
julia
struct OCPStateVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(only)}, CV<:Union{typeof(identity), typeof(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.

_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{M<:Tuple}

Carrier for a tuple of multipliers, paired element-wise with a CTFlows.Flows._CombinedConstraint. Its uniform call concatenates the per-multiplier values μᵢ(t,x,p,v) in the same order, so sum(μ .* g) = Σᵢ μᵢ·gᵢ.

Type Parameters

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

Fields

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.AbstractADBackendDifferentiation.DifferentiationInterface

  • Integrators.AbstractIntegratorIntegrators.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.

_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.

_build_flow_components [Function]

CTFlows.Flows._build_flow_components Function
julia
_build_flow_components(
    routed
) -> NamedTuple{(:backend, :integrator), <:Tuple{Any, Any}}

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

Returns

  • NamedTuple{(:backend, :integrator)}: Concrete strategy instances.

Example

julia
# Build concrete strategies from routed options
routed = Flows._route_flow_options((; reltol=1e-8))
components = Flows._build_flow_components(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

_build_ocp_pseudo_flow [Function]

CTFlows.Flows._build_ocp_pseudo_flow Function
julia
_build_ocp_pseudo_flow(
    _::Val{:total},
    ocp,
    law,
    components,
    cspec,
    mspec
) -> 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 of an OCP + control-law flow, dispatching on the hamiltonian_type and on the presence of a constraint/multiplier pair (already validated by CTFlows.Flows._validate_constraint_pair).

See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier, 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, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} 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}
_build_ocp_solution(
    ocp,
    sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
    variable,
    integ,
    law
) -> Union{CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} 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}, CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} 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{TS} where TS<:(CTModels.Components.CoercedTrajectory{F, typeof(identity)} where F<:CTFlows.Flows.var"#_control_of##4#_control_of##5"), CTModels.Components.ControlModelSolution{TS} where TS<:(CTModels.Components.CoercedTrajectory{F, typeof(only)} where F<:CTFlows.Flows.var"#_control_of##4#_control_of##5")}, 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}}

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 with the control law into a CTBase.Data.ComposedHamiltonian and wrap it in a CTFlows.Systems.HamiltonianSystem (AD through the law).

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).

_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 constraint/multiplier specs — 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); Tuple constraint/multiplier specs 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 constraint spec (nothing, Symbol, Function, Tuple, or CTBase.Data.PathConstraint).

  • mspec: the multiplier spec (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!.

_constrained_pseudo_H [Function]

CTFlows.Flows._constrained_pseudo_H Function
julia
_constrained_pseudo_H(
    h::CTFlows.Flows.ConstrainedPseudoHamiltonianFunction,
    t,
    x,
    p,
    u,
    v
) -> Any

Core computation of the constrained pseudo-Hamiltonian value H̃(t,x,p,u,v) + μ(t,x,p,v)·g(t,x,u,v). The pairing μ·g uses sum(μ .* g) so it handles both scalar (1-D) and vector constraints (matching the p·f idiom in CTFlows.Flows._ocp_pseudo_H). When v === nothing (Fixed problems) an empty variable vector is forwarded to μ/g; their Fixed-trait uniform calls ignore it.

See also: CTFlows.Flows.ConstrainedPseudoHamiltonianFunction.

_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:

  • nothingt -> 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.

_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: _invoke_flow, CTFlows.Integrators.build_problem, CommonSolve.solve, CTFlows.Trajectories.build_trajectory.

_dim_coerce [Function]

CTFlows.Flows._dim_coerce Function
julia
_dim_coerce(
    dim::Int64
) -> Union{typeof(identity), typeof(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.

_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, _::AbstractVector) -> Any

Return the result buffer as-is for an n-D (vector) state.

_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 the paired constraint / multiplier options that turn the flow into a constrained pseudo-Hamiltonian flow. All three 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_families [Function]

CTFlows.Flows._flow_families Function
julia
_flow_families(

) -> @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

_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}} 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, CTBase.Data.VectorField{F, TD3, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace}, CTFlows.Systems.IPVFOoPRHS{VF}, CTFlows.Systems.OoPVFOoPRHS{VF1}, Nothing} where {F<:Function, VF<:(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(only)}, CV<:Union{typeof(identity), typeof(only)}, TD1<:CTBase.Traits.TimeDependence}), VF1<:(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(only)}, CV<:Union{typeof(identity), typeof(only)}, TD1<:CTBase.Traits.TimeDependence})}), 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}} 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, CTBase.Data.VectorField{F, TD3, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace}, CTFlows.Systems.IPVFOoPRHS{VF}, CTFlows.Systems.OoPVFOoPRHS{VF1}, Nothing} where {F<:Function, VF<:(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(only)}, CV<:Union{typeof(identity), typeof(only)}, TD1<:CTBase.Traits.TimeDependence}), VF1<:(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(only)}, CV<:Union{typeof(identity), typeof(only)}, TD1<:CTBase.Traits.TimeDependence})}), 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...
) -> 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} 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 an CTFlows.Flows.OptimalControlFlow from the OCP pseudo-Hamiltonian and a DynClosedLoop law, dispatching on the hamiltonian_type action option.

If constraint/multiplier are given as 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},
::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_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 (a 1-element vector gives SciML a 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,
    x0
) -> Union{typeof(identity), typeof(only)}

Precomputed state coercion (only for a 1-D state, identity otherwise) from the OCP's declared state dimension.

julia
_flow_state_coerce(
    _::Nothing,
    x0
) -> Union{typeof(identity), typeof(only)}

Precomputed state coercion (only for a 1-D state, identity otherwise) inferred from x0 when there is no OCP (Flow(fc, law)).

_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: 2. The flow's VariableDependence trait (Fixed or NonFixed)

  1. 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; if false, throw SolverFailure on integration failure.

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, _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, _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.SupportsVariableCostate},
    ::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.

Throws

  • CTBase.Exceptions.PreconditionError: Always, with a descriptive message indicating that variable_costate is only supported for point configurations.

See also: CTBase.Traits.SupportsVariableCostate, 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

_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.

_ocp_H [Function]

CTFlows.Flows._ocp_H Function
julia
_ocp_H(
    h::CTFlows.Flows.OCPHamiltonianFunction,
    t,
    x,
    p,
    v
) -> Any

Core computation of the OCP Hamiltonian value H(t,x,p,v).

Passes x (and the variable v) to the in-place dynamics as received — a scalar for a 1-dimensional quantity, a vector otherwise (the ecosystem "1-D = scalar" convention) — and accumulates p·f + sp0·ℓ. The derivative buffer r is always a length-n_x vector. When v === nothing the variable is an empty vector (used by Fixed-trait call paths).

See also: CTFlows.Flows.OCPHamiltonianFunction.

_ocp_constrained_pseudo_hamiltonian [Function]

CTFlows.Flows._ocp_constrained_pseudo_hamiltonian Function
julia
_ocp_constrained_pseudo_hamiltonian(
    ocp,
    g,
    μ
) -> Union{CTBase.Data.PseudoHamiltonian{CTFlows.Flows.ConstrainedPseudoHamiltonianFunction{TD, VD, H, G, M}, TD1, CTBase.Traits.Fixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H<:CTFlows.Flows.OCPPseudoHamiltonianFunction, G, M, TD1<:CTBase.Traits.TimeDependence}, CTBase.Data.PseudoHamiltonian{CTFlows.Flows.ConstrainedPseudoHamiltonianFunction{TD, VD, H, G, M}, TD1, CTBase.Traits.NonFixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H<:CTFlows.Flows.OCPPseudoHamiltonianFunction, G, M, TD1<:CTBase.Traits.TimeDependence}}

Build a CTFlows.Flows.ConstrainedPseudoHamiltonianFunction from an OCP, a resolved path constraint g and a resolved multiplier μ, wrapped in a CTBase.Data.PseudoHamiltonian so it flows into the :total pipeline exactly like the unconstrained CTFlows.Flows._ocp_pseudo_hamiltonian.

See also: CTFlows.Flows.ConstrainedPseudoHamiltonianFunction, CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier.

_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(only)}, CU<:Union{typeof(identity), typeof(only)}, CV<:Union{typeof(identity), typeof(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(only)}, CU<:Union{typeof(identity), typeof(only)}, CV<:Union{typeof(identity), typeof(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), fill a length-n_x buffer with the in-place dynamics, 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) -> CTBase.Data.Hamiltonian

Build an OCPHamiltonianFunction from a control-free OCP and wrap it in a Data.Hamiltonian.

Extracts the state dimension, dynamics, criterion sign, Lagrange cost, and time/variable-dependence traits from the OCP, then constructs a typed OCPHamiltonianFunction and wraps it so the downstream AD pipeline receives a uniform (t, x, p, v) interface.

See also: CTFlows.Flows.OCPHamiltonianFunction, CTFlows.Flows.OptimalControlFlow, CTFlows.Flows.Flow.

_ocp_pseudo_H [Function]

CTFlows.Flows._ocp_pseudo_H Function
julia
_ocp_pseudo_H(
    h::CTFlows.Flows.OCPPseudoHamiltonianFunction,
    t,
    x,
    p,
    u,
    v
) -> Any

Core computation of the OCP pseudo-Hamiltonian value H̃(t,x,p,u,v). Passes x, u (and the variable v) to the in-place dynamics as received — scalar for a 1-dimensional quantity, vector otherwise ("1-D = scalar" convention) — and accumulates p·f + sp0·ℓ. The derivative buffer r is always a length-n_x vector.

See also: CTFlows.Flows.OCPPseudoHamiltonianFunction.

_ocp_pseudo_hamiltonian [Function]

CTFlows.Flows._ocp_pseudo_hamiltonian Function
julia
_ocp_pseudo_hamiltonian(
    ocp
) -> CTBase.Data.PseudoHamiltonian

Build an CTFlows.Flows.OCPPseudoHamiltonianFunction from an OCP and wrap it in a CTBase.Data.PseudoHamiltonian, giving the uniform (t,x,p,u,v) interface used by the pseudo-Hamiltonian AD pipeline.

See also: CTFlows.Flows.OCPPseudoHamiltonianFunction, 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(only)}, CV<:Union{typeof(identity), typeof(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(only)}, CV<:Union{typeof(identity), typeof(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), fill a length-n_x buffer with the in-place dynamics called with an empty control, and return it (scalar for a 1-D state).

See also: CTFlows.Flows.OCPStateVectorFieldFunction.

_print_user_options [Function]

CTFlows.Flows._print_user_options Function
julia
_print_user_options(io::IO, integ::Integrators.AbstractIntegrator)

Print user-supplied integrator options inline: (key = val, …). Silently does nothing when no user options are set.

Arguments

  • io::IO: The IO stream to write to.

  • integ::Integrators.AbstractIntegrator: The integrator to inspect for user options.

Example

julia
# If user options are set: prints " (abstol = 1e-8, reltol = 1e-6)"
# If no user options: prints nothing

_reject_control_free_constraint [Function]

CTFlows.Flows._reject_control_free_constraint Function
julia
_reject_control_free_constraint(kwargs)

Reject a constraint / multiplier 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.

_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(
    ocp,
    spec::Symbol
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:Function

Resolve a constraint specification into a CTBase.Data.PathConstraint.

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

_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.

_route_flow_options [Function]

CTFlows.Flows._route_flow_options Function
julia
_route_flow_options(
    kwargs;
    action_defs
) -> NamedTuple{(:action, :strategies), <:Tuple{NamedTuple, 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 (strategy options only, no action-level options).

Returns

  • NamedTuple with fields:
    • action: action-level options (always empty for flows)

    • 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.

  • No action-level options are defined for flows (empty OptionDefinition array).

See also: CTFlows.Flows._flow_families, CTFlows.Flows._build_flow_components, CTBase.Orchestration.route_all_options

_spec_arity_issues! [Function]

CTFlows.Flows._spec_arity_issues! Function
julia
_spec_arity_issues!(
    issues,
    ocp,
    _::Nothing,
    label,
    second,
    kind
)

Collect arity issues from a convenience spec into issues, dispatching on the spec's shape: skip nothing; check a raw Function directly; check each Function element of a Tuple (multi-constraint/multiplier case, labelled label1, label2, …); skip anything else (Symbol, CTBase.Data.PathConstraint, CTBase.Data.Multiplier — not raw functions).

Arguments

  • issues::Vector{String}: accumulator, mutated in place.

  • ocp::CTModels.Models.Model: the OCP, used to infer the expected arity.

  • spec: the convenience spec (nothing, Function, Tuple, or an already-resolved carrier).

  • label::AbstractString, second::AbstractString, kind::AbstractString: forwarded to CTFlows.Flows._arity_issue.

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.

_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.

_validate_constraint_pair [Function]

CTFlows.Flows._validate_constraint_pair Function
julia
_validate_constraint_pair(cspec, mspec)

Validate the constraint/multiplier pairing: they must be given together (both or neither), and for multiple constraints both must be tuples of equal length (element i of constraint pairs with element i of multiplier).

Throws

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

_variable_vector [Function]

CTFlows.Flows._variable_vector Function

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.


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 aligned under the value column and prefixed with a pipe (blanks when last), mirroring the multi-line field convention used across the control-toolbox ecosystem. 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.

_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.

_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.

_ham_split_solution [Function]

CTFlows.Trajectories._ham_split_solution Function
julia
_ham_split_solution(u::AbstractVector, x0::Number) = (only(u[1:1]), 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. For vector/matrix x0, extracts views of the appropriate size.

_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.

_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).