Private API
This page lists non-exported (internal) symbols of CTFlowsSciMLFlows, CTFlowsPlots, CTFlows.MultiPhase, CTFlowsStaticArrays, CTFlows.TrajectoryPlots, CTFlows.Systems, CTFlowsSciMLIntegrator, CTFlows.Flows, CTFlowsMakie, CTFlows.Configs, CTFlows.Display, CTFlows.Integrators, CTFlows.Trajectories.
From CTFlowsSciMLFlows
IPSciMLIpRHS [Struct]
CTFlowsSciMLFlows.IPSciMLIpRHS Type
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).label::String: The label of the phase the flow integrates (""for no label), seeCTFlows.Flows.label.
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.
_check_problem_saveat [Function]
CTFlowsSciMLFlows._check_problem_saveat Function
_check_problem_saveat(prob, config)Reject an output grid given at the call when the wrapped problem stores its own saveat.
Throws
CTBase.Exceptions.IncorrectArgument: If a grid is given andprob.kwargshassaveat.
_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 CTFlowsPlots
_plot [Function]
CTFlowsPlots._plot Function
_plot(sol, description::Symbol...; size, kwargs...) -> AnyInternal implementation of Plots.plot for the CTFlows trajectory types.
Builds the figure with CTFlows.TrajectoryPlots.build_figure (which owns the user-facing defaults and throws on an empty description) and renders it via CTBase.Plotting.render on the Plots backend. Returns a Plots.Plot.
_plot! [Function]
CTFlowsPlots._plot! Function
_plot!(
p::Plots.Plot,
sol,
description::Symbol...;
kwargs...
) -> Plots.PlotInternal implementation of Plots.plot! for the CTFlows trajectory types: build the figure with CTFlows.TrajectoryPlots.build_figure and overlay it onto the existing plot p via CTBase.Plotting.render! (Plots backend).
From CTFlows.MultiPhase
_PiecewiseControlLaw [Struct]
CTFlows.MultiPhase._PiecewiseControlLaw Type
struct _PiecewiseControlLaw{L, S}Piecewise control law reconstructed from the per-phase laws of a multi-phase flow. It selects the phase by time (a flat searchsortedfirst over the switching times — no nested closures), then delegates to that phase's law with the caller's uniform signature. It serves both reconstruction paths: (pl)(t, x, p, v) for the Hamiltonian/OCP law, and CTFlows.Trajectories._controlled_u(pl, t, x, v) for the state (controlled) law.
At an exact switching time tᵢ the phase that ends at tᵢ is selected, consistently with the state and costate, which are left-continuous: u(tᵢ) is the left limit, computed from the values before the jump. The right limit, the next phase's law evaluated after the jump, is given by CTFlows.MultiPhase._right_law.
Type Parameters
L: type of the tuple of per-phase control laws.S: type of the switching-times vector.
Fields
laws::L: tuple of the per-phase control laws (each 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_phase_grids [Function]
CTFlows.MultiPhase._check_phase_grids Function
_check_phase_grids(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
config
)Reject a generated grid (grid=) when a phase integrator sets saveat. A grid of times is checked by each phase flow on its sub-grid.
_check_switching_times_order [Function]
CTFlows.MultiPhase._check_switching_times_order Function
_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,
config::CTFlows.Configs.AbstractTrajectoryConfig;
variable,
unsafe
)Evaluate a single phase for a state flow with trajectory configuration.
Dispatches on the abstract dynamics axis (AbstractStateFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.
Arguments
flow::Flows.AbstractStateFlow: The state (or decorated state) flow to evaluate.t0: Start time.tf: End time.x: Initial state.::Configs.AbstractTrajectoryConfig: Trajectory configuration type tag.variable: The variable parameter value (for NonFixed systems).unsafe: If true, bypass ODE solver retcode checking.
Returns
- Trajectory solution from t0 to tf.
See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.StateFlow.
_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,
config::CTFlows.Configs.AbstractTrajectoryConfig;
variable,
unsafe
)Evaluate a single phase for a Hamiltonian flow with trajectory configuration.
Dispatches on the abstract dynamics axis (AbstractHamiltonianFlow) and unwraps decorator flows via CTFlows.MultiPhase._raw_flow before integrating.
Arguments
flow::Flows.AbstractHamiltonianFlow: The Hamiltonian (or decorated Hamiltonian) flow to evaluate.t0: Start time.tf: End time.state_tuple: Tuple of (initial_state, initial_costate).::Configs.AbstractTrajectoryConfig: Trajectory configuration type tag.variable: The variable parameter value (for NonFixed systems).unsafe: If true, bypass ODE solver retcode checking.
Returns
- Trajectory solution from t0 to tf.
See also: CTFlows.MultiPhase._raw_flow, CTFlows.Flows.HamiltonianFlow.
_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
) -> Any
_finalize_multiphase_trajectory(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
merged,
variable,
grid
) -> Any
_finalize_multiphase_trajectory(
mpf::CTFlows.MultiPhase.MultiPhaseFlow,
merged,
variable,
grid,
bounds
) -> 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
- Tuple of
(state, costate).
Notes
This is an internal dispatch method for the _format_final_output function.
_merge_switching_times [Function]
CTFlows.MultiPhase._merge_switching_times Function
_merge_switching_times(f1, t_switch, f2) -> VectorMerge the switching times of two flows and a new switching time into a concrete vector.
_multiphase_display_name [Function]
CTFlows.MultiPhase._multiphase_display_name Function
Return a human-readable display name for a MultiPhaseFlow, dispatching on the dynamics trait.
StateDynamics→"MultiPhaseStateFlow"HamiltonianDynamics→"MultiPhaseHamiltonianFlow"Fallback →
string(nameof(typeof(mpf)))
See also: CTFlows.MultiPhase.MultiPhaseFlow.
_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 searchsortedfirst over the switching times, clamped to the valid phase range. At a switching time, it is the law of the phase that ends there (left continuity).
Arguments
pl::_PiecewiseControlLaw: The piecewise control law.t: The time at which to select the active phase.
Returns
- The per-phase control law active at time
t.
_phase_times [Function]
CTFlows.MultiPhase._phase_times Function
_phase_times(
t0,
tf,
_::Union{Nothing, CTFlows.Configs.AbstractGrid}
) -> Tuple{Any, Any}Time specification of a phase [t0, tf] when no output grid is imposed at the call: the phase's time span.
_phase_times(t0, tf, grid::AbstractVector) -> AnyTime specification of a phase [t0, tf] under an output grid imposed at the call: the grid times strictly inside the phase, framed by the phase bounds (a switching time thus closes one phase and opens the next, as without a grid).
_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}}
_reconstruct_controlled_trajectory(
mpf,
merged,
variable,
grid
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}
_reconstruct_controlled_trajectory(
mpf,
merged,
variable,
grid,
bounds
) -> Union{CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(identity), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(identity)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(identity)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}, CTFlows.Trajectories.StateFlowTrajectory{CTFlows.Trajectories.VectorFieldTrajectory{R, V, X0}, CTFlows.MultiPhase._PiecewiseControlLaw{_A, S}, _A1, _B, typeof(CTFlows.Systems._safe_only), _C, CTFlows.Trajectories.ControlledStateProjection{T, typeof(CTFlows.Systems._safe_only)}, CTFlows.Trajectories.ControlProjection{T1, L, _A2, typeof(CTFlows.Systems._safe_only)}} where {R<:CTSolvers.Integrators.AbstractIntegrationResult, V, X0, _A, S<:(Vector{<:Real}), _A1, _B, _C, T<:CTFlows.Trajectories.VectorFieldTrajectory, T1<:CTFlows.Trajectories.VectorFieldTrajectory, L<:(CTFlows.MultiPhase._PiecewiseControlLaw{_A, S} where {_A, S}), _A2}}Rebuild a CTFlows.Trajectories.StateFlowTrajectory from an all-ControlledFlow multi-phase trajectory, reconstructing the control as a CTFlows.MultiPhase._PiecewiseControlLaw and recomputing the objective (Mayer + Lagrange) over the merged trajectory when the phases carry an OCP (nothing objective for Flow(fc, law) phases).
Arguments
mpf: The multi-phase state flow.merged: The merged state trajectory over all phases.variable: The variable parameter value (for NonFixed systems).
Returns
- 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
) -> Union{CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{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}, CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.SwitchingModel} 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}}
_reconstruct_ocp_solution(
mpf,
merged,
variable,
grid
) -> Union{CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{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}, CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.SwitchingModel} 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}}
_reconstruct_ocp_solution(
mpf,
merged,
variable,
grid,
bounds
) -> Union{CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{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}, CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.SwitchingModel} 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.
_regrid_raw [Function]
CTFlows.MultiPhase._regrid_raw Function
_regrid_raw(
merged,
grid,
bounds
) -> CTFlows.Trajectories.VectorFieldTrajectoryRegrid a raw merged trajectory (no control law) on a generated grid, whose plotted curves are the state (and the costate); unchanged otherwise.
_reshape_to_x0 [Function]
CTFlows.MultiPhase._reshape_to_x0 Function
_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.
_right_law [Function]
CTFlows.MultiPhase._right_law Function
_right_law(
pl::CTFlows.MultiPhase._PiecewiseControlLaw,
i::Integer
) -> AnyReturn the law of the phase that starts at the i-th switching time: the law that gives the right limit of the control there.
_shared_ocp [Function]
CTFlows.MultiPhase._shared_ocp Function
_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.
_switching_time_eltype [Function]
CTFlows.MultiPhase._switching_time_eltype Function
_switching_time_eltype(
_::Type{Real},
_::Type{B},
_::Type{Real}
) -> TypeReturn the concrete common element type for switching times from two flows and a new time.
The empty switching-time vector returned by a single-phase flow has element type Real, so vcat alone would promote a concrete switching-time vector to Vector{Real}.
From CTFlows.TrajectoryPlots
_BUILD_KEYS [Constant]
CTFlows.TrajectoryPlots._BUILD_KEYS Constant
Keyword-argument names consumed by build_figure; every other keyword a user passes to plot(sol; …) is forwarded to the CTBase.Plotting rendering backend.
_SWITCHING_STYLE [Constant]
CTFlows.TrajectoryPlots._SWITCHING_STYLE Constant
Default style of the vertical lines at the switching times: dashed black lines behind the curves, as the initial/final time markers of a CTModels.Solution plot.
_assemble [Function]
CTFlows.TrajectoryPlots._assemble Function
_assemble(
sol,
panels,
placement;
layout,
time,
vlines,
annotations
)Lower each panel and assemble the CTBase.Plotting layout tree from (layout, placement):
:group→ one cell per panel, laid out in a horizontal row;:split,:paired→ one column per panel (components stacked), columns side by side (e.g. state | costate) when they have equal heights;:split,:stacked→ all component cells in a single vertical column.
vlines are drawn in every cell; annotations[k] are the texts of the k-th panel. A lone panel needs no combinator. An invalid layout / time is reported by CTBase.Plotting.lower as a CTBase.Exceptions.IncorrectArgument.
_check_jumps [Function]
CTFlows.TrajectoryPlots._check_jumps Function
_check_jumps(jumps::Symbol)Check the drawing of the jumps: :segment or :none.
Throws
CTBase.Exceptions.IncorrectArgument: for any other value.
_check_phase_labels [Function]
CTFlows.TrajectoryPlots._check_phase_labels Function
_check_phase_labels(phase_labels::Symbol)Check the placement of the phase labels: :control, :all or :none.
Throws
CTBase.Exceptions.IncorrectArgument: for any other value.
_control_name [Function]
CTFlows.TrajectoryPlots._control_name Function
_control_name(sol) -> StringName of the control as a whole (for the label of its norm): from the OCP model, else "u".
_control_names [Function]
CTFlows.TrajectoryPlots._control_names Function
_control_names(sol, m) -> AnyNames of the m control components: from the OCP model when the trajectory carries one, else generated (u, u₁, …).
_control_panel [Function]
CTFlows.TrajectoryPlots._control_panel Function
_control_panel(
sol,
ts,
control::Symbol,
style::NamedTuple;
connect
) -> CTBase.Plotting.PanelThe control panel: control(sol) sampled at ts, drawn as its components (control=:components), its norm (:norm) or both (:all).
Throws
CTBase.Exceptions.IncorrectArgument: for any other value ofcontrol.
_control_shown [Function]
CTFlows.TrajectoryPlots._control_shown Function
_control_shown(description, control_style) -> BoolReturn whether the control panel is drawn: :control is in the description and the control is not styled :none.
_costate_panel [Function]
CTFlows.TrajectoryPlots._costate_panel Function
_costate_panel(
sol,
ts,
style::NamedTuple;
state_shown,
connect
)The costate panel: costate(sol) sampled at ts. When the state is drawn alongside (paired columns), the state labels name the rows, so the costate curves carry no label, as in CTModels.
_default_description [Function]
CTFlows.TrajectoryPlots._default_description Function
_default_description(
_::CTFlows.Trajectories.AbstractVectorFieldTrajectory
) -> Tuple{Symbol, Symbol}Contract: the default panels for a trajectory when the user gives no description. Defined on the abstract trajectory types and specialized where a subtype exposes more (a StateFlowTrajectory also has a control).
AbstractVectorFieldTrajectory→(:state,)StateFlowTrajectory→(:state, :control)AbstractHamiltonianVectorFieldTrajectory→(:state, :costate)
_gen_names [Function]
CTFlows.TrajectoryPlots._gen_names Function
_gen_names(sym::AbstractString, n::Integer) -> AnyGenerated component names, used when the trajectory carries no model: ["x"] for one component, ["x₁", "x₂", …] otherwise.
_limits [Function]
CTFlows.TrajectoryPlots._limits Function
_limits(sol, component::Symbol) -> Tuple{Any, Any}Return the limits of component at the switching times of sol as the (left, right) matrices of CTBase.Plotting.splice_jumps: one row per switching time, one column per component. They are read with CTFlows.Trajectories.left_limit and CTFlows.Trajectories.right_limit.
_nothing_to_plot [Function]
CTFlows.TrajectoryPlots._nothing_to_plot Function
_nothing_to_plot()Throw a CTBase.Exceptions.IncorrectArgument for the empty case: an empty description, or every drawn group styled :none, leaves nothing to plot.
_panels [Function]
CTFlows.TrajectoryPlots._panels Function
_panels(
sol,
description;
control,
state_style,
costate_style,
control_style,
connect
)Turn a trajectory and a cleaned description into (times, panels, placement). Panels are emitted in the canonical order state → costate → control; a group whose style is :none is skipped. placement is :paired when both state and costate are drawn (they sit side by side), otherwise :stacked.
_phase_label_panels [Function]
CTFlows.TrajectoryPlots._phase_label_panels Function
_phase_label_panels(
phase_labels::Symbol,
n::Int64,
control_shown::Bool
) -> Vector{Bool}Return, for each of the n drawn panels, whether it receives the phase labels: every panel for phase_labels = :all, none for :none; for :control, the control panel when it is drawn (the last panel, see CTFlows.TrajectoryPlots._panels), the first panel otherwise.
_rownorm [Function]
CTFlows.TrajectoryPlots._rownorm Function
_rownorm(row) -> AnyEuclidean norm of a row, written out to avoid a LinearAlgebra dependency.
_sample [Function]
CTFlows.TrajectoryPlots._sample Function
_sample(f, ts) -> AnySample a callable f over the times ts into an (n_times × n_components) matrix. A scalar (1-D) and a vector-valued f are handled alike.
_spliced_samples [Function]
CTFlows.TrajectoryPlots._spliced_samples Function
_spliced_samples(
sol,
ts::AbstractVector,
M::AbstractMatrix,
component::Symbol;
connect
) -> Tuple{Any, Any}Insert the left and right limits of component at the switching times of sol into the samples (ts, M) of that component, with CTBase.Plotting.splice_jumps: a jump is drawn as a vertical segment, or, with connect = false, the curve is broken between the two limits. The samples are returned unchanged when the trajectory has no switching time.
Returns
(ts, M): the time grid (each switching time twice) and the matrix of samples.
_state_names [Function]
CTFlows.TrajectoryPlots._state_names Function
_state_names(sol, n) -> AnyNames of the n state components: from the OCP model when the trajectory carries one, else generated (x, x₁, …).
_state_panel [Function]
CTFlows.TrajectoryPlots._state_panel Function
_state_panel(
sol,
ts,
style::NamedTuple;
connect
) -> CTBase.Plotting.PanelThe state panel: state(sol) sampled at ts, one curve per component, with the jumps at the switching times drawn as vertical segments.
_sub [Function]
CTFlows.TrajectoryPlots._sub Function
_sub(i::Integer) -> StringSubscript form of a component index: 1 → "₁", 12 → "₁₂".
_time_name [Function]
CTFlows.TrajectoryPlots._time_name Function
_time_name(sol) -> StringTime-axis name for a trajectory: the OCP's time name when available, else "t".
_traj_model [Function]
CTFlows.TrajectoryPlots._traj_model Function
_traj_model(sol) -> AnyThe OCP model a trajectory carries, or nothing. Only a StateFlowTrajectory built from an OCP (Flow(ocp, law)) carries one.
build_figure [Function]
CTFlows.TrajectoryPlots.build_figure Function
build_figure(
sol,
description::Symbol...;
layout,
control,
time,
state_style,
costate_style,
control_style,
switching_style,
phase_labels,
phase_labels_style,
jumps,
size
) -> CTBase.Plotting.FigureBuild the CTBase.Plotting.Figure for a CTFlows trajectory sol and a description.
Resolves the description (the _default_description contract default when none is given), builds the state / costate / control CTBase.Plotting.Panels via the semantic accessors, and assembles the layout tree. This is the single backend-agnostic entry point: the CTFlowsPlots / CTFlowsMakie extensions call it and render the result through a CTBase.Plotting.render backend.
Arguments
sol: aVectorFieldTrajectory,HamiltonianVectorFieldTrajectoryorStateFlowTrajectory.description: any of:state,:costate,:control; empty ⇒ the per-type default.
Keyword arguments
layout::Symbol = :split::split(one subplot per component) or:group.control::Symbol = :components::components,:normor:all.time::Symbol = :default::defaultor:normalize/:normalise.state_style/costate_style/control_style: aNamedTupleof attributes or:noneto hide the group.switching_style = NamedTuple(): style of the vertical lines at the switching times of a multi-phase trajectory (dashed black lines by default, merged with this style);:nonehides them.phase_labels::Symbol = :control: where to write the phase labels (seeCTFlows.Trajectories.phase_labels)::control(the control panel, or the first drawn panel when the control is not drawn),:all(every panel) or:none.phase_labels_style::NamedTuple = NamedTuple(): style of the labels (color,fontsize,halign,valign).jumps::Symbol = :segment: a jump at a switching time is drawn as a vertical segment from the left to the right limit (:segment), or the curve is broken between the two limits (:none), so that no segment suggests values the trajectory does not take.size: figure size;nothingdefers to the engine heuristic.
At every switching time, a jump of the state, costate or control is drawn as a vertical segment, from the left to the right limit, or as a break in the curve with jumps=:none. The whole trajectory is one curve per component, so it keeps one color across phases.
Returns
CTBase.Plotting.Figure.
Throws
CTBase.Exceptions.IncorrectArgument: nothing to draw (empty description, or every drawn group styled:none); an invalidcontrol/layout/time/phase_labels/jumps.
clean [Function]
CTFlows.TrajectoryPlots.clean Function
clean(description) -> TupleStandardize a description tuple: map plural forms to singular and drop duplicates. The canonical symbols are :state, :costate, :control.
split_plot_kwargs [Function]
CTFlows.TrajectoryPlots.split_plot_kwargs Function
split_plot_kwargs(kwargs) -> Tuple{NamedTuple, NamedTuple}Split the user keyword arguments of plot(sol; …) into the pair (build, render): build holds the _BUILD_KEYS consumed by build_figure, render holds everything else (forwarded to the CTBase.Plotting backend). The size keyword is handled explicitly by the extensions and is not part of _BUILD_KEYS.
From CTFlows.Systems
HVFIpFunctor [Struct]
CTFlows.Systems.HVFIpFunctor Type
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 "in-place buffer stays a vector" exception, ct-conventionsDIM2).
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.
_accessor_hint [Function]
CTFlows.Systems._accessor_hint Function
_accessor_hint(
sys::CTFlows.Systems.AbstractSystem
) -> Tuple{String, String}Describe what a system holds and which accessors apply to it, as a (got, suggestion) pair of strings for CTFlows.Systems._unavailable.
_aug_assign! [Function]
CTFlows.Systems._aug_assign! Function
_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.
_unavailable [Function]
CTFlows.Systems._unavailable Function
_unavailable(
accessor::Symbol,
what::String,
sys::CTFlows.Systems.AbstractSystem
)Throw the IncorrectArgument raised by an accessor that does not apply to sys.
Arguments
accessor::Symbol: the name of the accessor, e.g.:hamiltonian.what::String: what the accessor returns, e.g."Hamiltonian".sys::AbstractSystem: the system of the flow.
Throws
CTBase.Exceptions.IncorrectArgument: always.
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.
_with_output_grid [Function]
CTFlowsSciMLIntegrator._with_output_grid Function
_with_output_grid(
options,
_::Union{Nothing, CTFlows.Configs.AbstractGrid}
) -> AnyNo grid of times imposed at the call (none, or a generated grid built after the integration): the cached trajectory options are used as they are.
_with_output_grid(options, grid::AbstractVector) -> AnyGrid of times imposed at the call: a copy of the trajectory options whose saveat is the grid (a call that also has the integrator's saveat is rejected upstream). saveat only shapes the output; the integration stays dense (see CommonSolve.solve for Integrators.SciML).
From CTFlows.Flows
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.
_BoundedConstraint [Struct]
CTFlows.Flows._BoundedConstraint Type
struct _BoundedConstraint{C, S, B} <: FunctionA path constraint lb ≤ c(t,x,u,v) ≤ ub from the model, normalised as g ≥ 0 on its active side: g = sign · (c - bound), with sign = 1 and bound = lb on the lower side, sign = -1 and bound = ub on the upper side. Scalar fields for a one-dimensional constraint, vectors (one entry per component) otherwise.
Fields
c::C: the constraint functionc(t,x,u,v)stored in the model.sign::S:1(lower side) or-1(upper side), per component.bound::B: the bound of the active side, per component.
See also: CTFlows.Flows._resolve_constraint.
_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.
__grid [Function]
CTFlows.Flows.__grid Function
__grid() -> CTBase.Core.NotProvidedTypeDefault value for the grid keyword of a top-level trajectory call.
Returns CTBase.Core.NotProvided by default, meaning no output grid is imposed: the call then generates an CTFlows.Configs.AutomaticGrid (AdaptiveGrid(250) when the solver returns fewer than 250 times), unless a grid of times or the integrator's saveat already shapes the output. grid=nothing keeps the solver steps. Internal calls (the inner flow of a decorator, a phase of a multi-phase flow) pass grid=nothing.
See also: CTFlows.Flows._default_grid.
_active_side [Function]
CTFlows.Flows._active_side Function
_active_side(label, lb, ub, side::Nothing) -> SymbolReturn the active side, :lower or :upper, of one component lb ≤ c ≤ ub of the path constraint label. With side === nothing it is inferred from the bounds:
lower bound only:
:lower(g = c - lb);upper bound only:
:upper(g = ub - c);equality,
lb == ub::lower(g = c - lb; the multiplier has no sign).
Throws
CTBase.Exceptions.IncorrectArgument: for a two-sided constraint with no side given, for a constraint with no finite bound, for a side other than:loweror:upper, or for a side whose bound is infinite.
_adtypes_backend [Function]
CTFlows.Flows._adtypes_backend Function
_adtypes_backend(
backend::CTBase.Differentiation.DifferentiationInterface
) -> AnyThe ADTypes backend wrapped by an AD backend strategy: only the DifferentiationInterface strategy wraps one (any other strategy, e.g. a user-defined one, gives nothing).
_apply_dim_coerce [Function]
CTFlows.Flows._apply_dim_coerce Function
_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.
_bounded_constraint [Function]
CTFlows.Flows._bounded_constraint Function
_bounded_constraint(
label,
c,
lb::Real,
ub::Real,
side
) -> CTFlows.Flows._BoundedConstraint{_A, Int64, B} where {_A, B<:Real}Build the CTFlows.Flows._BoundedConstraint of a scalar constraint.
_bounded_constraint(
label,
c,
lb::AbstractVector,
ub::AbstractVector,
side
) -> CTFlows.Flows._BoundedConstraintBuild the CTFlows.Flows._BoundedConstraint of a vector constraint, one side per component.
_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
) -> NamedTuple{(:integrator, :label), <:Tuple{Any, String}}Build the SciML integrator for an AD-free flow (Traits.WithoutAD) directly from a flow constructor's keyword arguments, honouring a method=:gpu device selection popped from them. Return (integrator, label): the integrator and the routed label action option (see CTFlows.Flows._routed_label).
Shared by the AD-free constructors (Flow(VectorField), Flow(HamiltonianVectorField), controlled-vector-field flows, Flow(ODEFunction), Flow(ODEProblem)), which build only an integrator (no :di AD backend). Routing through the WithoutAD plan means an ad_backend option is correctly rejected here as unknown (there is no AD backend to configure).
See also: CTFlows.Flows._build_flow_components, CTFlows.Flows._pop_method.
_build_ocp_pseudo_flow [Function]
CTFlows.Flows._build_ocp_pseudo_flow Function
_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}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(identity)}}, CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(only)}}}, VariableModelType<:Union{CTModels.Components.VariableModelSolution{Vector{Float64}}, CTModels.Components.VariableModelSolution{Float64}}, ModelType<:(CTModels.Models.Model{<:CTBase.Traits.TimeDependence, T} where T<:CTModels.Components.TimesModel), CostateModelType<:CTModels.Components.CoercedTrajectory}
_build_ocp_solution(
ocp,
sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
variable,
integ,
law;
switching
) -> Union{CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(identity)}}, CTModels.Components.ControlModelSolution{CTModels.Components.CoercedTrajectory{CTFlows.Flows.var"#_control_of##2#_control_of##3", typeof(only)}}}, VariableModelType<:Union{CTModels.Components.VariableModelSolution{Vector{Float64}}, CTModels.Components.VariableModelSolution{Float64}}, ModelType<:(CTModels.Models.Model{<:CTBase.Traits.TimeDependence, T} where T<:CTModels.Components.TimesModel), CostateModelType<:CTModels.Components.CoercedTrajectory}, CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, CTModels.Solutions.EmptyDualModel, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}, CTModels.Solutions.EmptySwitchingModel} where {TimeGridModelType<:Union{CTModels.Solutions.MultipleTimeGridModel, CTModels.Solutions.UnifiedTimeGridModel{Vector{Float64}}}, TimesModelType<:CTModels.Components.TimesModel, StateModelType<:(CTModels.Components.StateModelSolution{TS} where TS<:CTModels.Components.CoercedTrajectory), ControlModelType<:Union{CTModels.Components.ControlModelSolution{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.
_call_arrays [Function]
CTFlows.Flows._call_arrays Function
_call_arrays(
config::CTFlows.Configs.AbstractStateConfig
) -> Tuple{Any}Initial arrays of a call configuration whose placement is checked: the state, and the costate of a Hamiltonian configuration (the variable costate is a host object by design).
_call_grid_spec [Function]
CTFlows.Flows._call_grid_spec Function
_call_grid_spec(tspan, grid, flow) -> AnyValidate the grid keyword of a decorated trajectory call and return the generated grid spec (or nothing). A grid of times given in place of the span is left to the inner flow.
Throws
CTBase.Exceptions.IncorrectArgument: If a grid of times andgrid=are both given, or if the integrator setssaveatwhilegrid=is given.
_check_ad_eltypes [Function]
CTFlows.Flows._check_ad_eltypes Function
_check_ad_eltypes(_, values)Reject, for the AutoMooncake backend ad, the values of the call (state, costate, times, variable) whose element type Mooncake cannot differentiate through (see CTFlows.Flows._mooncake_eltype). Other backends accept every element type here.
_check_call [Function]
CTFlows.Flows._check_call Function
_check_call(
flow::CTFlows.Flows.AbstractFlow,
config::CTFlows.Configs.AbstractConfig;
variable
)Check a flow call before the integration:
a GPU flow (
method=:gpu) needs device arrays, not host arrays;the
AutoMooncakebackend needs IEEE floats in the state, the costate, the times and the variable (no outer ForwardDiff through the flow);the package of the AD backend of the system is loaded (see
CTBase.Differentiation.check_backend).
Each check raises a structured error at the call, instead of a raw error from the AD backend deep inside the integration. variable is the variable of the call (nothing if none).
Throws
CTBase.Exceptions.PreconditionError: For a host array undermethod=:gpu, or a non-IEEE element type with theAutoMooncakebackend.CTBase.Exceptions.ExtensionError: If the package of the AD backend is not loaded.
See also: CTFlows.Flows._core_invoke_flow.
_check_convenience_arities [Function]
CTFlows.Flows._check_convenience_arities Function
_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,label => side,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!.
_check_host_arrays [Function]
CTFlows.Flows._check_host_arrays Function
_check_host_arrays(device, host)Reject host arrays when the flow is a GPU flow. device is the device parameter of the integrator, host the host arrays of the call.
_check_output_grid [Function]
CTFlows.Flows._check_output_grid Function
_check_output_grid(flow, config)Reject an output grid given at the call (grid of times or generated) when the flow's integrator sets saveat (the integrator is only queried when a grid is given).
_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.
_default_grid [Function]
CTFlows.Flows._default_grid Function
_default_grid(
grid,
tspan,
flows...
) -> Union{Nothing, CTFlows.Configs.AutomaticGrid}Resolve the grid keyword of a top-level trajectory call. An explicit grid (nothing, an integer, a generated grid) is returned as given. Core.NotProvided becomes CTFlows.Configs.AutomaticGrid when the call sets a time span and none of the flows (every phase of a multi-phase flow) has an integrator with saveat, and nothing otherwise: a grid of times or a saveat already shapes the output.
See also: CTFlows.Flows.__grid.
_dim_coerce [Function]
CTFlows.Flows._dim_coerce Function
_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.
_integrator_device [Function]
CTFlows.Flows._integrator_device Function
_integrator_device(_::CTSolvers.Integrators.SciML{P}) -> AnyDevice parameter (CTBase.Strategies.CPU or CTBase.Strategies.GPU) of an integrator, or nothing for an integrator that is not device-parameterized.
_invoke_flow [Function]
CTFlows.Flows._invoke_flow Function
_invoke_flow(
flow::CTFlows.Flows.AbstractFlow,
config::CTFlows.Configs.AbstractConfig;
variable,
unsafe
)Solve an ODE problem using a flow with trait-based dispatch on the variable parameter.
This function dispatches to one of four specialized implementations based on:
The flow's
VariableDependencetrait (FixedorNonFixed)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.AbstractVariableCostateCapability},
::Type{VT},
flow::CTFlows.Flows.AbstractHamiltonianFlow,
config::CTFlows.Configs.HamiltonianTrajectoryConfig;
variable,
unsafe
)Variable costate call for trajectory configurations.
Variable costate computation is only supported for point configurations, not trajectory configurations. This method throws an error when attempting to use variable_costate=true with a trajectory configuration, whatever the flow's variable-costate capability (SupportsVariableCostate or NoVariableCostate): the call form is rejected first.
Throws
CTBase.Exceptions.PreconditionError: Always, with a descriptive message indicating that variable_costate is only supported for point configurations.
See also: CTBase.Traits.AbstractVariableCostateCapability, CTFlows.Configs.HamiltonianTrajectoryConfig.
_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.
_is_host_array [Function]
CTFlows.Flows._is_host_array Function
_is_host_array(x) -> BoolWhether x is a dense host array. Numbers (a 1-D state is a scalar) and device arrays are not.
_label_action_def [Function]
CTFlows.Flows._label_action_def Function
_label_action_def(
) -> CTBase.Options.OptionDefinition{String}Return the definition of the label action option, accepted by every flow constructor: the label of the phase the flow integrates (e.g. "bang"), default CTFlows.Flows.__label (no label).
It is routed as an action option, like hamiltonian_type, so it is checked by the orchestration (type, unknown or misplaced options) and never mistaken for a strategy option; CTFlows.Flows._route_flow_options adds it to every routing.
See also: CTFlows.Flows._routed_label, CTFlows.Flows.label.
_limit_rows [Function]
CTFlows.Flows._limit_rows Function
_limit_rows(values::AbstractVector) -> Matrix{Float64}Stack values (scalars for one component, vectors otherwise) as the rows of a matrix: one row per switching time. No value gives a 0 × 0 matrix.
_mooncake_eltype [Function]
CTFlows.Flows._mooncake_eltype Function
_mooncake_eltype(
_::Type{<:Union{Float16, Float32, Float64, Integer}}
) -> BoolWhether AutoMooncake can differentiate through a value of element type T: an IEEE float or an integer (an integer time is promoted by the integrator). A ForwardDiff.Dual (the flow differentiated by an outer ForwardDiff) or a BigFloat is refused by Mooncake.
_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.
_ocp_switching_model [Function]
CTFlows.Flows._ocp_switching_model Function
_ocp_switching_model(
sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory,
law,
variable,
labels::AbstractVector{<:AbstractString}
) -> Union{CTModels.Solutions.EmptySwitchingModel, CTModels.Solutions.SwitchingModel}Build the switching structure of the Solution of an OCP flow from its Hamiltonian trajectory: the switching times of the trajectory, the phase labels labels (one per phase), and the left and right limits of the state, costate and control at every switching time. The control limits come from the law: the left limit from the law of the phase that ends (at the values before the jump), the right one from the law of the next phase (at the values after it), see CTFlows.Flows._right_ocp_control.
Returns an CTModels.Solutions.EmptySwitchingModel when there is no switching time and no label.
_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.
_regrid_hamiltonian [Function]
CTFlows.Flows._regrid_hamiltonian Function
_regrid_hamiltonian(
sol,
_::Union{Nothing, AbstractVector},
law,
variable,
bounds
) -> AnyNo generated grid: the Hamiltonian trajectory is returned unchanged.
_regrid_hamiltonian(
sol,
spec::CTFlows.Configs.AbstractGrid,
law,
variable,
bounds
) -> CTFlows.Trajectories.HamiltonianVectorFieldTrajectoryRegrid a Hamiltonian trajectory on the generated grid spec, whose plotted curves are the state, the costate and, when there is a law, the reconstructed control.
See also: CTFlows.Trajectories.apply_generated_grid.
_regrid_state [Function]
CTFlows.Flows._regrid_state Function
_regrid_state(
traj,
_::Union{Nothing, AbstractVector},
law,
variable,
coerce,
bounds
) -> AnyNo generated grid: the state trajectory is returned unchanged.
_regrid_state(
traj,
spec::CTFlows.Configs.AbstractGrid,
law,
variable,
coerce,
bounds
) -> CTFlows.Trajectories.VectorFieldTrajectoryRegrid a state trajectory on the generated grid spec, whose plotted curves are the state and, when there is a law, the reconstructed control.
See also: CTFlows.Trajectories.apply_generated_grid.
_reject_control_free_constraint [Function]
CTFlows.Flows._reject_control_free_constraint Function
_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.
_reject_saveat [Function]
CTFlows.Flows._reject_saveat Function
_reject_saveat(integ)Reject an output grid imposed at the call when the integrator already sets saveat.
Throws
CTBase.Exceptions.IncorrectArgument: IfIntegrators.has_saveat(integ).
_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-placec(t,x,u,v)and its boundslb ≤ c ≤ ub. The constraint is normalised asg ≥ 0from the bounds:g = c - lbfor a lower bound,g = ub - cfor an upper bound,g = c - lbfor an equality; a two-sided constraint needs the side (next item). 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.spec::Pairislabel => side: the label as above, on the activeside(:loweror:upper, or one of them per component of a vector constraint).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(
ocp,
spec::Pair{Symbol}
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:FunctionResolve a :label => side constraint spec: the :path constraint label, normalised as g ≥ 0 on the given active side — :lower (g = c - lb) or :upper (g = ub - c). side is one Symbol for every component of the constraint, or a Tuple/AbstractVector with one Symbol per component.
Throws
CTBase.Exceptions.IncorrectArgument: iflabelis not a:pathconstraint, if a side is neither:lowernor:upper, if the bound of the given side is infinite, or if the number of sides does not match the constraint dimension.
See also: CTFlows.Flows._resolve_constraint.
_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), label => side, Function, Tuple, and CTBase.Data.PathConstraint are accepted.
Throws
CTBase.Exceptions.IncorrectArgument: whenspecis not a supported type.
See also: CTFlows.Flows._resolve_constraint.
_resolve_labelled_constraint [Function]
CTFlows.Flows._resolve_labelled_constraint Function
_resolve_labelled_constraint(
ocp,
label::Symbol,
side
) -> CTBase.Data.PathConstraint{F, CTBase.Traits.MixedConstraintKind} where F<:FunctionResolve the :path constraint label of ocp into a CTBase.Data.MixedConstraint normalised as g ≥ 0, from the function c and the bounds lb ≤ c ≤ ub stored in the model. side is nothing (inferred from the bounds), a Symbol, or one Symbol per component.
Throws
CTBase.Exceptions.IncorrectArgument: iflabelis not a:pathconstraint, or if the active side cannot be determined or is invalid (seeCTFlows.Flows._active_side).
_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.
_right_ocp_control [Function]
CTFlows.Flows._right_ocp_control Function
_right_ocp_control(law, _::Integer, t, x, p, v) -> AnyControl just after the i-th switching time t, from the state x and costate p after the jump. A single law has no phase, so it is the law itself; CTFlows.MultiPhase adds the method of the piecewise law of a multi-phase flow (the law of the next phase).
_right_ocp_control(
pl::CTFlows.MultiPhase._PiecewiseControlLaw,
i::Integer,
t,
x,
p,
v
) -> AnyControl just after the i-th switching time t, from the state x and costate p after the jump: the law of the next phase. Used to build the switching structure of the Solution of a multi-phase OCP flow.
_route_flow_options [Function]
CTFlows.Flows._route_flow_options Function
_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 (action and strategy options mixed,methodalready popped).action_defs: the action options of the constructor, on top of thelabeloption that every flow constructor accepts (seeCTFlows.Flows._label_action_def).
Returns
NamedTuplewith fields:action: action-level options (label, plus those ofaction_defs)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.An action option shadows a strategy option of the same name (an info message is emitted);
route_topasses a value to the strategy instead.
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.
_routed_label [Function]
CTFlows.Flows._routed_label Function
_routed_label(routed) -> StringReturn the label action option of a routing result, as a String (CTFlows.Flows.__label when it is not set).
See also: CTFlows.Flows._label_action_def, CTFlows.Flows._route_flow_options.
_single_side [Function]
CTFlows.Flows._single_side Function
_single_side(
label,
side::Union{Nothing, Symbol},
i,
n
) -> Union{Nothing, Symbol}Return the side requested for component i (of n): side itself when it is nothing or a Symbol, its i-th entry when it gives one side per component.
Throws
CTBase.Exceptions.IncorrectArgument: if the number of sides is notn.
_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.
_system_ad_backend [Function]
CTFlows.Flows._system_ad_backend Function
_system_ad_backend(sys) -> AnyThe ADTypes backend of the system of a flow: the backend of an AD system, nothing for an AD-free one.
See also: CTBase.Traits.ad_trait, CTFlows.Systems.backend.
_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.
_value_eltype [Function]
CTFlows.Flows._value_eltype Function
_value_eltype(x::AbstractArray) -> AnyElement type of a value of the call: the element type of an array, the type of a number, nothing for anything else (no variable, NotProvided).
_variable_vector [Function]
CTFlows.Flows._variable_vector Function
_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.
_warn_not_dense [Function]
CTFlows.Flows._warn_not_dense Function
_warn_not_dense(traj)Warn (once) when an OCP objective is about to be recomputed from a trajectory that has no dense interpolant (e.g. integrated with dense=false): the state is then only linearly interpolated between the saved points, so the objective — and the reconstructed control — are accurate to the grid spacing, not to the solver tolerances.
See also: CTFlows.Flows._flow_objective, CTSolvers.Integrators.is_dense.
_with_flow_label [Function]
CTFlows.Flows._with_flow_label Function
_with_flow_label(
result,
_::CTFlows.Flows.AbstractFlow
) -> Union{CTFlows.Trajectories.HamiltonianVectorFieldTrajectory, CTFlows.Trajectories.VectorFieldTrajectory}Give a raw trajectory the label of the flow that computed it; any other result (a point evaluation) is returned as is.
From CTFlowsMakie
_plot [Function]
CTFlowsMakie._plot Function
_plot(
sol,
description::Symbol...;
size,
kwargs...
) -> Makie.FigureInternal implementation of Makie.plot for the CTFlows trajectory types.
Builds the figure with CTFlows.TrajectoryPlots.build_figure (which owns the user-facing defaults and throws on an empty description) and renders it via CTBase.Plotting.render on the Makie backend. Returns a Makie.Figure.
_plot! [Function]
CTFlowsMakie._plot! Function
_plot!(
f::Makie.Figure,
sol,
description::Symbol...;
kwargs...
) -> Makie.FigureInternal implementation of Makie.plot! for the CTFlows trajectory types: build the figure with CTFlows.TrajectoryPlots.build_figure and overlay it onto the existing Makie.Figure f via CTBase.Plotting.render! (Makie backend).
From CTFlows.Configs
_check_grid_size [Function]
CTFlows.Configs._check_grid_size Function
_check_grid_size(n::Integer, context::String)Check the number of times of a generated grid.
Throws
CTBase.Exceptions.IncorrectArgument: Ifn < 2.
_grid_spec [Function]
CTFlows.Configs._grid_spec Function
_grid_spec(_::Nothing)Normalize the grid keyword of a trajectory call: nothing (no generated grid), an integer n (uniform grid of n times) or an CTFlows.Configs.AbstractGrid.
Throws
CTBase.Exceptions.IncorrectArgument: For any other value (a vector of times is passed in place of the time span, not throughgrid).
_time_spec [Function]
CTFlows.Configs._time_spec Function
_time_spec(
tspan::Tuple{Real, Real}
) -> Tuple{Tuple{Any, Any}, Nothing}Time span (t0, tf), no imposed output grid.
_time_spec(
times::Tuple{Vararg{Real}}
) -> Tuple{Tuple{Any, Any}, Nothing}Imposed output grid given as a tuple of times.
_time_spec(
grid::AbstractVector{<:Real}
) -> Tuple{Tuple{Any, Any}, Any}Imposed output grid: returns the span (first, last) and the grid as a vector of floats.
Throws
CTBase.Exceptions.IncorrectArgument: If the grid has fewer than two times or is not strictly monotone.
_time_spec(
times::Union{Tuple{Vararg{Real}}, AbstractVector{<:Real}},
grid
) -> Tuple{Tuple{Any, Any}, Any}Time specification of a trajectory call with a grid keyword: the span and the output grid (a vector of times, a generated grid spec, or nothing).
Throws
CTBase.Exceptions.IncorrectArgument: If both a grid of times andgrid=are given.
From CTFlows.Display
BRANCH_END [Constant]
CTFlows.Display.BRANCH_END Constant
Tree-branch prefix for the last field in a list (└─), styled with the muted palette role at print time.
BRANCH_MID [Constant]
CTFlows.Display.BRANCH_MID Constant
Tree-branch prefix for a mid-list field (├─), styled with the muted palette role at print time.
format_codes [Function]
CTFlows.Display.format_codes Function
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.
_NEGLIGIBLE_CURVATURE [Constant]
CTFlows.Trajectories._NEGLIGIBLE_CURVATURE Constant
Curvature below which the scaled curves are considered straight. The curves are scaled to a unit range over a unit time, where a significant bend has a curvature of order one; the finite-difference rounding noise on a straight segment, amplified by the square roots of the density, would otherwise drive the whole grid.
_aug_split_solution [Function]
CTFlows.Trajectories._aug_split_solution Function
_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.
_cdf_table [Function]
CTFlows.Trajectories._cdf_table Function
_cdf_table(
_::CTFlows.Configs.UniformGrid,
curve,
steps,
a,
b
) -> NamedTuple{(:F, :T, :mass), <:Tuple{Vector{Float64}, Any, Any}}Uniform cumulative distribution on the phase [a, b]; its mass is the duration.
_cdf_table(
spec::CTFlows.Configs.AdaptiveGrid,
curve,
steps,
a,
b
) -> NamedTuple{(:F, :T, :mass), <:Tuple{Any, Any, Any}}Cumulative distribution on the phase [a, b] of the curvature density ρ ∝ ‖ỹ''‖^{1/2} of the scaled plotted curves, mixed with the uniform density, tabulated on the solver steps subdivided in 8. Components with a negligible range are ignored, and so are negligible curvatures (_NEGLIGIBLE_CURVATURE); with no curvature at all the distribution is uniform.
_check_switch_index [Function]
CTFlows.Trajectories._check_switch_index Function
_check_switch_index(sol, i::Integer, context::String)Check that i is the index of a switching time of sol.
Throws
CTBase.Exceptions.IncorrectArgument: if it is not.
_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.
_curve_in_phase [Function]
CTFlows.Trajectories._curve_in_phase Function
_curve_in_phase(curve, t, a, b) -> AnyEvaluate the plotted curve inside the phase [a, b]: at the phase start, slightly inside, so that the right limit is read after a jump (the trajectory is left-continuous).
_flat [Function]
CTFlows.Trajectories._flat Function
_flat(v::Real) -> VectorFlatten a plotted value (number or array) into a vector of floats; a complex value gives its real parts followed by its imaginary parts. A device array (e.g. CuArray) is first copied to the host: the plotted curve is host data and must not scalar-index the device. The primal value is taken (dual numbers of an automatic-differentiation pass only shape the grid through their value, see CTSolvers.Integrators.deepvalue).
_flat_part [Function]
CTFlows.Trajectories._flat_part Function
_flat_part(part, v) -> AnyPrimal values of the part (real or imag) of the entries of the complex array v, as a vector of floats.
_ham_split_solution [Function]
CTFlows.Trajectories._ham_split_solution Function
_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.
_invert_cdf [Function]
CTFlows.Trajectories._invert_cdf Function
_invert_cdf(
F::AbstractVector,
T::AbstractVector,
n::Int64
) -> Vector{Float64}Invert the tabulated cumulative distribution F (non-decreasing, from 0 to 1) over the times T at n equally spaced levels; the bounds are exact.
_kept_labels [Function]
CTFlows.Trajectories._kept_labels Function
_kept_labels(
sol,
labels::AbstractVector{<:AbstractString}
) -> Vector{String}Return the labels of sol to keep: none when every label is empty, all of them otherwise.
Throws
CTBase.Exceptions.IncorrectArgument: if there is not one label per phase ofsol.
_phase_sequence [Function]
CTFlows.Trajectories._phase_sequence Function
_phase_sequence(
labels::AbstractVector{<:AbstractString}
) -> StringReturn the sequence of phase labels as written by the displays, e.g. "bang → · → singular": the labels joined by arrows, a phase with no label written · so that every phase keeps its place between the switching times.
See also: CTFlows.Trajectories.phase_labels.
_plotted_curve [Function]
CTFlows.Trajectories._plotted_curve Function
_plotted_curve(
fs...
) -> CTFlows.Trajectories.var"#_plotted_curve##0#_plotted_curve##1"{<:Tuple}Plotted curve t -> [x(t); p(t); u(t)] from callables (nothing entries are skipped).
_pre_grid [Function]
CTFlows.Trajectories._pre_grid Function
_pre_grid(steps, a, b, k::Int64) -> AnyPre-grid of the phase [a, b]: the solver steps inside it, each interval subdivided in k, in integration order.
_right_controlled_u [Function]
CTFlows.Trajectories._right_controlled_u Function
_right_controlled_u(law, _::Integer, t, x, v) -> AnyControl just after the i-th switching time t, from the state x after the jump: the law of the next phase. A single law has no phase, so it is the law itself; CTFlows.MultiPhase adds the method of the piecewise law of a multi-phase flow.
_right_controlled_u(
pl::CTFlows.MultiPhase._PiecewiseControlLaw,
i::Integer,
t,
x,
v
) -> AnyState (controlled) control just after the i-th switching time t, from the state x after the jump: the law of the next phase. Used by CTFlows.Trajectories.right_limit.
_scale_rows [Function]
CTFlows.Trajectories._scale_rows Function
_scale_rows(Y::AbstractMatrix) -> AnyScale every row (component) by its range; a component whose range is negligible with respect to its size is constant and gets a zero row (otherwise its rounding noise would dominate the density).
_sft_control [Function]
CTFlows.Trajectories._sft_control Function
_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.
_share_intervals [Function]
CTFlows.Trajectories._share_intervals Function
_share_intervals(
masses::AbstractVector,
total::Int64
) -> AnyShare total intervals between phases in proportion to masses (largest remainder), at least one per phase.
_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).
_switching_fields [Function]
CTFlows.Trajectories._switching_fields Function
_switching_fields(sol, fmt) -> Vector{Any}Return the display fields of the switching structure of a trajectory: the switching times when there are any, the sequence of phase labels when at least one phase is labelled (nothing is shown for an unlabelled trajectory).
See also: CTFlows.Trajectories._phase_sequence.
_switching_parts [Function]
CTFlows.Trajectories._switching_parts Function
_switching_parts(sol) -> Vector{String}Return the compact display parts of the switching structure of a trajectory (see CTFlows.Trajectories._switching_fields).
_throw_component [Function]
CTFlows.Trajectories._throw_component Function
_throw_component(sol, component::Symbol, expected::String)Throw the error of a component a trajectory does not have.
Throws
CTBase.Exceptions.IncorrectArgument: always.
apply_generated_grid [Function]
CTFlows.Trajectories.apply_generated_grid Function
apply_generated_grid(
traj,
_::Union{Nothing, AbstractVector},
curve,
bounds
) -> AnyApply the output grid of a call to a trajectory (or integration result): unchanged without a generated grid; otherwise generate it from curve over bounds (the solver times of traj as pre-grid) and regrid.
apply_generated_grid(
traj,
spec::CTFlows.Configs.AutomaticGrid,
curve,
bounds
) -> AnyApply the default output grid of a call (issue #446): the adaptive grid is generated only when the trajectory is dense (the curvature of a linear interpolant is meaningless) and has fewer than spec.grid.n distinct times; otherwise traj is returned unchanged.
See also: CTFlows.Configs.AutomaticGrid.
generate_grid [Function]
CTFlows.Trajectories.generate_grid Function
generate_grid(
spec::CTFlows.Configs.AbstractGrid,
curve,
steps,
bounds::AbstractVector
) -> Vector{Float64}Generate the output grid spec on the phases delimited by bounds ([t0, t₁, …, tf], in integration order): exactly spec.n distinct times, every bound included once.
curve(t) returns the plotted values at t as a vector (state, costate, control); steps are the solver times, used as the pre-grid of an CTFlows.Configs.AdaptiveGrid. The n - 1 intervals are shared between the phases in proportion to their mass (duration for a uniform grid), at least one per phase.
Throws
CTBase.Exceptions.IncorrectArgument: Ifspec.nis smaller than the number of bounds.