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
struct IPSciMLIpRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPRHSIn-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 ODEFunctioncx::CX: coercion applied to the state before callingf(_safe_onlyfor a 1-D state,identityotherwise, per issue #357 —SciMLFunctionSystemsharesVectorFieldSystem'sSystems/Trajectoriesdispatch, so it gets the same 1-D = scalar coercion; seeCTFlows.Systems._coerce_state).
Call signature
(r::IPSciMLIpRHS)(du, u, λ, t) -> nothing
See also: CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.
IPSciMLOoPRHS [Struct]
CTFlowsSciMLFlows.IPSciMLOoPRHS Type
struct IPSciMLOoPRHS{F<:SciMLBase.AbstractODEFunction{false}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPRHSIn-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 ODEFunctioncx::CX: coercion applied to the state before callingf.
Call signature
(r::IPSciMLOoPRHS)(du, u, λ, t) -> nothing
See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.
OoPSciMLIpFinalizeRHS [Struct]
CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS Type
struct OoPSciMLIpFinalizeRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHSOut-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 ODEFunctioncx::CX: coercion applied to the state before callingf.
Call signature
(r::OoPSciMLIpFinalizeRHS)(u, λ, t) -> du
See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.
OoPSciMLIpRHS [Struct]
CTFlowsSciMLFlows.OoPSciMLIpRHS Type
struct OoPSciMLIpRHS{F<:SciMLBase.AbstractODEFunction{true}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHSOut-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 ODEFunctioncx::CX: coercion applied to the state before callingf.
Call signature
(r::OoPSciMLIpRHS)(u, λ, t) -> du
Notes
dx = similar(u)already matchesu's actual (uncoerced) shape, so no reshaping is needed even whencxcollapses the CALL argument to a scalar.
See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.
OoPSciMLOoPRHS [Struct]
CTFlowsSciMLFlows.OoPSciMLOoPRHS Type
struct OoPSciMLOoPRHS{F<:SciMLBase.AbstractODEFunction{false}, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPRHSOut-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 ODEFunctioncx::CX: coercion applied to the state before callingf.
Call signature
(r::OoPSciMLOoPRHS)(u, λ, t) -> du
Notes
- Unlike the Hamiltonian-family out-of-place functors, this functor has a single block and nothing to reassemble: when
cxcollapsesuto a scalar for the call,fmay return a bare scalar too, which does not matchu's own (uncoerced) container shape. That case is reshaped back explicitly, matchingCTFlows.Systems.OoPVFOoPRHS's identical handling.
See also: CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS.
SciMLFunctionSystem [Struct]
CTFlowsSciMLFlows.SciMLFunctionSystem Type
struct SciMLFunctionSystem{F<:SciMLBase.AbstractODEFunction} <: CTFlows.Systems.AbstractStateSystem{CTBase.Traits.NonAutonomous, CTBase.Traits.NonFixed}Concrete AbstractStateSystem wrapping a SciMLBase.AbstractODEFunction.
Unlike a genuine SciML bypass (SciMLProblemFlow, wrapping an AbstractODEProblem), this system implements Systems.AbstractSystem (get_ip_rhs/get_oop_rhs) and shares VectorFieldSystem's Systems/Trajectories dispatch, so per issue control-toolbox/CTFlows.jl#357 it also follows the "1-D = scalar" convention: RHS closures are built lazily by get_ip_rhs/get_oop_rhs based on the actual initial condition type, coercing a 1-D state to a scalar before calling the wrapped ODE function — mirroring CTFlows.Systems.VectorFieldSystem.
Unlike CTFlows-native systems, this system passes p = variable directly to the ODE — no ODEParameters wrapper — so users can pass arbitrary SciML parameter objects.
The mutability trait is encoded in the iip type parameter of the wrapped function:
AbstractODEFunction{true}→ in-placef!(du, u, p, t)AbstractODEFunction{false}→ out-of-placef(u, p, t) -> du
Type Parameters
F <: SciMLBase.AbstractODEFunction: The wrapped ODE function.
Fields
f::F: The wrapped SciML ODE function.
Example
using SciMLBase, CTFlows
f = ODEFunction((du, u, p, t) -> du .= -p .* u)
sys = SciMLFunctionSystem(f)SciMLProblemFlow [Struct]
CTFlowsSciMLFlows.SciMLProblemFlow Type
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)— callsSciMLBase.remakefirst with point options, returns final state only.Trajectory call
f(tspan, x0; variable, unsafe)— callsSciMLBase.remakefirst with trajectory options, returns complete solution.
Type Parameters
P <: SciMLBase.AbstractODEProblem: The wrapped ODE problem.I <: Integrators.AbstractIntegrator: The integrator strategy (typicallySciML).
Fields
prob::P: The wrapped ODE problem (contains u0, tspan, p).integrator::I: The integrator strategy (provides options viabuild_options).
Example
using SciMLBase, CTFlows
prob = ODEProblem((du, u, p, t) -> du .= -p .* u, [1.0], (0.0, 1.0), 2.0)
flow = SciMLProblemFlow(prob, Integrators.SciML())
# No-arg call: solve as-is
sol = flow(; unsafe=false)
# Point call: modify initial condition and time span, returns final state
xf = flow(0.5, [2.0], 2.0; variable=3.0, unsafe=false)
# Trajectory call: modify initial condition and time span, returns complete solution
sol = flow((0.5, 2.0), [2.0]; variable=3.0, unsafe=false)_AnySciMLRHS [Struct]
CTFlowsSciMLFlows._AnySciMLRHS Type
Union type of all SciML RHS functors.
Notes
Internal type alias used for method dispatch on display methods.
Covers all five conversion strategies between in-place and out-of-place interfaces.
See also: CTFlowsSciMLFlows._rhs_sciml_label, CTFlowsSciMLFlows.IPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpRHS, CTFlowsSciMLFlows.OoPSciMLIpFinalizeRHS, CTFlowsSciMLFlows.IPSciMLOoPRHS, CTFlowsSciMLFlows.OoPSciMLOoPRHS.
_rhs_sciml_label [Function]
CTFlowsSciMLFlows._rhs_sciml_label Function
_rhs_sciml_label(
_::CTFlowsSciMLFlows.IPSciMLIpRHS
) -> StringReturn 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.showmethods.Labels describe both the wrapped SciML function's interface and the provided interface.
See also: CTFlowsSciMLFlows._AnySciMLRHS.
From CTFlows.MultiPhase
_PiecewiseControlLaw [Struct]
CTFlows.MultiPhase._PiecewiseControlLaw Type
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 aCTBase.Data.ControlLaw).switches::S: then-1sorted switching times.
See also: CTFlows.MultiPhase._reconstruct_ocp_solution, CTFlows.MultiPhase._reconstruct_controlled_trajectory.
_apply_component_jump [Function]
CTFlows.MultiPhase._apply_component_jump Function
_apply_component_jump(v, j) -> AnyApply 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.
_apply_component_jump(v, j::Function) -> AnyApply a callable jump to a single component.
Arguments
v: Component value (state or costate).j::Function: Callable; called asj(v).
Returns
j(v).
See also: CTFlows.MultiPhase._apply_jump.
_apply_component_jump(v, _::Nothing) -> AnyIdentity jump — leave the component unchanged.
Arguments
v: Component value (state or costate).::Nothing: Sentinel for "no jump on this component".
Returns
vunchanged.
See also: CTFlows.MultiPhase._apply_jump.
_apply_hamiltonian_jump [Function]
CTFlows.MultiPhase._apply_hamiltonian_jump Function
_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, ornothing.
Returns
- Tuple of updated (state, costate).
See also: CTFlows.MultiPhase._apply_jump, CTFlows.MultiPhase._apply_component_jump.
_apply_hamiltonian_jump(
state_tuple::Tuple,
jump::Function
) -> AnyApply 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 byjump.
See also: CTFlows.MultiPhase._apply_jump, CTFlows.MultiPhase._apply_component_jump.
_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
_apply_jump(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
i,
state
) -> AnyApply 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.
_apply_jump(
_::Type{CTBase.Traits.StateDynamics},
mpf,
i,
state
) -> AnyApply 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).
_apply_jump(
_::Type{CTBase.Traits.HamiltonianDynamics},
mpf,
i,
state_tuple
) -> AnyApply 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
_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
CTBase.Exceptions.PreconditionError: If switching times are not strictly increasing.
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
_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.
_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
_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.
_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.
_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.
_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
_extract_final_state(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
segment,
current_state
) -> AnyExtract 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.
_extract_final_state(
_::Type{CTBase.Traits.StateDynamics},
segment,
_
) -> AnyExtract 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.
_extract_final_state(
_::Type{CTBase.Traits.StateDynamics},
segment::CTFlows.Trajectories.VectorFieldTrajectory,
_
) -> AnyExtract the final state from a VectorFieldTrajectory segment for state dynamics, reshaped back to the segment's own x0 container type (see CTFlows.MultiPhase._reshape_to_x0) rather than through its "1-D = scalar" Integrators.final_state accessor (issue #357).
_extract_final_state(
_::Type{CTBase.Traits.StateDynamics},
segment::CTFlows.Trajectories.StateFlowTrajectory,
_
) -> AnyExtract the final state from a StateFlowTrajectory segment for state dynamics (Flow(fc, law) / Flow(ocp, law)), reshaped back to the inner trajectory's own x0 container type (see CTFlows.MultiPhase._reshape_to_x0) rather than through its "1-D = scalar" Integrators.final_state accessor — see the VectorFieldTrajectory overload above for why.
_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_final_state(
_::Type{CTBase.Traits.HamiltonianDynamics},
segment::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
_
) -> Tuple{Any, Any}Extract the final state and costate from a HamiltonianVectorFieldTrajectory segment.
Unlike the generic HamiltonianDynamics method, no manual splitting is needed because HamiltonianVectorFieldTrajectory already stores the combined (x, p) vector and Integrators.final_state returns it directly.
Returns
- The final combined
(state, costate)vector from the segment.
_extract_initial_state [Function]
CTFlows.MultiPhase._extract_initial_state Function
_extract_initial_state(
config::CTFlows.Configs.AbstractStateConfig
) -> AnyExtract 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.
_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
_finalize_multiphase_trajectory(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
merged,
variable
) -> AnyFinalize 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, aStateFlowTrajectory, or the merged trajectory (see above).
See also: CTFlows.MultiPhase._evaluate_multiphase.
_format_final_output [Function]
CTFlows.MultiPhase._format_final_output Function
_format_final_output(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
state
) -> AnyFormat 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.
_format_final_output(
_::Type{CTBase.Traits.StateDynamics},
x
) -> AnyFormat 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.
_format_final_output(
_::Type{CTBase.Traits.HamiltonianDynamics},
state_tuple
) -> AnyFormat 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.
_multiphase_display_name(
_::CTFlows.MultiPhase.MultiPhaseHamiltonianFlow
) -> StringReturn "MultiPhaseHamiltonianFlow" for a MultiPhaseFlow with HamiltonianDynamics.
_multiphase_display_name(
mpf::CTFlows.MultiPhase.MultiPhaseFlow
) -> StringFallback: return the concrete type name as a string.
_phase_law [Function]
CTFlows.MultiPhase._phase_law Function
_phase_law(
pl::CTFlows.MultiPhase._PiecewiseControlLaw,
t
) -> AnyReturn 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
_raw_flow(f::CTFlows.Flows.AbstractFlow) -> AnyReturn 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.
_raw_flow(f::CTFlows.Flows.OptimalControlFlow) -> AnyUnwrap an CTFlows.Flows.OptimalControlFlow to its inner flow.
Returns
f.flow: the innerStateFlow/HamiltonianFlow.
_raw_flow(f::CTFlows.Flows.ControlledFlow) -> AnyUnwrap a CTFlows.Flows.ControlledFlow to its inner flow.
Returns
f.flow: the innerStateFlow/HamiltonianFlow.
_reconstruct_controlled_trajectory [Function]
CTFlows.MultiPhase._reconstruct_controlled_trajectory Function
_reconstruct_controlled_trajectory(
mpf,
merged,
variable
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}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
- A
CTFlows.Trajectories.StateFlowTrajectorywith the piecewise-reconstructed control.
See also: CTFlows.MultiPhase._reconstruct_ocp_solution, CTFlows.Flows._state_flow_objective.
_reconstruct_ocp_solution [Function]
CTFlows.MultiPhase._reconstruct_ocp_solution Function
_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
- A
CTModels.Solutions.Solutionwith the piecewise-reconstructed control.
See also: CTFlows.MultiPhase._reconstruct_controlled_trajectory, CTFlows.Flows._build_ocp_solution.
_reshape_to_x0 [Function]
CTFlows.MultiPhase._reshape_to_x0 Function
_reshape_to_x0(x0::Number, raw) -> AnyReshape a raw internal final state back to match x0's own declared container type, for inter-phase handoff inside a multi-phase state flow.
Notes
This is deliberately not CTFlows.Systems._coerce_state: that function also collapses a length-1 AbstractVector/SVector to a scalar (the "1-D = scalar" convention, issue #357), which is the right call for a user-facing accessor but wrong for this internal handoff — it would silently turn a length-1-vector-sourced multi-phase state into a scalar mid-chain, producing a phase 2 segment with a different x0 container type than phase 1's, which CTSolvers.Integrators.merge cannot concatenate. A bare Number x0 still collapses the raw result (needed because some flows, e.g. Flow(ocp, law), may integrate on an internally-promoted vector even when the caller declared a scalar x0); any AbstractVector/AbstractMatrix x0, length-1 included, is returned as-is.
_reshape_to_x0(x0, raw) -> AnyFallback for AbstractVector/AbstractMatrix x0: return raw unchanged.
Unlike the Number method, no collapsing is needed — the container type already matches what CTSolvers.Integrators.merge expects.
_shared_ocp [Function]
CTFlows.MultiPhase._shared_ocp Function
_shared_ocp(phases) -> AnyReturn 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 anocpfield).
Returns
- The single OCP object (or
nothing) common to all phases.
Throws
CTBase.Exceptions.IncorrectArgument: if the phases carry two or more distinct OCP objects.
From CTFlows.Systems
HVFIpFunctor [Struct]
CTFlows.Systems.HVFIpFunctor Type
struct HVFIpFunctor{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend} <: FunctionIn-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) -> nothingNonAutonomous/Fixed —
(dx, dp, t, x, p) -> nothingAutonomous/NonFixed —
(dx, dp, x, p, v; dpv=nothing, variable_costate=false) -> nothingNonAutonomous/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: whenvariable_costate=trueanddpvisnothing.
See also: CTFlows.Systems.HVFOoPFunctor, CTFlows.Systems.hamiltonian_vector_field.
HVFOoPFunctor [Struct]
CTFlows.Systems.HVFOoPFunctor Type
struct HVFOoPFunctor{H<:CTBase.Data.AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend} <: FunctionOut-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)whenvariable_costate=trueNonAutonomous/NonFixed —
(t, x, p, v; variable_costate=false) -> (∂p, -∂x), or(∂p, -∂x, -∂v)whenvariable_costate=true
See also: CTFlows.Systems.HVFIpFunctor, CTFlows.Systems.hamiltonian_vector_field.
HamIpAugRHS [Struct]
CTFlows.Systems.HamIpAugRHS Type
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.AbstractIPHamRHSIn-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:
ẋ = ∂H/∂p
ṗ = -∂H/∂x
ṽ = -∂H/∂vThe state vector is augmented as [x; p; v] where v is the variable costate.
Fields
h::H: The Hamiltonian function (anyData.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 (ornothingfor systems without AD).
Call Signature
(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_augmentedfor Hamiltonian systems.
See also: CTFlows.Systems.HamIpRHS, CTFlows.Systems.HamOoPRHS.
HamIpRHS [Struct]
CTFlows.Systems.HamIpRHS Type
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.AbstractIPHamRHSIn-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:
ẋ = ∂H/∂p
ṗ = -∂H/∂xFields
h::H: The Hamiltonian function (anyData.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 (ornothingfor systems without AD).
Call Signature
(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_rhsfor Hamiltonian systems.
See also: CTFlows.Systems.HamOoPRHS, CTFlows.Systems.HamIpAugRHS.
HamOoPRHS [Struct]
CTFlows.Systems.HamOoPRHS Type
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.AbstractOoPHamRHSOut-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:
ẋ = ∂H/∂p
ṗ = -∂H/∂xFields
h::H: The Hamiltonian function (anyData.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 (ornothingfor systems without AD).
Call Signature
(f::HamOoPRHS)(u, λ, t) -> duu: 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_rhsfor Hamiltonian systems.
See also: CTFlows.Systems.HamIpRHS, CTFlows.Systems.HamIpAugRHS.
IPHVFIpAugRHS [Struct]
CTFlows.Systems.IPHVFIpAugRHS Type
IPHVFIpAugRHS{F,TD,VD} <: AbstractIPHVFRHSIn-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
IPHVFIpRHS{F,TD,VD,CX,CP} <: AbstractIPHVFRHSIn-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.,identityoronly).cp::CP: Coercion function for costate (e.g.,identityoronly).
Call signature
(f::IPHVFIpRHS)(du, u, λ, t) -> nothing
IPHVFOoPAugRHS [Struct]
CTFlows.Systems.IPHVFOoPAugRHS Type
IPHVFOoPAugRHS{F,TD,VD} <: AbstractIPHVFRHSIn-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
IPHVFOoPRHS{F,TD,VD,CX,CP} <: AbstractIPHVFRHSIn-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.,identityoronly).cp::CP: Coercion function for costate (e.g.,identityoronly).
Call signature
(f::IPHVFOoPRHS)(du, u, λ, t) -> nothing
IPPseudoHVFIpAugRHS [Struct]
CTFlows.Systems.IPPseudoHVFIpAugRHS Type
struct IPPseudoHVFIpAugRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHSIn-place augmented RHS functor for an in-place PseudoHamiltonianVectorField with variable costate. Extends CTFlows.Systems.IPPseudoHVFIpRHS with ṗv = -∂H̃/∂v (supplied directly by h̃vf at u_ = law(t,x,p,v), no AD). The augmented state is [x; p; pv].
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).n_x::Int: state dimension.n_v::Int: variable dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::IPPseudoHVFIpAugRHS)(du, u, λ, t) -> nothing
See also: CTFlows.Systems.IPPseudoHVFOoPAugRHS.
IPPseudoHVFIpRHS [Struct]
CTFlows.Systems.IPPseudoHVFIpRHS Type
struct IPPseudoHVFIpRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHSIn-place RHS functor for an in-place PseudoHamiltonianVectorField. Evaluates the feedback control u_ = law(t, x, p, v) and then calls the wrapped in-place vector field directly with the pre-allocated dx/dp buffers.
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).N::Int: state dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::IPPseudoHVFIpRHS)(du, u, λ, t) -> nothing
See also: CTFlows.Systems.IPPseudoHVFOoPRHS.
IPPseudoHVFOoPAugRHS [Struct]
CTFlows.Systems.IPPseudoHVFOoPAugRHS Type
struct IPPseudoHVFOoPAugRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHSIn-place augmented RHS functor for an out-of-place PseudoHamiltonianVectorField with variable costate. Evaluates u_ = law(t, x, p, v), then calls h̃vf(t, x, p, u_, v; variable_costate=true) to get (dx, dp, dpv). The augmented state is [x; p; pv].
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).n_x::Int: state dimension.n_v::Int: variable dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::IPPseudoHVFOoPAugRHS)(du, u, λ, t) -> nothing
See also: CTFlows.Systems.IPPseudoHVFIpAugRHS.
IPPseudoHVFOoPRHS [Struct]
CTFlows.Systems.IPPseudoHVFOoPRHS Type
struct IPPseudoHVFOoPRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractIPPseudoHVFRHSIn-place RHS functor for an out-of-place PseudoHamiltonianVectorField. Evaluates the feedback control u_ = law(t, x, p, v) and then computes (dx, dp) = h̃vf(t, x, p, u_, v) directly (no AD), writing the result into the pre-allocated du buffer.
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).N::Int: state dimension.cx::CX: coercion function for state (e.g.,identityor_safe_only).cp::CP: coercion function for costate (e.g.,identityor_safe_only).
Call signature
(f::IPPseudoHVFOoPRHS)(du, u, λ, t) -> nothing
See also: CTFlows.Systems.OoPPseudoHVFOoPRHS, CTFlows.Systems.IPPseudoHVFIpRHS.
IPVFIpRHS [Struct]
CTFlows.Systems.IPVFIpRHS Type
IPVFIpRHS{F,TD,VD,CX} <: AbstractIPRHSIn-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 VectorFieldcx::CX: coercion applied to the state before callingvf.
Call signature
(f::IPVFIpRHS)(du, u, λ, t) -> nothing
IPVFOoPRHS [Struct]
CTFlows.Systems.IPVFOoPRHS Type
IPVFOoPRHS{VF<:Data.AbstractVectorField,CX} <: AbstractIPRHSIn-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 (anyData.AbstractVectorField).cx::CX: coercion applied to the state before callingvf(_safe_onlyfor a 1-D state,identityotherwise) — seeCTFlows.Systems._coerce_state.
Call signature
(f::IPVFOoPRHS)(du, u, λ, t) -> nothing
Notes
duis always the pre-allocated buffer supplied by the integrator, matchingu's actual (uncoerced) shape — broadcasting a coerced-scalar result into it is safe regardless ofcx(the Handbook's documented "in-place buffer stays a vector" exception).
OoPHVFIpFinalizeRHS [Struct]
CTFlows.Systems.OoPHVFIpFinalizeRHS Type
OoPHVFIpFinalizeRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHSOut-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.,identityoronly).cp::CP: Coercion function for costate (e.g.,identityoronly).
Call signature
(f::OoPHVFIpFinalizeRHS)(u, λ, t) -> du
OoPHVFIpRHS [Struct]
CTFlows.Systems.OoPHVFIpRHS Type
OoPHVFIpRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHSOut-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.,identityoronly).cp::CP: Coercion function for costate (e.g.,identityoronly).
Call signature
(f::OoPHVFIpRHS)(u, λ, t) -> du
OoPHVFOoPRHS [Struct]
CTFlows.Systems.OoPHVFOoPRHS Type
OoPHVFOoPRHS{F,TD,VD,CX,CP} <: AbstractOoPHVFRHSOut-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.,identityoronly).cp::CP: Coercion function for costate (e.g.,identityoronly).
Call signature
(f::OoPHVFOoPRHS)(u, λ, t) -> du
OoPPseudoHVFIpFinalizeRHS [Struct]
CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS Type
struct OoPPseudoHVFIpFinalizeRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHSOut-of-place RHS functor for an in-place PseudoHamiltonianVectorField, converting the result back to the input array type (e.g. Vector → SVector) for immutable initial conditions.
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).N::Int: state dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::OoPPseudoHVFIpFinalizeRHS)(u, λ, t) -> du
See also: CTFlows.Systems.OoPPseudoHVFIpRHS.
OoPPseudoHVFIpRHS [Struct]
CTFlows.Systems.OoPPseudoHVFIpRHS Type
struct OoPPseudoHVFIpRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHSOut-of-place RHS functor for an in-place PseudoHamiltonianVectorField; allocates temporary dx/dp buffers on each call via similar.
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.InPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).N::Int: state dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::OoPPseudoHVFIpRHS)(u, λ, t) -> du
See also: CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS.
OoPPseudoHVFOoPRHS [Struct]
CTFlows.Systems.OoPPseudoHVFOoPRHS Type
struct OoPPseudoHVFOoPRHS{F<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, L<:CTBase.Data.ControlLaw, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CP<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: CTFlows.Systems.AbstractOoPPseudoHVFRHSOut-of-place RHS functor for an out-of-place PseudoHamiltonianVectorField; see CTFlows.Systems.IPPseudoHVFOoPRHS for the computation. Returns vcat(dx, dp).
Fields
h̃vf::PseudoHamiltonianVectorField{F,TD,VD,Traits.OutOfPlace}: the wrapped pseudo-Hamiltonian vector field.law::L: the dynamic closed-loop control lawu(t, x, p, v).N::Int: state dimension.cx::CX: coercion function for state.cp::CP: coercion function for costate.
Call signature
(f::OoPPseudoHVFOoPRHS)(u, λ, t) -> du
See also: CTFlows.Systems.IPPseudoHVFOoPRHS.
OoPVFIpFinalizeRHS [Struct]
CTFlows.Systems.OoPVFIpFinalizeRHS Type
OoPVFIpFinalizeRHS{F,TD,VD,CX} <: AbstractOoPRHSOut-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 VectorFieldcx::CX: coercion applied to the state before callingvf.
Call signature
(f::OoPVFIpFinalizeRHS)(u, λ, t) -> du
OoPVFIpRHS [Struct]
CTFlows.Systems.OoPVFIpRHS Type
OoPVFIpRHS{F,TD,VD,CX} <: AbstractOoPRHSOut-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 VectorFieldcx::CX: coercion applied to the state before callingvf.
Call signature
(f::OoPVFIpRHS)(u, λ, t) -> du
Notes
dx = similar(u)already matchesu's actual (uncoerced) shape, so no reshaping is needed here even whencxcollapses the CALL argument to a scalar — the in-placevfcall still writes into the properly-shaped buffer.
OoPVFOoPRHS [Struct]
CTFlows.Systems.OoPVFOoPRHS Type
OoPVFOoPRHS{VF<:Data.AbstractVectorField,CX} <: AbstractOoPRHSOut-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 (anyData.AbstractVectorField).cx::CX: coercion applied to the state before callingvf.
Call signature
(f::OoPVFOoPRHS)(u, λ, t) -> du
Notes
- Unlike the Hamiltonian-family out-of-place functors (which always reassemble their return value via
vcatof a state and a costate block, safe for either shape), this functor has a single block and nothing to reassemble: whencxcollapsesuto a scalar for the call,vfmay return a bare scalar too, which does not matchu's own (uncoerced) container shape. That case is reshaped back explicitly so the returned derivative always matchesu's actual type, as SciML's out-of-place interface requires.
__hvf_ad_backend [Function]
CTFlows.Systems.__hvf_ad_backend Function
__hvf_ad_backend(
) -> CTBase.Differentiation.DifferentiationInterface{CTBase.Strategies.CPU, CTBase.Strategies.StrategyOptions{NT}} where NT<:NamedTupleDefault AD backend for the hamiltonian_vector_field(h::Data.AbstractHamiltonian; ...) getter.
Returns Differentiation.DifferentiationInterface(), the CPU-default strategy. Callers that need a device-specific backend (e.g. GPU) must build and pass one explicitly — this default is not device-aware.
See also: CTFlows.Systems.hamiltonian_vector_field, CTBase.Differentiation.DifferentiationInterface.
_aug_assign! [Function]
CTFlows.Systems._aug_assign! Function
_aug_assign!(
du::AbstractVector,
dx,
dp,
dpv,
n_x::Int64,
n_v::Int64
)Assign derivatives to the augmented derivative vector for Hamiltonian systems with variable costate.
The augmented derivative vector has the form [dx; dp; dpv] where:
dxis the state derivative (firstn_xelements)dpis the costate derivative (nextn_xelements)dpvis the variable costate derivative (lastn_velements)
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_assign!(
du::AbstractMatrix,
dx,
dp,
dpv,
n_x::Int64,
n_v::Int64
)Matrix variant of CTFlows.Systems._aug_assign!: assigns state, costate, and variable-costate derivatives into the corresponding row-blocks of each column.
See also: CTFlows.Systems._aug_assign!.
_aug_split [Function]
CTFlows.Systems._aug_split Function
_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:
xis the state (firstn_xelements)pis the costate (nextn_xelements)pvis the variable costate (lastn_velements)
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@viewslice.
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.
_aug_split(
u::AbstractMatrix,
n_x::Int64,
n_v::Int64
) -> Tuple{Any, Any, Any}Matrix variant of CTFlows.Systems._aug_split: splits each column of u into state, costate, and variable-costate row-block views.
See also: CTFlows.Systems._aug_split.
_buffer_like [Function]
CTFlows.Systems._buffer_like Function
_buffer_like(
template::AbstractArray,
_::Type{T},
n::Int64
) -> AnyAllocate an uninitialised length-n buffer of eltype T in template's array type.
Arguments
template: an array or scalar whose type determines the buffer's array backend.T: the element type of the buffer.n::Int: the length of the buffer.
Returns
For
template::AbstractArray:similar(template, T, n)— same array backend astemplate.For any other
template(e.g.Number):Vector{T}(undef, n)— a host vector.
Notes
The OCP right-hand sides fill a length-
n_xbuffer through the in-place dynamicsdynamics!(r, t, x, u, v), plus emptyu/vbuffers for control-free /Fixedproblems. Allocating those as a hostVectorpins the whole OCP hot path to the CPU; deriving them from the state instead keeps the buffer on whichever device the state already lives on.The
Numberfallback is required, not defensive: under the "1-D = scalar" convention the coerced state is a scalar (viaCTFlows.Systems._safe_onlyfor a declared dimension of 1), andsimilaris undefined forNumber. A scalar state is a host scalar even on GPU, so a hostVectoris the correct buffer there.This generalises the same
isa AbstractArraybranch already used forpv0inCTFlows.Flowsaugmented initial conditions.Dispatch is on the value actually received at the call site, so CPU behaviour is byte-for-byte unchanged and no run-time type test enters the hot path.
See also: CTFlows.Systems._device_like, CTFlows.Systems._safe_only.
_buffer_like(_, _::Type{T}, n::Int64) -> AnyScalar fallback: allocate a host Vector{T}(undef, n) — similar is undefined for Number.
See also: CTFlows.Systems._buffer_like.
_buffer_like(
template::AbstractMatrix,
_::Type{T},
n::Int64
) -> AnyAllocate an uninitialised n × batch buffer of eltype T when template is itself a batched Matrix state (each column an independent trajectory) — batch = size(template, 2).
More specific than the AbstractArray method above, so it is selected automatically for a Matrix/MMatrix/SMatrix template; no call site needs to change.
See also: CTFlows.Systems._buffer_like.
_check_aug_batch_compat [Function]
CTFlows.Systems._check_aug_batch_compat Function
Check batch size compatibility for augmented Hamiltonian RHS with matrix inputs.
When using batch mode with matrix inputs, ensures that the state matrix u and variable matrix v have compatible batch sizes (same number of columns).
Arguments
u::AbstractMatrix: State matrix with shape(n, batch_size).v::AbstractMatrix: Variable matrix with shape(m, batch_size).
Returns
nothingif batch sizes match.
Throws
Exceptions.PreconditionError: Ifsize(u, 2) ≠ size(v, 2).
Notes
No-op for non-matrix inputs (vectors or scalars).
Used internally by
CTFlows.Systems.HamIpAugRHSto validate batch mode.
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
Used as fallback when inputs are not matrices.
See
CTFlows.Systems._check_aug_batch_compat(::AbstractMatrix, ::AbstractMatrix)for the matrix version.
_coerce_state [Function]
CTFlows.Systems._coerce_state Function
_coerce_state(
_::Number
) -> typeof(CTFlows.Systems._safe_only)Return the coercion applied to a 1-D quantity (state, costate, variable costate, control) so that it is represented as a scalar when it has length 1, and left untouched otherwise.
Methods
_coerce_state(::Number) = _safe_only_coerce_state(::AbstractMatrix) = identity_coerce_state(x::AbstractVector) = length(x) == 1 ? _safe_only : identity
This enforces the ecosystem convention "a 1-dimensional quantity is a scalar": both 2.0 and [2.0] collapse to the scalar 2.0 via _safe_only, regardless of how the user supplied the initial condition. Vectors of length ≥ 2 and matrices (batch mode) are left untouched via identity.
Notes
Scope (issue control-toolbox/CTFlows.jl#357): applied on every control-toolbox-sourced flow —
HamiltonianSystem,HamiltonianVectorFieldSystem,PseudoHamiltonianSystem,ConstrainedPseudoHamiltonianSystem,PseudoHamiltonianVectorFieldSystem,VectorFieldSystem, andCTFlowsSciMLFlows.SciMLFunctionSystem(which sharesVectorFieldSystem'sSystems/Trajectoriesdispatch).CTFlowsSciMLFlows.SciMLProblemFlow(built directly from anSciMLBase.AbstractODEProblem) genuinely bypasses this dispatch (remake+solveonly) and stays shape-preserving instead — it never calls_coerce_state.Differs from
CTBase.Core.make_coercein that a length-1 vector also collapses to a scalar (_safe_only, the GPU-safeonly), not only a bareNumber.
See also: CTFlows.Systems._safe_only.
_coerce_state(_::AbstractMatrix) -> typeof(identity)Batched Matrix states are always left untouched (identity): batch mode never collapses to a scalar.
See also: CTFlows.Systems._coerce_state.
_coerce_state(
x::AbstractVector
) -> Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}Vector states: _safe_only for length 1 (1-D = scalar convention), identity otherwise.
See also: CTFlows.Systems._coerce_state, CTFlows.Systems._safe_only.
_coerce_state(
_::CTBase.Core.NotProvidedType
) -> typeof(identity)No-op fallback for when the initial state is unknown (Core.NotProvided), e.g. a trajectory container built directly from a raw integration result without going through a Configs.AbstractConfig (tests, low-level plumbing). Safe default: apply no coercion rather than guess.
_device_like [Function]
CTFlows.Systems._device_like Function
_device_like(_::AbstractArray, src) -> NumberReturn src in a form that can be broadcast into dst without a device/host mismatch.
Arguments
dst: the destination array whose device determines the required location.src: the source block to broadcast intodst.
Returns
srcitself when it is already compatible withdst(host/host, device/device, or scalar).A device-resident copy of
srcwhendstis a device array andsrcis a host array.
Notes
Augmented Hamiltonian flows split into
[∂p; -∂x; -∂pv]; on GPU the state blocks∂x/∂pare device-resident but∂pv = -∂H/∂vis host (the variablevtransits host-side), so broadcasting it into a deviceduslice wraps a non-isbitshostVectorin aBroadcastedand fails to compile (GPUCompiler.KernelError)._device_likecopies only that host block onto the device matchingdst; on host, and for already-device blocks, it is the identity (no copy).Dispatch is on the array actually received at the call site, so CPU behaviour is byte-for-byte unchanged and only the degenerate device-
dst/host-srccase pays a tinyO(n_v)H2D copy.Backend-agnostic (
GPUArraysCore.AbstractGPUArraycovers CUDA/AMDGPU/Metal).
See also: CTFlows.Systems._aug_assign!, CTFlows.Systems._safe_only.
_device_like(
_::GPUArraysCore.AbstractGPUArray,
src::Number
) -> NumberScalar source is always compatible with any destination: return src as-is.
See also: CTFlows.Systems._device_like.
_device_like(
_::GPUArraysCore.AbstractGPUArray,
src::GPUArraysCore.AbstractGPUArray
) -> GPUArraysCore.AbstractGPUArrayDevice-resident source on a matching device destination: return src as-is (no copy).
See also: CTFlows.Systems._device_like.
_ham_assign! [Function]
CTFlows.Systems._ham_assign! Function
_ham_assign!(du::AbstractVector, dx, dp, N::Int64) -> AnyAssign 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::AbstractVectororAbstractMatrix: Combined derivative to fill[dx; dp].dx: State derivative (same shape as state part ofdu).dp: Costate derivative (same shape as costate part ofdu).N::Intornothing: State dimension. Ifnothing, infers assize(du, 1) ÷ 2.
Returns
nothing
Notes
Internal helper used by RHS builders for Hamiltonian systems.
Performs in-place assignment using broadcasting.
_ham_assign!(du::AbstractMatrix, dx, dp, N::Int64) -> AnyMatrix variant of CTFlows.Systems._ham_assign!: assigns state and costate derivatives into the corresponding row-blocks of each column.
See also: CTFlows.Systems._ham_assign!.
_ham_split [Function]
CTFlows.Systems._ham_split Function
_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::AbstractVectororAbstractMatrix: Combined state vector/matrix[x; p].N::Intornothing: State dimension. Ifnothing, infers assize(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
CTFlowsStaticArraysextension provides a type-stable method forStaticVector.
_ham_split(u::AbstractMatrix, N::Int64) -> Tuple{Any, Any}Matrix variant of CTFlows.Systems._ham_split: splits each column of u into state and costate row-block views.
See also: CTFlows.Systems._ham_split.
Type-stable split of a SVector into state and costate components.
Arguments
u::SVector: Combined state vector[x; p].N::Int: Known state dimension (compile-time).
Returns
Tuple{SVector{N}, SVector{N}}: Tuple of(x, p)asSVectors.
Notes
This method provides type stability for SciML's out-of-place ODE solvers when using
StaticArrays.Used automatically when the
CTFlowsStaticArraysextension 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)asSMatrixs.
Notes
This method provides type stability for SciML's out-of-place ODE solvers when using
StaticArraysfor matrix initial conditions.Constructs new
SMatrixobjects 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
CTFlowsStaticArraysextension is loaded.
_hamiltonian_vector_field_by_ad [Function]
CTFlows.Systems._hamiltonian_vector_field_by_ad Function
_hamiltonian_vector_field_by_ad(
::Type{CTBase.Traits.WithAD},
sys::CTFlows.Systems.AbstractHamiltonianSystem;
inplace
) -> AnyCompute 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.
_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 implementhamiltonian_vector_fieldfor the system type or useHamiltonianVectorFieldSystem.
See also: CTFlows.Systems.hamiltonian_vector_field, CTFlows.Systems.HamiltonianVectorFieldSystem.
_rhs_conversion_label [Function]
CTFlows.Systems._rhs_conversion_label Function
_rhs_conversion_label(
f::CTFlows.Systems.IPVFOoPRHS
) -> StringReturn a descriptive label for the RHS conversion performed by a vector-field functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractRHS.
_rhs_conversion_label(
f::CTFlows.Systems.IPVFIpRHS
) -> StringIn-place VF wrapped as in-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
f::CTFlows.Systems.OoPVFOoPRHS
) -> StringOut-of-place VF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
f::CTFlows.Systems.OoPVFIpRHS
) -> StringIn-place VF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
f::CTFlows.Systems.OoPVFIpFinalizeRHS
) -> StringIn-place VF wrapped as out-of-place interface with type-finalize conversion.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPHVFOoPRHS
) -> StringReturn a descriptive label for the RHS conversion performed by a Hamiltonian vector field functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractHVFRHS.
_rhs_conversion_label(
_::CTFlows.Systems.IPHVFIpRHS
) -> StringIn-place HVF wrapped as in-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPHVFOoPRHS
) -> StringOut-of-place HVF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPHVFIpRHS
) -> StringIn-place HVF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPHVFIpFinalizeRHS
) -> StringIn-place HVF wrapped as out-of-place interface with type-finalize conversion.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPHVFOoPAugRHS
) -> StringOut-of-place HVF wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPHVFIpAugRHS
) -> StringIn-place HVF wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(_::CTFlows.Systems.HamIpRHS) -> StringReturn a descriptive label for the RHS conversion performed by a Hamiltonian functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractHamRHS.
_rhs_conversion_label(
_::CTFlows.Systems.HamOoPRHS
) -> StringHamiltonian AD wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.HamIpAugRHS
) -> StringHamiltonian AD wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.PseudoHamIpRHS
) -> StringReturn a descriptive label for the RHS conversion performed by a pseudo-Hamiltonian functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractPseudoHamRHS.
_rhs_conversion_label(
_::CTFlows.Systems.PseudoHamOoPRHS
) -> StringPseudo-Hamiltonian AD wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.PseudoHamIpAugRHS
) -> StringPseudo-Hamiltonian AD wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPPseudoHVFOoPRHS
) -> StringReturn a descriptive label for the RHS conversion performed by a pseudo-Hamiltonian vector field functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractPseudoHVFRHS.
_rhs_conversion_label(
_::CTFlows.Systems.IPPseudoHVFIpRHS
) -> StringIn-place PHVF wrapped as in-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPPseudoHVFOoPRHS
) -> StringOut-of-place PHVF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPPseudoHVFIpRHS
) -> StringIn-place PHVF wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.OoPPseudoHVFIpFinalizeRHS
) -> StringIn-place PHVF wrapped as out-of-place interface with type-finalize conversion.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPPseudoHVFOoPAugRHS
) -> StringOut-of-place PHVF wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.IPPseudoHVFIpAugRHS
) -> StringIn-place PHVF wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.ConstrainedPseudoHamIpRHS
) -> StringReturn a descriptive label for the RHS conversion performed by a constrained pseudo-Hamiltonian functor.
Used internally by Base.show for display.
See also: CTFlows.Systems.AbstractPseudoHamRHS.
_rhs_conversion_label(
_::CTFlows.Systems.ConstrainedPseudoHamOoPRHS
) -> StringConstrained pseudo-Hamiltonian AD wrapped as out-of-place interface.
See also: CTFlows.Systems._rhs_conversion_label.
_rhs_conversion_label(
_::CTFlows.Systems.ConstrainedPseudoHamIpAugRHS
) -> StringConstrained pseudo-Hamiltonian AD wrapped as in-place augmented interface.
See also: CTFlows.Systems._rhs_conversion_label.
_safe_only [Function]
CTFlows.Systems._safe_only Function
_safe_only(x::GPUArraysCore.AbstractGPUArray)Collapse a length-1 array to its single scalar element, GPU-safely.
Arguments
x::GPUArraysCore.AbstractGPUArray: device-resident array whose single element is extracted.x: any other length-1 collection (host arrays, etc.).
Returns
- The single scalar element of
x(a host scalar on both CPU and GPU).
Notes
On host arrays this is exactly
only(x).On device arrays,
onlywould resolve viaiterate → getindex, whichGPUArraysCoreblocks by default (scalar indexing of device memory). Since this is a single, deliberate, O(1) terminal extraction — not a scalar loop — it is wrapped in@allowscalar.Dispatch is on the array actually received at the call site, so the "1-D = scalar" convention returns an identical host scalar on CPU and GPU (never a device 1-vector).
Backend-agnostic (
AbstractGPUArraycovers CUDA/AMDGPU/Metal).On the RHS hot path, only ever runs for the degenerate length-1-on-GPU case (real GPU workloads have
length ≥ 2, whereCTFlows.Systems._coerce_statereturnsidentityat zero cost).
See also: CTFlows.Systems._coerce_state.
_safe_only(x)Host-array fallback: exactly only(x).
See also: CTFlows.Systems._safe_only.
_state_dim [Function]
CTFlows.Systems._state_dim Function
_state_dim(_::Number) -> Int64Infer the state dimension from the initial condition shape.
Methods
_state_dim(x0::Number) = 1_state_dim(x0::AbstractVector) = length(x0)_state_dim(x0::AbstractMatrix) = size(x0, 1)
_state_dim(x::AbstractVector) -> AnyState dimension of a vector initial condition: length(x).
See also: CTFlows.Systems._state_dim.
_state_dim(x::AbstractMatrix) -> AnyState dimension of a batched Matrix initial condition: size(x, 1) (per-column batch).
See also: CTFlows.Systems._state_dim.
constraint [Function]
CTFlows.Systems.constraint Function
constraint(
sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> AnyReturn 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
multiplier(
sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> AnyReturn 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
_check_dyn_config(
_::Type{CTBase.Traits.StateDynamics},
_::CTFlows.Configs.AbstractConfig
)Compatibility guard between system dynamics and config type.
Validates that the dynamics trait of the system matches the expected config type:
StateDynamics↔AbstractConfigHamiltonianDynamics↔AbstractHamiltonianConfigorAbstractAugmentedHamiltonianConfig
Throws PreconditionError if the pair is incompatible.
See also: CTFlows.Configs.AbstractConfig, CTFlows.Configs.AbstractHamiltonianConfig.
From CTFlows.Flows
ConstrainedPseudoHamiltonianFunction [Struct]
CTFlows.Flows.ConstrainedPseudoHamiltonianFunction Type
struct ConstrainedPseudoHamiltonianFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H<:CTFlows.Flows.OCPPseudoHamiltonianFunction, G, M} <: FunctionInternal 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 H̃ is an CTFlows.Flows.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 H̃, μ, g and the law (total derivative). The (TD, VD) traits drive natural-arity dispatch exactly as for CTFlows.Flows.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-HamiltonianH̃(t,x,p,u,v).g::G: path constraintg(t,x,u,v).μ::M: multiplierμ(t,x,p,v).
See also: CTFlows.Flows.OCPPseudoHamiltonianFunction, CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.
OCPControlledVectorFieldFunction [Struct]
CTFlows.Flows.OCPControlledVectorFieldFunction Type
struct OCPControlledVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: FunctionInternal 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 dynamicsf!(r, t, x, u, v)from the OCP.n::Int: state dimension.cx::CX,cu::CU,cv::CV: state / control / variable coercions (onlyfor a 1-D quantity,identityotherwise), 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
struct OCPHamiltonianFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, LF<:Union{Nothing, Function}} <: FunctionInternal 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 (AutonomousorNonAutonomous).VD: variable-dependence trait (FixedorNonFixed).DF: type of the in-place dynamics function.LF: type of the Lagrange cost function (orNothing).
Fields
dynamics!::DF: in-place dynamicsf!(r, t, x, u, v)from the OCP.lagrange::LF: Lagrange costℓ(t, x, u, v)ornothingif absent.sp0::Float64: sign-weighted multipliers·p⁰.n::Int: state dimension.
See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows._ocp_H, CTFlows.Flows._ocp_hamiltonian.
OCPPseudoHamiltonianFunction [Struct]
CTFlows.Flows.OCPPseudoHamiltonianFunction Type
struct OCPPseudoHamiltonianFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, LF<:Union{Nothing, Function}} <: FunctionInternal 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 CTFlows.Flows.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 (orNothing).
Fields
dynamics!::DF: in-place dynamicsf!(r, t, x, u, v)from the OCP.lagrange::LF: Lagrange costℓ(t, x, u, v)ornothing.sp0::Float64: sign-weighted multipliers·p⁰.n::Int: state dimension.
See also: CTFlows.Flows.OCPHamiltonianFunction, CTFlows.Flows._ocp_pseudo_hamiltonian, CTBase.Data.PseudoHamiltonian.
OCPStateVectorFieldFunction [Struct]
CTFlows.Flows.OCPStateVectorFieldFunction Type
struct OCPStateVectorFieldFunction{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}} <: FunctionInternal 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 dynamicsf!(r, t, x, u, v)from the OCP (called with an emptyu).n::Int: state dimension.cx::CX,cv::CV: state / variable coercions (onlyfor a 1-D quantity,identityotherwise), precomputed once from the OCP dimensions.
See also: CTBase.Data.VectorField, CTFlows.Flows._ocp_state_vector_field, CTFlows.Flows.OCPControlledVectorFieldFunction.
_CTM_Auton [Abstract Type]
CTFlows.Flows._CTM_Auton Type
Const aliases for CTModels.Components.Autonomous / NonAutonomous, keeping method signatures concise in the call-operator dispatch below.
_CombinedConstraint [Struct]
CTFlows.Flows._CombinedConstraint Type
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
parts::G: the resolved per-constraint carriers (each aCTBase.Data.PathConstraint).
See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._CombinedMultiplier.
_CombinedMultiplier [Struct]
CTFlows.Flows._CombinedMultiplier Type
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
parts::M: the resolved per-multiplier carriers (each aCTBase.Data.Multiplier).
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
Used by
CTFlows.Flows._route_flow_optionsandCTFlows.Flows._build_flow_components.Passed to
CTBase.Orchestration.route_all_optionsandCTBase.Orchestration.resolve_method.
See also: CTFlows.Flows._route_flow_options, CTFlows.Flows._build_flow_components, CTFlows.Flows._flow_families.
_FLOW_REGISTRY [Constant]
CTFlows.Flows._FLOW_REGISTRY Constant
Strategy registry for flow construction.
This constant holds the precomputed strategy registry that maps abstract strategy types to their concrete implementations for flow construction:
Differentiation.AbstractADBackend→Differentiation.DifferentiationInterfaceIntegrators.AbstractIntegrator→Integrators.SciML
Type
CTBase.Strategies.StrategyRegistry: Registry mapping abstract types to concrete implementations.
Notes
Created at module load time via
CTBase.Strategies.create_registry.Used by
CTFlows.Flows.flow_registryto provide the registry to routing functions.The registry is cached for performance.
See also: CTFlows.Flows.flow_registry, CTFlows.Flows._route_flow_options, CTBase.Strategies.create_registry.
_apply_dim_coerce [Function]
CTFlows.Flows._apply_dim_coerce Function
_apply_dim_coerce(
coerce,
x::AbstractMatrix
) -> AbstractMatrixApply a precomputed per-dimension coercion (_dim_coerce), except on a batched Matrix value, which is always left untouched regardless of the declared dimension. _dim_coerce is baked in once from the OCP's declared dimension, at flow-construction time, before the shape of any future call-site value is known — it cannot itself special-case Matrix. This guard is the runtime check that closes that gap, mirroring Systems._coerce_state(::AbstractMatrix) = identity.
See also: CTFlows.Flows._dim_coerce.
_apply_dim_coerce(coerce, x) -> AbstractMatrixApply a precomputed per-dimension coercion to a non-batched value: returns coerce(x) (only for 1-D, identity otherwise).
See also: CTFlows.Flows._apply_dim_coerce, CTFlows.Flows._dim_coerce.
_arity_issue [Function]
CTFlows.Flows._arity_issue Function
_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 iffhas more than one method (ambiguous).String: a one-line diagnostic naming the expected natural syntax, otherwise.
See also: CTFlows.Flows._expected_arity, CTFlows.Flows._natural_syntax.
_as_method_tokens [Function]
CTFlows.Flows._as_method_tokens Function
_as_method_tokens(_::Nothing)Normalize a user-supplied method into a token tuple, or return nothing when no method was given (the default). A bare Symbol (e.g. :gpu) is wrapped into a single-element tuple; a tuple of Symbols is returned as-is.
See also: CTFlows.Flows._flow_description
_as_method_tokens(m::Symbol) -> Tuple{Symbol}Wrap a bare Symbol (e.g. :gpu) into a single-element tuple.
See also: CTFlows.Flows._as_method_tokens, CTFlows.Flows._flow_description.
_as_method_tokens(
m::Tuple{Vararg{Symbol}}
) -> Tuple{Vararg{Symbol}}Return a tuple of Symbols as-is — already in the normalized form.
See also: CTFlows.Flows._as_method_tokens, CTFlows.Flows._flow_description.
_available_flow_methods [Function]
CTFlows.Flows._available_flow_methods Function
_available_flow_methods(
_::Type{CTBase.Traits.WithAD}
) -> Tuple{Tuple{Symbol, Symbol, Symbol}, Tuple{Symbol, Symbol, Symbol}}Candidate descriptions (the :cpu/:gpu device variants) against which a user method is completed via CTBase.Descriptions.complete.
_available_flow_methods(
_::Type{CTBase.Traits.WithoutAD}
) -> Tuple{Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol}}Candidate descriptions for an AD-free flow: only the :sciml integrator with :cpu/:gpu device variants (no :di backend).
See also: CTFlows.Flows._available_flow_methods, CTBase.Descriptions.complete.
_build_flow_components [Function]
CTFlows.Flows._build_flow_components Function
_build_flow_components(
ad_trait,
routed;
method
) -> Union{NamedTuple{_A, <:Tuple{Any}} where _A, NamedTuple{_A, <:Tuple{Any, Any}} where _A}Build concrete strategy instances from routed options.
Each strategy is constructed via CTBase.Orchestration.build_strategy_from_resolved using the options that were routed to its family by CTFlows.Flows._route_flow_options.
Arguments
ad_trait:Traits.WithAD(builds:dibackend +:scimlintegrator) orTraits.WithoutAD(builds only the:scimlintegrator).routed: Result ofCTFlows.Flows._route_flow_optionscontaining routed option values.method: Optional device selection (Symbol/token tuple, e.g.:gpu) threaded into the resolved global strategy parameter (CPU/GPU) for all families at once.
Returns
NamedTuple: concrete strategy instances keyed by family —(integrator,)forWithoutAD,(backend, integrator)forWithAD.
Example
routed = Flows._route_flow_options(Traits.WithAD, (; reltol=1e-8))
components = Flows._build_flow_components(Traits.WithAD, routed)
# components.backend isa CTBase.Differentiation.DifferentiationInterface
# components.integrator isa CTFlows.Integrators.SciMLSee also: CTFlows.Flows._route_flow_options, CTFlows.Flows.flow_registry, CTBase.Orchestration.build_strategy_from_resolved
_build_flow_components(
routed
) -> NamedTuple{(:backend, :integrator), <:Tuple{Any, Any}}Back-compat alias: build flow components using the WithAD plan (backend + integrator).
See also: CTFlows.Flows._build_flow_components.
_build_integrator [Function]
CTFlows.Flows._build_integrator Function
_build_integrator(opts) -> AnyBuild the SciML integrator for an AD-free flow (Traits.WithoutAD) directly from a flow constructor's keyword arguments, honouring a method=:gpu device selection popped from them.
Shared by the AD-free constructors (Flow(VectorField), Flow(HamiltonianVectorField), controlled-vector-field flows, Flow(ODEFunction), Flow(ODEProblem)), which build only an integrator (no :di AD backend). Routing through the WithoutAD plan means an ad_backend option is correctly rejected here as unknown (there is no AD backend to configure).
See also: CTFlows.Flows._build_flow_components, CTFlows.Flows._pop_method.
_build_ocp_pseudo_flow [Function]
CTFlows.Flows._build_ocp_pseudo_flow Function
_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).
:total— bake the constraint into the pseudo-HamiltonianH̃(t,x,p,u,v) + μ(t,x,p,v)·g(t,x,u,v)(viaCTFlows.Flows._ocp_constrained_pseudo_hamiltonian) and compose with the law; AD differentiates throughH̃,μ,gand the law (total derivative). Unconstrained → the plainCTFlows.Flows._ocp_pseudo_hamiltonian.:partial— build aCTFlows.Systems.ConstrainedPseudoHamiltonianSystemcarrying the baseH̃, the law,gandμseparately; the RHS freezes the multiplier valueμalongside the controluand differentiates only throughg. Unconstrained → aCTFlows.Systems.PseudoHamiltonianSystem.
See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier, CTFlows.Flows._build_pseudo_flow.
_build_ocp_pseudo_flow(
_::Val{:partial},
ocp,
law,
components,
cspec,
mspec
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.ConstrainedPseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}}Build the inner flow for the :partial mode from an OCP pseudo-Hamiltonian and a control law. When a constraint spec (cspec) is provided, resolve it together with the multiplier spec (mspec) and build a CTFlows.Systems.ConstrainedPseudoHamiltonianSystem; otherwise delegate to CTFlows.Flows._build_pseudo_flow.
See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.ConstrainedPseudoHamiltonianSystem, CTFlows.Flows._resolve_constraint, CTFlows.Flows._resolve_multiplier.
_build_ocp_pseudo_flow(
_::Val{ht},
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}))}Unknown hamiltonian_type: delegate to the (throwing) unconstrained fallback so the error message and type match Flow(h̃, law; hamiltonian_type=…).
See also: CTFlows.Flows._build_pseudo_flow.
_build_ocp_solution [Function]
CTFlows.Flows._build_ocp_solution Function
_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
_build_pseudo_flow(
_::Val{:total},
h̃,
law,
components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}Build the inner Hamiltonian flow for the :total mode: compose the pseudo-Hamiltonian H̃ with the control law u(t,x,p,v) into a CTBase.Data.ComposedHamiltonian H(t,x,p,v) = H̃(t,x,p,u(t,x,p,v),v), wrap it in a CTFlows.Systems.HamiltonianSystem, and build the flow.
See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.HamiltonianSystem, CTBase.Data.ComposedHamiltonian.
_build_pseudo_flow(
_::Val{:partial},
h̃,
law,
components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}Build the inner Hamiltonian flow for the :partial mode: wrap the pseudo-Hamiltonian and control law in a CTFlows.Systems.PseudoHamiltonianSystem (AD at fixed u).
See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Systems.PseudoHamiltonianSystem.
_build_pseudo_flow(
_::Val{ht},
h̃,
law,
components
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}Throw an CTBase.Exceptions.IncorrectArgument for an unknown hamiltonian_type value. Only :total and :partial are supported.
Throws
CTBase.Exceptions.IncorrectArgument: whenhtis not:totalor:partial.
See also: CTFlows.Flows._build_pseudo_flow.
_check_convenience_arities [Function]
CTFlows.Flows._check_convenience_arities Function
_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 (nothingor a rawFunction).cspec: theconstraintspec (nothing,Symbol,Function,Tuple, orCTBase.Data.PathConstraint).mspec: themultiplierspec (nothing,Function,Tuple, orCTBase.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
CTBase.Exceptions.IncorrectArgument: if at least one raw function has a single method and a mismatched arity, on a with-control OCP.
See also: CTFlows.Flows._arity_issue, CTFlows.Flows._spec_arity_issues!.
_constrained_pseudo_H [Function]
CTFlows.Flows._constrained_pseudo_H Function
_constrained_pseudo_H(
h::CTFlows.Flows.ConstrainedPseudoHamiltonianFunction,
t,
x,
p,
u,
v
) -> AnyCore 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
_control_of(
_::Nothing,
x,
v
) -> CTFlows.Flows.var"#_control_of##0#_control_of##1"Reconstruct the control along a trajectory as a callable t -> u(t).
Dispatched on the control law and the available data:
nothing→t -> Float64[](control-free OCP), for both the state(x, v)and the Hamiltonian(x, p, v)call shapes.a law with the state and costate projections
(x, p, v)→t -> law(t, x(t), p(t), v)(theDynClosedLoop/ Hamiltonian path, which uses the costate).a law with only the state projection
(x, v)→t -> u(t)viaCTFlows.Trajectories._controlled_u(theOpenLoop/ClosedLoopstate 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.
_control_of(
_::Nothing,
x,
p,
v
) -> CTFlows.Flows.var"#_control_of##2#_control_of##3"Control-free OCP with costate projection: returns t -> Float64[] (no control to reconstruct).
See also: CTFlows.Flows._control_of.
_control_of(
law,
x,
p,
v
) -> CTFlows.Flows.var"#_control_of##2#_control_of##3"DynClosedLoop law with costate: returns t -> law(t, x(t), p(t), v) (Hamiltonian path).
See also: CTFlows.Flows._control_of.
_control_of(
law,
x,
v
) -> CTFlows.Flows.var"#_control_of##0#_control_of##1"OpenLoop/ClosedLoop law with state only: returns t -> u(t) via CTFlows.Trajectories._controlled_u (state path, no costate).
See also: CTFlows.Flows._control_of, CTFlows.Trajectories._controlled_u.
_controlled_flow [Function]
CTFlows.Flows._controlled_flow Function
_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
_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 benothingfor Fixed systems).unsafe: Iftrue, bypass ODE solver retcode checking.
Returns
- The packaged solution (type varies by config type).
Notes
This is an internal function called by the trait-dispatch overloads of _invoke_flow. Users should call the public _invoke_flow function instead.
See also: CTFlows.Flows._invoke_flow, CTFlows.Integrators.build_problem, CommonSolve.solve, CTFlows.Trajectories.build_trajectory.
_dim_coerce [Function]
CTFlows.Flows._dim_coerce Function
_dim_coerce(
dim::Int64
) -> Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}Precomputed coercion from a declared dimension: only collapses a 1-D quantity to a scalar (accepting both a scalar and a length-1 vector), identity leaves n-D untouched.
_expected_arity [Function]
CTFlows.Flows._expected_arity Function
_expected_arity(ocp) -> Int64Natural 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
_finalize_vf(r, _::Number) -> AnyCollapse a length-1 result buffer to a scalar (1-D state convention).
_finalize_vf(r, _::Vector) -> AnyReturn the result buffer as-is for a Vector state — r already has this exact type (see CTFlows.Systems._buffer_like), so this is an identity, no-allocation path.
_finalize_vf(r, xs::AbstractVector) -> AnyReconstruct the result buffer in the state's own container type (e.g. Vector → SVector/MVector), mirroring Systems.OoPVFIpFinalizeRHS. The internal buffer r is always a plain Vector (see CTFlows.Systems._buffer_like); for an immutable state container this conversion is required for OrdinaryDiffEq's out-of-place type-constancy.
_finalize_vf(r, _::Matrix) -> AnyReturn the result buffer as-is for a batched Matrix state (each column an independent trajectory) — r already has this exact type (see CTFlows.Systems._buffer_like), so this is an identity, no-allocation path.
_finalize_vf(r, xs::AbstractMatrix) -> AnyReconstruct the result buffer in the state's own container type (e.g. Matrix → SMatrix/MMatrix) for a batched immutable-matrix state, for the same out-of-place type-constancy reason as the AbstractVector method above.
_flow_action_defs [Function]
CTFlows.Flows._flow_action_defs Function
_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_base_description [Function]
CTFlows.Flows._flow_base_description Function
_flow_base_description(
_::Type{CTBase.Traits.WithAD}
) -> Tuple{Symbol, Symbol, Symbol}Base method description for a flow plan, per AD trait. The device token (:cpu) is explicit: the flow registry is parameterized ([CPU, GPU]), so a device token is required — CTBase.Strategies.extract_global_parameter_from_method throws otherwise. The bare :cpu reproduces the pre-parameterization CPU behaviour exactly (SciML{CPU} metadata ≡ old).
See also: CTFlows.Flows._flow_base_description, CTFlows.Flows._available_flow_methods.
_flow_base_description(
_::Type{CTBase.Traits.WithoutAD}
) -> Tuple{Symbol, Symbol}Base method description for an AD-free flow plan: no :di backend token (no scalar Hamiltonian is differentiated), only the :sciml integrator and :cpu device.
See also: CTFlows.Flows._flow_base_description, CTFlows.Flows._available_flow_methods.
_flow_description [Function]
CTFlows.Flows._flow_description Function
_flow_description(
ad_trait,
method
) -> Union{Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol, Symbol}}Resolve the effective method description for a flow from its AD trait and an optional user method (a Symbol such as :gpu, or a token tuple). method === nothing yields the base (CPU) description; otherwise the tokens are completed against CTFlows.Flows._available_flow_methods.
_flow_families [Function]
CTFlows.Flows._flow_families Function
_flow_families(
_::Type{CTBase.Traits.WithAD}
) -> @NamedTuple{backend::DataType, integrator::DataType}Return the strategy families used for option routing in flow construction.
The returned NamedTuple maps family names to their abstract types, as expected by CTBase.Orchestration.route_all_options.
Returns
NamedTuple:(backend, integrator)mapped to their abstract types
Example
# 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_families(
_::Type{CTBase.Traits.WithoutAD}
) -> @NamedTuple{integrator::DataType}Strategy families for an AD-free flow: only the :sciml integrator (no :di backend, since no scalar Hamiltonian is differentiated).
_flow_families(
) -> @NamedTuple{backend::DataType, integrator::DataType}Back-compat alias: return the full (WithAD) strategy families — backend + integrator.
See also: CTFlows.Flows._flow_families.
_flow_from_controlled_vf [Function]
CTFlows.Flows._flow_from_controlled_vf Function
_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.
_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
_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, F} where F<:(CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD3, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}})), I1<:CTSolvers.Integrators.AbstractIntegrator}, CTFlows.Flows.OptimalControlFlow{TD, VD, CTFlows.Flows.Flow{TD1, VD1, D, S, I}, CTModels.Models.Model{TD2, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, DefinitionType, BuildExaModelType}, Nothing, CTFlows.Flows.StateFlow{TD3, CTBase.Traits.NonFixed, S1, I1}} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, TD1<:CTBase.Traits.TimeDependence, VD1<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD1, VD1, D}, I<:CTSolvers.Integrators.AbstractIntegrator, TD2<:CTBase.Traits.TimeDependence, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.Components.AbstractObjectiveModel, ConstraintsModelType<:CTModels.Components.AbstractConstraintsModel, DefinitionType<:CTModels.Components.AbstractDefinition, BuildExaModelType<:Union{Nothing, Function}, TD3<:CTBase.Traits.TimeDependence, S1<:(CTFlows.Systems.VectorFieldSystem{TD3, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace, F} where F<:(CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD3, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}})), I1<:CTSolvers.Integrators.AbstractIntegrator}}Build an OptimalControlFlow from a control-free OCP.
Constructs the OCP Hamiltonian, builds the Hamiltonian system with the chosen AD backend, and wraps the resulting flow together with the OCP reference.
See also: CTFlows.Flows.OptimalControlFlow, CTFlows.Flows.Flow, CTFlows.Flows._ocp_hamiltonian.
_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
_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
CTBase.Exceptions.IncorrectArgument: ifconstraintormultiplierhas a single method and a mismatched arity.
See also: CTFlows.Flows._build_pseudo_flow, CTFlows.Flows._ocp_pseudo_hamiltonian, CTFlows.Flows._check_convenience_arities.
_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
_flow_from_pseudo_hamiltonian(
::Type{CTBase.Traits.DynClosedLoopFeedback},
h̃::CTBase.Data.PseudoHamiltonian,
law::CTBase.Data.ControlLaw;
kwargs...
) -> Union{CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.HamiltonianSystem{TD, VD, H} where H<:(CTBase.Data.ComposedHamiltonian{TD, VD}))}, CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianSystem{TD, VD, PH} where PH<:(CTBase.Data.PseudoHamiltonian{<:Function, TD, VD}))}}Dispatch helper for CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw): build a Hamiltonian flow from a DynClosedLoop law, routing on the hamiltonian_type action option.
See also: CTFlows.Flows._build_pseudo_flow.
_flow_from_pseudo_hamiltonian(
::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
::CTBase.Data.PseudoHamiltonian,
::CTBase.Data.ControlLaw;
kwargs...
)Reject OpenLoop/ClosedLoop laws in CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw): a pseudo-Hamiltonian H̃(t,x,p,u,v) depends on the costate p, which OpenLoop/ClosedLoop laws do not provide.
See also: CTFlows.Flows.Flow(h̃::CTBase.Data.PseudoHamiltonian, law::CTBase.Data.ControlLaw).
_flow_from_pseudo_hamiltonian_vf [Function]
CTFlows.Flows._flow_from_pseudo_hamiltonian_vf Function
_flow_from_pseudo_hamiltonian_vf(
::Type{CTBase.Traits.DynClosedLoopFeedback},
h̃vf::CTBase.Data.PseudoHamiltonianVectorField,
law::CTBase.Data.ControlLaw;
opts...
) -> CTFlows.Flows.HamiltonianFlow{TD, VD, S} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, S<:(CTFlows.Systems.PseudoHamiltonianVectorFieldSystem{F, TD, VD} where F<:Function)}Dispatch helper for CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw): build a PseudoHamiltonianVectorFieldSystem-backed Hamiltonian flow from a DynClosedLoop law.
See also: CTFlows.Systems.build_system.
_flow_from_pseudo_hamiltonian_vf(
::Type{<:Union{CTBase.Traits.ClosedLoopFeedback, CTBase.Traits.OpenLoopFeedback}},
::CTBase.Data.PseudoHamiltonianVectorField,
::CTBase.Data.ControlLaw;
opts...
)Reject OpenLoop/ClosedLoop laws in CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw): a pseudo-Hamiltonian vector field h̃vf(t,x,p,u,v) depends on the costate p, which OpenLoop/ClosedLoop laws do not provide.
See also: CTFlows.Flows.Flow(h̃vf::CTBase.Data.PseudoHamiltonianVectorField, law::CTBase.Data.ControlLaw).
_flow_objective [Function]
CTFlows.Flows._flow_objective Function
_flow_objective(ocp, x, u, v, t0, tf, integ) -> AnyCompute the objective value (Mayer + Lagrange) of an OCP along a trajectory, given callable state x(t) and control u(t) and the variable v.
The Mayer term is evaluated at the endpoints x(t0) and x(tf). The Lagrange term is integrated by flowing ℓ̇(t) = ℓ(t, x(t), u(t), v) from t0 to tf on a scalar cost state: under the "1-D = scalar" convention the out-of-place right-hand side is wrapped in an IPVFOoPRHS, and that wrapper — not the state — supplies SciML's mutable in-place buffer. Shared core of both the Hamiltonian (OptimalControlFlow) and state (ControlledFlow) objective paths; each caller builds its own x, u, v and delegates here.
See also: CTFlows.Flows._control_of, CTFlows.Flows._build_ocp_solution, CTFlows.Flows._state_flow_objective.
_flow_state_coerce [Function]
CTFlows.Flows._flow_state_coerce Function
_flow_state_coerce(
ocp,
_::AbstractMatrix
) -> typeof(identity)Precomputed state coercion (only for a 1-D state, identity otherwise) from the OCP's declared state dimension. Unlike CTFlows.Flows._dim_coerce alone, this also special-cases a batched Matrix x0 to always return identity, regardless of the declared dimension — _dim_coerce is baked in from the OCP's declared dimension and cannot see x0's runtime shape by itself. Fixing it here (the single source of coerce) covers every later application of the returned function, including inside CTFlows.Trajectories.StateFlowTrajectory.
_flow_state_coerce(ocp, x0) -> typeof(identity)State coercion from the OCP's declared state dimension for a non-batched x0: only for a 1-D state, identity otherwise.
See also: CTFlows.Flows._flow_state_coerce, CTFlows.Flows._dim_coerce.
_flow_state_coerce(
_::Nothing,
_::AbstractMatrix
) -> typeof(identity)Precomputed state coercion (only for a 1-D state, identity otherwise) inferred from x0 when there is no OCP (Flow(fc, law)); a batched Matrix x0 always yields identity — see CTFlows.Flows._flow_state_coerce.
_flow_state_coerce(_::Nothing, x0) -> typeof(identity)Precomputed state coercion (only for a 1-D state, identity otherwise) inferred from x0 when there is no OCP (Flow(fc, law)): a Matrix x0 always yields identity (see CTFlows.Flows._flow_state_coerce).
See also: CTFlows.Flows._flow_state_coerce, CTFlows.Flows._dim_coerce.
_invoke_flow [Function]
CTFlows.Flows._invoke_flow Function
_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)
- Whether the
variableparameter was provided (NotProvidedvs any other type)
Dispatch Rules
Fixed+NotProvided: Variable not required, proceeds withvariable=nothing.Fixed+ provided: ThrowsPreconditionError(Fixed systems must not receive a variable).NonFixed+ provided: Variable required, proceeds with the provided value.NonFixed+NotProvided: ThrowsPreconditionError(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: Iftrue, bypass ODE solver retcode checking; iffalse, throwSolverFailureon 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
# 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 providedSee also: CTFlows.Flows.AbstractFlow, CTBase.Traits.VariableDependence, CTBase.Core.NotProvided, CTFlows.Integrators.build_problem, CommonSolve.solve, CTFlows.Trajectories.build_trajectory.
_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.
_invoke_flow(
::Type{CTBase.Traits.Fixed},
::Type{CTBase.Core.NotProvidedType},
flow,
config;
unsafe,
variable
)Dispatch for Fixed flows when the variable parameter was not provided.
This overload is selected when a Fixed flow (which does not require a variable) is called without providing the variable argument. This is the expected and valid case, so it forwards to _core_invoke_flow with variable=nothing.
Returns
- The result of
_core_invoke_flow.
See also
CTBase.Traits.Fixed, CTBase.Core.NotProvided, CTFlows.Flows._core_invoke_flow.
_invoke_flow(
::Type{CTBase.Traits.NonFixed},
::Type{VT},
flow,
config;
unsafe,
variable
)Dispatch for NonFixed flows when a variable parameter is provided.
This overload is selected when a NonFixed flow (which requires a variable) is called with a provided variable parameter. This is the expected and valid case, so it forwards to _core_invoke_flow with the provided variable value.
Returns
- The result of
_core_invoke_flow.
See also
CTBase.Traits.NonFixed, CTFlows.Flows._core_invoke_flow.
_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
_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
CTBase.Exceptions.PreconditionError: Always.
_invoke_flow_variable_costate [Function]
CTFlows.Flows._invoke_flow_variable_costate Function
_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: Iftrue, 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.
_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.
_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: Iftrue, bypass ODE solver retcode checking.
Returns
Tuple{AbstractVector, AbstractVector, AbstractVector}: The augmented solution(xf, pf, pvf).
See also: CTBase.Traits.SupportsVariableCostate, CTFlows.Configs.AugmentedHamiltonianEndPointConfig.
_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.
_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.
_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
CTBase.Exceptions.PreconditionError: Always.
_natural_syntax [Function]
CTFlows.Flows._natural_syntax Function
_natural_syntax(
label::AbstractString,
second::AbstractString,
ocp
) -> StringNatural-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
_ocp_H(
h::CTFlows.Flows.OCPHamiltonianFunction,
t,
x,
p,
v
) -> AnyCore 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
_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
_ocp_controlled_vector_field(
ocp
) -> Union{CTBase.Data.ControlledVectorField{CTFlows.Flows.OCPControlledVectorFieldFunction{TD, VD, DF, CX, CU, CV}, TD1, CTBase.Traits.Fixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}, CTBase.Data.ControlledVectorField{CTFlows.Flows.OCPControlledVectorFieldFunction{TD, VD, DF, CX, CU, CV}, TD1, CTBase.Traits.NonFixed} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CU<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}}Build an CTFlows.Flows.OCPControlledVectorFieldFunction from an OCP and wrap it in a CTBase.Data.ControlledVectorField.
See also: CTFlows.Flows.OCPControlledVectorFieldFunction, CTFlows.Flows._ocp_pseudo_hamiltonian.
_ocp_controlled_vf [Function]
CTFlows.Flows._ocp_controlled_vf Function
_ocp_controlled_vf(
h::CTFlows.Flows.OCPControlledVectorFieldFunction,
t,
x,
u,
v
) -> AnyCore computation of the OCP controlled dynamics fc(t,x,u,v): coerce x/u/v with the precomputed per-dimension coercions (scalar for 1-D; a batched Matrix is always left untouched via CTFlows.Flows._apply_dim_coerce), fill a buffer with the in-place dynamics (n_x × batch for a Matrix state — see CTFlows.Systems._buffer_like), and return it (scalar for a 1-D state).
_ocp_hamiltonian [Function]
CTFlows.Flows._ocp_hamiltonian Function
_ocp_hamiltonian(ocp) -> CTBase.Data.HamiltonianBuild 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
_ocp_pseudo_H(
h::CTFlows.Flows.OCPPseudoHamiltonianFunction,
t,
x,
p,
u,
v
) -> AnyCore 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
_ocp_pseudo_hamiltonian(
ocp
) -> CTBase.Data.PseudoHamiltonianBuild 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
_ocp_state_vector_field(
ocp
) -> Union{CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD1, CTBase.Traits.Fixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}, CTBase.Data.VectorField{CTFlows.Flows.OCPStateVectorFieldFunction{TD, VD, DF, CX, CV}, TD1, CTBase.Traits.NonFixed, CTBase.Traits.OutOfPlace} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, DF<:Function, CX<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, CV<:Union{typeof(identity), typeof(CTFlows.Systems._safe_only)}, TD1<:CTBase.Traits.TimeDependence}}Build an CTFlows.Flows.OCPStateVectorFieldFunction from a control-free OCP and wrap it in a CTBase.Data.VectorField (out-of-place).
See also: CTFlows.Flows.OCPStateVectorFieldFunction, CTFlows.Flows._ocp_controlled_vector_field.
_ocp_state_vf [Function]
CTFlows.Flows._ocp_state_vf Function
_ocp_state_vf(
h::CTFlows.Flows.OCPStateVectorFieldFunction,
t,
x,
v
) -> AnyCore computation of the control-free OCP state dynamics g(t,x,v) = f(t,x,∅,v): coerce x/v with the precomputed per-dimension coercions (scalar for 1-D; a batched Matrix is always left untouched via CTFlows.Flows._apply_dim_coerce), fill a buffer with the in-place dynamics called with an empty control (n_x × batch for a Matrix state), and return it (scalar for a 1-D state).
See also: CTFlows.Flows.OCPStateVectorFieldFunction.
_pop_method [Function]
CTFlows.Flows._pop_method Function
_pop_method(kwargs) -> Tuple{Any, NamedTuple}Split a flow constructor's keyword arguments into (method, rest): the device selection (method=:gpu, a Symbol or token tuple; nothing if absent) and the remaining strategy options. method rides along in every constructor's kwargs... and is popped here, at the routing boundary, so it is never mistaken for a strategy option.
See also: CTFlows.Flows._flow_description, CTFlows.Flows._route_flow_options.
_reject_control_free_constraint [Function]
CTFlows.Flows._reject_control_free_constraint Function
_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
_require_state_flow(
F::CTFlows.Flows.OptimalControlFlow
) -> AnyReturn 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
_resolve_constraint(
ocp,
spec::Symbol
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:FunctionResolve a constraint specification into a CTBase.Data.PathConstraint.
spec::Symbolis a:pathconstraint label: resolved viaCTModels.Models.constraint, which returns an out-of-placeg(t,x,u,v). Rejected withCTBase.Exceptions.IncorrectArgumentif the label is not a:pathconstraint (e.g.:boundaryor a box constraint). The functor is wrapped as a non-autonomous, non-fixedCTBase.Data.MixedConstraintso its uniform callg(t,x,u,v)forwards verbatim to the resolved functor.spec::CTBase.Data.PathConstraintis used as-is.spec::Functionis a raw function with the OCP's natural arity ((x,u),(t,x,u),(x,u,v)or(t,x,u,v)), wrapped in aCTBase.Data.MixedConstraintwith the OCP's time/variable dependence.spec::Tupleis a non-empty tuple of simultaneous constraints, each resolved recursively and wrapped in aCTFlows.Flows._CombinedConstraint(empty tuple rejected withCTBase.Exceptions.IncorrectArgument).
See also: CTFlows.Flows._resolve_multiplier, CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.
_resolve_constraint(
_,
spec::CTBase.Data.PathConstraint
) -> CTBase.Data.PathConstraintReturn a PathConstraint spec as-is — it is already a resolved CTBase.Data.PathConstraint.
See also: CTFlows.Flows._resolve_constraint, CTBase.Data.PathConstraint.
_resolve_constraint(
ocp,
spec::Function
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:FunctionResolve a Function constraint spec into a CTBase.Data.MixedConstraint, inferring autonomy and variable-dependence from the OCP.
See also: CTFlows.Flows._resolve_constraint, CTBase.Data.MixedConstraint.
_resolve_constraint(
ocp,
spec::Tuple
) -> CTFlows.Flows._CombinedConstraintResolve a Tuple of constraint specs into a CTFlows.Flows._CombinedConstraint, rejecting an empty tuple with CTBase.Exceptions.IncorrectArgument.
Throws
CTBase.Exceptions.IncorrectArgument: whenspecis an empty tuple.
See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._CombinedConstraint.
_resolve_constraint(
_,
spec
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:FunctionThrow an CTBase.Exceptions.IncorrectArgument for an unsupported constraint spec type. Only Symbol (path label), Function, Tuple, and CTBase.Data.PathConstraint are accepted.
Throws
CTBase.Exceptions.IncorrectArgument: whenspecis not a supported type.
See also: CTFlows.Flows._resolve_constraint.
_resolve_multiplier [Function]
CTFlows.Flows._resolve_multiplier Function
_resolve_multiplier(
_,
spec::CTBase.Data.Multiplier
) -> CTBase.Data.MultiplierResolve a multiplier specification into a CTBase.Data.Multiplier.
spec::CTBase.Data.Multiplieris used as-is.spec::Functionis a raw function with the OCP's natural arity ((x,p),(t,x,p),(x,p,v)or(t,x,p,v)), wrapped in aCTBase.Data.Multiplierwith the OCP's time/variable dependence.spec::Tupleis a non-empty tuple of multipliers, each resolved recursively and wrapped in aCTFlows.Flows._CombinedMultiplier— matched element-wise with the constraint tuple (empty tuple rejected withCTBase.Exceptions.IncorrectArgument).
See also: CTFlows.Flows._resolve_constraint, CTFlows.Flows._ocp_constrained_pseudo_hamiltonian.
_resolve_multiplier(
ocp,
spec::Function
) -> CTBase.Data.MultiplierResolve a Function multiplier spec into a CTBase.Data.Multiplier, inferring autonomy and variable-dependence from the OCP.
See also: CTFlows.Flows._resolve_multiplier, CTBase.Data.Multiplier.
_resolve_multiplier(
ocp,
spec::Tuple
) -> CTFlows.Flows._CombinedMultiplierResolve a Tuple of multiplier specs into a CTFlows.Flows._CombinedMultiplier, rejecting an empty tuple with CTBase.Exceptions.IncorrectArgument.
Throws
CTBase.Exceptions.IncorrectArgument: whenspecis an empty tuple.
See also: CTFlows.Flows._resolve_multiplier, CTFlows.Flows._CombinedMultiplier.
_resolve_multiplier(_, spec) -> CTBase.Data.MultiplierThrow an CTBase.Exceptions.IncorrectArgument for an unsupported multiplier spec type. Only Function, Tuple, and CTBase.Data.Multiplier are accepted.
Throws
CTBase.Exceptions.IncorrectArgument: whenspecis not a supported type.
See also: CTFlows.Flows._resolve_multiplier.
_route_flow_options [Function]
CTFlows.Flows._route_flow_options Function
_route_flow_options(
ad_trait,
kwargs;
method,
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'sFlowcall (strategy options only, no action-level options).
Returns
NamedTuplewith fields:action: action-level options (always empty for flows)strategies:NamedTuplewithbackendandintegratorsub-tuples
Throws
CTBase.Exceptions.IncorrectArgument: If an option is unknown, ambiguous, or routed to the wrong strategy.
Example
# 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
:descriptionsource mode for user-friendly error messages.No action-level options are defined for flows (empty
OptionDefinitionarray).
See also: CTFlows.Flows._flow_families, CTFlows.Flows._build_flow_components, CTBase.Orchestration.route_all_options
_route_flow_options(
kwargs;
action_defs
) -> NamedTuple{(:action, :strategies), <:Tuple{NamedTuple, NamedTuple}}Back-compat alias: route options using the WithAD plan (the full :di/:sciml families).
See also: CTFlows.Flows._route_flow_options.
_spec_arity_issues! [Function]
CTFlows.Flows._spec_arity_issues! Function
_spec_arity_issues!(
issues,
ocp,
_::Nothing,
label,
second,
kind
)No arity issues for a nothing spec — skip the check.
See also: CTFlows.Flows._spec_arity_issues!.
_spec_arity_issues!(
issues,
ocp,
spec::Function,
label::AbstractString,
second::AbstractString,
kind::AbstractString
)Check the arity of a single Function spec against the OCP's expected arity and push an issue string into issues if they differ.
See also: CTFlows.Flows._check_convenience_arities, CTFlows.Flows._arity_issue.
_spec_arity_issues!(
issues,
ocp,
spec::Tuple,
label::AbstractString,
second::AbstractString,
kind::AbstractString
)Check the arity of each Function element in a Tuple spec against the OCP's expected arity, pushing an issue string per mismatch into issues. Non-Function elements are skipped.
See also: CTFlows.Flows._check_convenience_arities, CTFlows.Flows._arity_issue.
_spec_arity_issues!(issues, ocp, spec, label, second, kind)Fallback for an already-resolved spec (not a Function or Tuple): no arity check needed.
See also: CTFlows.Flows._check_convenience_arities.
_state_flow_objective [Function]
CTFlows.Flows._state_flow_objective Function
_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)).
_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
_unwrap_option(
opt::CTBase.Options.OptionValue,
fallback
) -> AnyRead 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.
_unwrap_option(opt, fallback) -> AnyReturn opt directly when it is not nothing, or fallback otherwise.
See also: CTFlows.Flows._unwrap_option, CTFlows.Flows._route_flow_options.
_validate_constraint_pair [Function]
CTFlows.Flows._validate_constraint_pair Function
_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
CTBase.Exceptions.IncorrectArgument: if exactly one of the two is given; if one is a tuple and the other is not; or if the two tuples have different lengths.
See also: CTFlows.Flows._build_ocp_pseudo_flow, CTFlows.Flows._CombinedConstraint.
_variable_vector [Function]
CTFlows.Flows._variable_vector Function
_variable_vector(
_::CTBase.Core.NotProvidedType
) -> Vector{Float64}Convert a variable argument into a Vector{Float64}.
Returns an empty vector when the variable was not provided (Core.NotProvided), a 1-element vector for scalars, and a copy for vectors.
See also: _build_ocp_solution, CTFlows.Flows._flow_objective.
_variable_vector(v::Number) -> VectorWrap a scalar variable into a 1-element Vector{Float64}.
See also: CTFlows.Flows._variable_vector.
_variable_vector(v::AbstractVector) -> AnyCopy a vector variable into a Vector{Float64}.
See also: CTFlows.Flows._variable_vector.
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
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.
print_field [Function]
CTFlows.Display.print_field Function
print_field(io::IO, label, value; last, fmt, value_style)Print one tree branch ├─ label: value (or └─ when last) on its own line.
A leading newline is emitted so the caller prints the header first, then a sequence of fields; no trailing newline is emitted, keeping the standard "no newline after the last field" REPL convention. The branch character and label use the muted/label roles; the value uses value_style (the value role by default). Pass value_style = "" to leave the value unstyled.
When value renders on several lines (e.g. a nested object whose own show is multi-line), continuation lines are indented under the branch character and prefixed with a │ pipe (blanks when last). value is rendered through print (so strings/symbols keep their plain form and objects use their own show), preserving colour from io.
print_fields [Function]
CTFlows.Display.print_fields Function
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.
print_header [Function]
CTFlows.Display.print_header Function
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
struct ControlledStateProjection{T<:CTFlows.Trajectories.VectorFieldTrajectory, C} <: FunctionCallable 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
_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 dimensionn_x = n_p.
Returns
Tuple{AbstractVector, AbstractVector, AbstractVector}: Tuple(x, p, pv).
Notes
Internal helper used by
build_trajectoryforAugmentedHamiltonianEndPointConfig.Assumes
n_p = n_xinvariant for Hamiltonian systems.
_build_control_proj [Function]
CTFlows.Trajectories._build_control_proj Function
_build_control_proj(_::Nothing, traj, variable, coerce)No control projection when there is no control law (a basic control-free Flow(ocp)).
_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
_controlled_u(
law::CTBase.Data.ControlLaw{<:Function, CTBase.Traits.OpenLoopFeedback},
t,
x,
v
) -> AnyReconstruct the control from an OpenLoop law: u(t, v) (the state is ignored).
_controlled_u(
law::CTBase.Data.ControlLaw{<:Function, CTBase.Traits.ClosedLoopFeedback},
t,
x,
v
) -> AnyReconstruct the control from a ClosedLoop law: u(t, x, v).
_controlled_u(
pl::CTFlows.MultiPhase._PiecewiseControlLaw,
t,
x,
v
) -> AnyState (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 (orCore.NotProvided).
Returns
- The control of the phase active at
t, reconstructed by the feedback-dispatched call.
_cp_variable [Function]
CTFlows.Trajectories._cp_variable Function
_cp_variable(v) -> AnyUnwrap 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
_ham_split_solution(u::AbstractVector, x0::Number) = (_safe_only(u[1:1]), _safe_only(u[2:2]))
_ham_split_solution(u::AbstractVector, x0::AbstractVector) = (u[1:n], u[n+1:2n])
_ham_split_solution(u::AbstractMatrix, x0::AbstractMatrix) = (u[1:n, :], u[n+1:2n, :])Split a combined state vector into state and costate components, preserving the shape of x0.
For scalar x0, extracts single elements and coerces them back to scalars (via the GPU-safe CTFlows.Systems._safe_only, consistent with every other 1-D=scalar split path). For vector/matrix x0, extracts views of the appropriate size.
_ham_split_solution(
u::AbstractVector,
x0::AbstractVector
) -> Tuple{Any, Any}Split a combined state–costate vector into two sub-vectors, using length(x0) as the state dimension n.
Returns
(u[1:n], u[(n+1):2n]): state and costate sub-vectors.
_ham_split_solution(
u::AbstractMatrix,
x0::AbstractMatrix
) -> Tuple{Any, Any}Split a combined state–costate matrix into two sub-matrices (column-wise), using size(x0, 1) as the state dimension n.
Returns
(u[1:n, :], u[(n+1):2n, :]): state and costate sub-matrices.
_sft_control [Function]
CTFlows.Trajectories._sft_control Function
_sft_control(
cp::CTFlows.Trajectories.ControlProjection
) -> CTFlows.Trajectories.ControlProjectionReturn 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.
_sft_control(_::Nothing)Throw a PreconditionError because the StateFlowTrajectory has no control projection (cp === nothing, a basic control-free Flow(ocp)).
This happens when the flow was built without a control law (e.g. for direct shooting), so there is no control to reconstruct.
_show_variable [Function]
CTFlows.Trajectories._show_variable Function
_show_variable(v) -> BoolReturn 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).