Flows
CTFlows.Flows.Flow Type
struct Flow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, S<:CTFlows.Systems.AbstractSystem{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait}, I<:AbstractIntegrator} <: CTFlows.Flows.AbstractFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait}Concrete flow combining an AbstractSystem with an AbstractIntegrator.
The dynamics axis is encoded in the type parameter D:
D = StateDynamics→ state flow (access viaStateFlowalias)D = HamiltonianDynamics→ Hamiltonian flow (access viaHamiltonianFlowalias)
Type Parameters
TD <: TimeDependence: Time dependence trait (Autonomous or NonAutonomous)VD <: VariableDependence: Variable dependence trait (Fixed or NonFixed)D <: AbstractDynamicsTrait: Dynamics trait (StateDynamicsorHamiltonianDynamics)S <: AbstractSystem{TD, VD, D}: The system typeI <: AbstractIntegrator: The integrator type
Fields
system::S: The system to integrateintegrator::I: The integrator to use for integration
Example
julia> using CTFlows.Flows, CTFlows.Systems, CTFlows.Integrators
julia> system = VectorFieldSystem(VectorField(x -> -x))
julia> integrator = SciML()
julia> flow = StateFlow(system, integrator)
StateFlow{...}See also: CTFlows.Flows.AbstractFlow, CTFlows.Flows.StateFlow, CTFlows.Flows.HamiltonianFlow.
CTFlows.Systems.control_law Function
control_law(
sys::CTFlows.Systems.PseudoHamiltonianSystem
) -> ControlLaw{<:Function, CTBase.Traits.DynClosedLoopFeedback}Return the control law u(t,x,p,v) of a PseudoHamiltonianSystem.
See also: CTFlows.Systems.PseudoHamiltonianSystem, CTFlows.Systems.pseudo_hamiltonian.
control_law(
sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> ControlLaw{<:Function, CTBase.Traits.DynClosedLoopFeedback}Return the control law u(t,x,p,v) of a ConstrainedPseudoHamiltonianSystem.
See also: CTFlows.Systems.ConstrainedPseudoHamiltonianSystem.
control_law(
sys::CTFlows.Systems.HamiltonianSystem
) -> ControlLaw{<:Function, CTBase.Traits.DynClosedLoopFeedback}Return the control law u(t, x, p, v) of a HamiltonianSystem built in the :total mode (wrapping a CTBase.Data.ComposedHamiltonian).
Throws
CTBase.Exceptions.IncorrectArgument: if the system wraps a plain Hamiltonian with no associated control law.
See also: CTFlows.Systems.pseudo_hamiltonian.
control_law(f::CTFlows.Flows.AbstractHamiltonianFlow) -> AnyReturn the control law u(t, x, p, v) carried by a Hamiltonian flow built from a control law. Delegates to CTFlows.Systems.control_law.
Throws
CTBase.Exceptions.IncorrectArgument: for a flow that carries no control law.
See also: CTFlows.Systems.pseudo_hamiltonian.
CTFlows.Systems.pseudo_hamiltonian Function
pseudo_hamiltonian(
sys::CTFlows.Systems.PseudoHamiltonianSystem
) -> PseudoHamiltonian{<:Function, TD, VD} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence}Return the pseudo-Hamiltonian H̃ of a PseudoHamiltonianSystem.
See also: CTFlows.Systems.PseudoHamiltonianSystem, CTFlows.Systems.control_law.
pseudo_hamiltonian(
sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> PseudoHamiltonian{<:Function, TD, VD} where {TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence}Return the base pseudo-Hamiltonian H̃ of a ConstrainedPseudoHamiltonianSystem (without the μ·g term). The constraint and multiplier are exposed separately by CTFlows.Systems.constraint and CTFlows.Systems.multiplier.
See also: CTFlows.Systems.ConstrainedPseudoHamiltonianSystem.
pseudo_hamiltonian(
sys::CTFlows.Systems.HamiltonianSystem
) -> PseudoHamiltonianReturn the pseudo-Hamiltonian H̃ underlying a HamiltonianSystem, when the system wraps a CTBase.Data.ComposedHamiltonian — i.e. it was built in the :total mode of an OCP-with-control (or pseudo-Hamiltonian + control law) flow. The control is not eliminated: H̃(t, x, p, u, v) keeps u as an independent argument.
Throws
CTBase.Exceptions.IncorrectArgument: if the system wraps a plain Hamiltonian with no associated control law (no pseudo-Hamiltonian to recover).
See also: CTFlows.Systems.hamiltonian, CTFlows.Systems.control_law.
pseudo_hamiltonian(
f::CTFlows.Flows.AbstractHamiltonianFlow
) -> AnyReturn the pseudo-Hamiltonian H̃(t, x, p, u, v) underlying a Hamiltonian flow, when available — i.e. when the flow was built from a pseudo-Hamiltonian (or an OCP) and a control law, in either the :partial or the :total mode. Delegates to CTFlows.Systems.pseudo_hamiltonian.
Throws
CTBase.Exceptions.IncorrectArgument: for a flow that carries no control law.
See also: CTFlows.Systems.hamiltonian, CTFlows.Systems.control_law.
CTFlows.Systems.hamiltonian Function
hamiltonian(_::CTFlows.Systems.HamiltonianVectorFieldSystem)Throw an IncorrectArgument error: a HamiltonianVectorFieldSystem stores the vector field X_H directly and carries no scalar Hamiltonian. Use CTFlows.Systems.hamiltonian_vector_field to retrieve X_H instead.
See also: CTFlows.Systems.HamiltonianVectorFieldSystem, CTFlows.Systems.hamiltonian_vector_field.
hamiltonian(
sys::CTFlows.Systems.HamiltonianSystem
) -> AbstractHamiltonianReturn the Hamiltonian function from a HamiltonianSystem.
Arguments
sys::HamiltonianSystem: The Hamiltonian system.
Returns
Data.Hamiltonian: The Hamiltonian function wrapped by the system.
See also: CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.backend.
hamiltonian(
sys::CTFlows.Systems.PseudoHamiltonianSystem
) -> ComposedHamiltonianReturn the true Hamiltonian of a PseudoHamiltonianSystem — the CTBase.Data.ComposedHamiltonian H(t,x,p,v) = H̃(t,x,p,u(t,x,p,v),v) obtained by eliminating the control with the feedback law. Built on the fly.
See also: CTFlows.Systems.pseudo_hamiltonian, CTFlows.Systems.HamiltonianSystem.
hamiltonian(
_::CTFlows.Systems.PseudoHamiltonianVectorFieldSystem
)Throw an IncorrectArgument error: a PseudoHamiltonianVectorFieldSystem stores the pseudo-Hamiltonian vector field X_H̃ directly and carries no scalar Hamiltonian. Use CTFlows.Systems.hamiltonian_vector_field to retrieve X_H̃ instead.
See also: CTFlows.Systems.PseudoHamiltonianVectorFieldSystem, CTFlows.Systems.hamiltonian_vector_field.
hamiltonian(
sys::CTFlows.Systems.ConstrainedPseudoHamiltonianSystem
) -> ComposedHamiltonianReturn the base (unconstrained) true Hamiltonian of a ConstrainedPseudoHamiltonianSystem — the CTBase.Data.ComposedHamiltonian H(t,x,p,v) = H̃(t,x,p,u(t,x,p,v),v). The integrated dynamics additionally include the μ·g term (with μ frozen during differentiation); the constraint and multiplier are available via CTFlows.Systems.constraint / CTFlows.Systems.multiplier. On a boundary arc, where g ≡ 0, this base Hamiltonian coincides with the constrained one.
See also: CTFlows.Systems.pseudo_hamiltonian, CTFlows.Systems.constraint.
hamiltonian(f::CTFlows.Flows.AbstractHamiltonianFlow) -> AnyReturn the Hamiltonian H(t, x, p, v) underlying a Hamiltonian flow.
Delegates to the system-level getter CTFlows.Systems.hamiltonian. The returned object is callable as a scalar function of (t, x, p, v) (or the shorter signatures allowed by the flow's time/variable dependence). It is available for flows built from a scalar Hamiltonian — HamiltonianSystem (including the :total mode of an OCP-with-control flow) and PseudoHamiltonianSystem (the :partial mode, where it reconstructs the composed Hamiltonian). Flows built from a raw Hamiltonian vector field carry no scalar Hamiltonian and are not supported.
This is the getter to use when writing a transversality condition on a free time in a shooting method: with v = t0 and/or tf a variable, the augmented flow integrates the naive adjoint ṗv = -∂H/∂v (initialized at 0), and the mitigated transversality conditions read p_{t0}(tf) = -H(t0, x0, p0, v) and p_{tf}(tf) = H(tf, xf, pf, v).
Example
H = CTFlows.Systems.hamiltonian(flow)
xf, pf, pvf = flow(t0, x0, p0, tf; variable = v, variable_costate = true)
s = pvf[idx_tf] - H(tf, xf, pf, v) # transversality for free final timeSee also: CTFlows.Systems.hamiltonian, CTFlows.Flows.system.
CTFlows.Systems.hamiltonian_vector_field Function
hamiltonian_vector_field(
h::AbstractHamiltonian{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence};
ad_backend,
inplace
) -> Union{HamiltonianVectorField{CTFlows.Systems.HVFIpFunctor{H, B}} where {H<:AbstractHamiltonian, B<:(CTBase.Differentiation.DifferentiationInterface{CPU, CTBase.Strategies.StrategyOptions{NT}} where NT<:NamedTuple)}, HamiltonianVectorField{CTFlows.Systems.HVFOoPFunctor{H, B}} where {H<:AbstractHamiltonian, B<:(CTBase.Differentiation.DifferentiationInterface{CPU, CTBase.Strategies.StrategyOptions{NT}} where NT<:NamedTuple)}}Get the Hamiltonian vector field from a Hamiltonian.
This function computes the Hamiltonian vector field X_H = (∂H/∂p, -∂H/∂x) (also known as the symplectic gradient of H) for a given Hamiltonian using automatic differentiation. It accepts any CTBase.Data.AbstractHamiltonian — a scalar Hamiltonian or a ComposedHamiltonian (as produced by an OCP + control law) — so it also covers pseudo-Hamiltonian flows. The returned vector field wraps a callable CTFlows.Systems.HVFOoPFunctor or CTFlows.Systems.HVFIpFunctor whose call signature matches the Hamiltonian's time and variable dependence traits.
Arguments
h::Data.AbstractHamiltonian{TD, VD}: The Hamiltonian with traitsTD(time dependence) andVD(variable dependence).ad_backend::Differentiation.AbstractADBackend: The AD backend to use (default:__hvf_ad_backend()=Differentiation.DifferentiationInterface(), the CPU default).inplace::Bool: Whether to return an in-place functor (default:__hvf_inplace()=false).
Returns
Data.HamiltonianVectorField: The Hamiltonian vector field with correct traits matching the input Hamiltonian.
Notes
ad_backendmust already be a fully-built strategy (e.g. fromFlow's registry-based routing, or constructed directly asDifferentiation.DifferentiationInterface{Strategies.GPU}(...)). This function does not build or device-select a backend from a rawADTypes.AbstractADType.The functor call signature depends on the Hamiltonian's traits:
Autonomous/Fixed:
(x, p) -> (∂p, -∂x)or(dx, dp, x, p) -> nothing(in-place)NonAutonomous/Fixed:
(t, x, p) -> (∂p, -∂x)or(dx, dp, t, x, p) -> nothing(in-place)Autonomous/NonFixed:
(x, p, v; variable_costate=false) -> (∂p, -∂x)or(x, p, v; variable_costate=true) -> (∂p, -∂x, -∂v)NonAutonomous/NonFixed:
(t, x, p, v; variable_costate=false) -> (∂p, -∂x)or(t, x, p, v; variable_costate=true) -> (∂p, -∂x, -∂v)
See also: CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.HamiltonianVectorFieldSystem, CTBase.Data.HamiltonianVectorField
hamiltonian_vector_field(
sys::CTFlows.Systems.HamiltonianVectorFieldSystem;
inplace
) -> HamiltonianVectorFieldGet the Hamiltonian vector field from a HamiltonianVectorFieldSystem.
This is a trivial getter that returns the pre-stored Hamiltonian vector field from the system. No computation is performed since the vector field is already constructed.
Arguments
sys::HamiltonianVectorFieldSystem: The system with a pre-stored Hamiltonian vector field.
Returns
Data.HamiltonianVectorField: The stored Hamiltonian vector field (identical tosys.hvf).
Notes
This overload is used when the Hamiltonian vector field is already known and stored, avoiding redundant automatic differentiation.
The returned vector field is identical to
sys.hvf(same object reference).
See also: CTFlows.Systems.HamiltonianVectorFieldSystem, CTBase.Data.HamiltonianVectorField
hamiltonian_vector_field(
sys::CTFlows.Systems.HamiltonianSystem;
inplace
) -> Union{HamiltonianVectorField{CTFlows.Systems.HVFIpFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}, HamiltonianVectorField{CTFlows.Systems.HVFOoPFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}}Get the Hamiltonian vector field from a HamiltonianSystem (AD-backed).
This function extracts the Hamiltonian and AD backend from the system and delegates to the Hamiltonian overload to compute the vector field via automatic differentiation.
Arguments
sys::HamiltonianSystem: The system containing a Hamiltonian and AD backend.inplace::Bool: Whether to return an in-place closure (default:__hvf_inplace()=false).
Returns
Data.HamiltonianVectorField: The Hamiltonian vector field with correct traits matching the system's Hamiltonian.
Notes
This overload uses the AD backend returned by
backend(sys)for gradient computation, passed through as-is (no unwrapping/rewrapping), so a device-specific backend (e.g.DifferentiationInterface{Strategies.GPU}) is preserved.The
inplaceparameter controls whether the returned closure writes results in-place.Delegates to
CTFlows.Systems.hamiltonian_vector_field.
See also: CTFlows.Systems.HamiltonianSystem, CTBase.Data.Hamiltonian, CTBase.Differentiation.AbstractADBackend
hamiltonian_vector_field(
sys::CTFlows.Systems.AbstractHamiltonianSystem;
inplace,
kwargs...
) -> HamiltonianVectorFieldGet the Hamiltonian vector field from any AbstractHamiltonianSystem, dispatching on ad_trait.
WithADsystems: computes the vector field via automatic differentiation usinghamiltonian(sys)andbackend(sys)(protocol methods the system must implement).WithoutADsystems: throwsNotImplemented— the system must implementhamiltonian_vector_fielddirectly (asHamiltonianVectorFieldSystemdoes).
Throws
Exceptions.NotImplemented: when the system's AD trait isWithoutADand no specializedhamiltonian_vector_fieldoverload exists for the system type.
See also: CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.HamiltonianVectorFieldSystem.
hamiltonian_vector_field(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> Union{HamiltonianVectorField{CTFlows.Systems.HVFIpFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}, HamiltonianVectorField{CTFlows.Systems.HVFOoPFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}}Return the (symplectic) Hamiltonian vector field X_H = (∂H/∂p, -∂H/∂x) of a Hamiltonian flow, as a CTBase.Data.HamiltonianVectorField. Delegates to the system-level CTFlows.Systems.hamiltonian_vector_field, so it also covers flows built from a pseudo-Hamiltonian (or an OCP) and a control law (:partial / :total), whose Hamiltonian is a CTBase.Data.ComposedHamiltonian.
See also: CTFlows.Systems.hamiltonian, CTFlows.Systems.vector_field.
hamiltonian_vector_field(
flow::Flow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.HamiltonianDynamics, <:CTFlows.Systems.HamiltonianSystem{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, H} where H<:AbstractHamiltonian{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence}};
inplace
) -> Union{HamiltonianVectorField{CTFlows.Systems.HVFIpFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}, HamiltonianVectorField{CTFlows.Systems.HVFOoPFunctor{H, B}} where {H<:AbstractHamiltonian, B<:CTBase.Differentiation.AbstractADBackend}}Get the Hamiltonian vector field from a HamiltonianFlow with an AD-backed system.
Delegates to the system-level getter. The inplace parameter controls whether the returned closure writes results in-place.
See also: CTFlows.Flows.HamiltonianFlow, CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.hamiltonian_vector_field
hamiltonian_vector_field(
flow::Flow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.HamiltonianDynamics, <:CTFlows.Systems.HamiltonianVectorFieldSystem{<:Function, TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence}}
) -> HamiltonianVectorFieldGet the Hamiltonian vector field from a HamiltonianFlow with an HVF-backed system.
Returns the pre-stored vector field from the HamiltonianVectorFieldSystem without any recomputation.
See also: CTFlows.Flows.HamiltonianFlow, CTFlows.Systems.HamiltonianVectorFieldSystem, CTFlows.Systems.hamiltonian_vector_field
CTFlows.Systems.vector_field Function
vector_field(
sys::CTFlows.Systems.VectorFieldSystem
) -> AbstractVectorFieldReturn the underlying vector field of a VectorFieldSystem, as a CTBase.Data.AbstractVectorField — the field X(t, x, v) integrated by the state flow.
See also: CTFlows.Systems.VectorFieldSystem, CTFlows.Systems.hamiltonian_vector_field.
vector_field(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> AnyReturn the vector field of a flow: the (symplectic) Hamiltonian vector field X_H for a Hamiltonian flow. Alias of CTFlows.Systems.hamiltonian_vector_field on the Hamiltonian side; see the StateDynamics method for state flows.
See also: CTFlows.Systems.hamiltonian_vector_field.
vector_field(f::CTFlows.Flows.AbstractStateFlow) -> AnyReturn the underlying vector field X(t, x, v) of a state flow, as a CTBase.Data.AbstractVectorField. Delegates to the system-level CTFlows.Systems.vector_field.
See also: CTFlows.Systems.hamiltonian_vector_field.
CTFlows.Systems.get_hamiltonian_gradient Function
get_hamiltonian_gradient(
sys::Union{CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.PseudoHamiltonianSystem};
ad_backend
) -> CTFlows.Systems.HamiltonianGradientReturn a CTFlows.Systems.HamiltonianGradient functor (t, x, p, v) -> (∂H/∂x, ∂H/∂p) for the true Hamiltonian of an AD-backed Hamiltonian system. For a PseudoHamiltonianSystem (or a :total HamiltonianSystem), the gradient is the total derivative — it differentiates through the control law.
The ad_backend keyword selects the AD backend used to differentiate; it defaults to the system's own backend but can be overridden (e.g. to use reverse mode for the gradient).
See also: CTFlows.Systems.hamiltonian, CTFlows.Systems.get_variable_gradient.
get_hamiltonian_gradient(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> CTFlows.Systems.HamiltonianGradientReturn a callable (t, x, p, v) -> (∂H/∂x, ∂H/∂p) for the true Hamiltonian of a Hamiltonian flow. Delegates to CTFlows.Systems.get_hamiltonian_gradient; the ad_backend keyword (default: the system's backend) selects the AD backend.
See also: CTFlows.Systems.hamiltonian, CTFlows.Systems.get_variable_gradient.
CTFlows.Systems.get_variable_gradient Function
get_variable_gradient(
sys::Union{CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.PseudoHamiltonianSystem};
ad_backend
) -> CTFlows.Systems.HamiltonianVariableGradientReturn a CTFlows.Systems.HamiltonianVariableGradient functor (t, x, p, v) -> ∂H/∂v for the true Hamiltonian of an AD-backed Hamiltonian system — the same quantity (before negation) that drives the augmented variable-costate equation ṗv = -∂H/∂v.
The ad_backend keyword selects the AD backend (default: the system's own backend).
See also: CTFlows.Systems.get_hamiltonian_gradient.
get_variable_gradient(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> CTFlows.Systems.HamiltonianVariableGradientReturn a callable (t, x, p, v) -> ∂H/∂v for the true Hamiltonian of a Hamiltonian flow — the quantity (before negation) driving ṗv = -∂H/∂v. Delegates to CTFlows.Systems.get_variable_gradient; the ad_backend keyword (default: the system's backend) selects the AD backend.
See also: CTFlows.Systems.get_hamiltonian_gradient.
CTFlows.Systems.get_pseudo_hamiltonian_gradient Function
get_pseudo_hamiltonian_gradient(
sys::Union{CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.PseudoHamiltonianSystem};
ad_backend
) -> CTFlows.Systems.PseudoHamiltonianGradient{H} where H<:PseudoHamiltonianReturn a CTFlows.Systems.PseudoHamiltonianGradient functor (t, x, p, u, v) -> (∂H̃/∂x, ∂H̃/∂p) for the pseudo-Hamiltonian, differentiated at fixed control u. Available for a PseudoHamiltonianSystem and for a :total HamiltonianSystem wrapping a ComposedHamiltonian.
The ad_backend keyword selects the AD backend (default: the system's own backend).
See also: CTFlows.Systems.pseudo_hamiltonian, CTFlows.Systems.get_pseudo_variable_gradient.
get_pseudo_hamiltonian_gradient(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> CTFlows.Systems.PseudoHamiltonianGradient{H} where H<:PseudoHamiltonianReturn a callable (t, x, p, u, v) -> (∂H̃/∂x, ∂H̃/∂p) for the pseudo-Hamiltonian of a Hamiltonian flow (differentiated at fixed control), when available. Delegates to CTFlows.Systems.get_pseudo_hamiltonian_gradient; the ad_backend keyword (default: the system's backend) selects the AD backend.
See also: CTFlows.Systems.pseudo_hamiltonian, CTFlows.Systems.get_pseudo_variable_gradient.
CTFlows.Systems.get_pseudo_variable_gradient Function
get_pseudo_variable_gradient(
sys::Union{CTFlows.Systems.HamiltonianSystem, CTFlows.Systems.PseudoHamiltonianSystem};
ad_backend
) -> CTFlows.Systems.PseudoHamiltonianVariableGradient{H} where H<:PseudoHamiltonianReturn a CTFlows.Systems.PseudoHamiltonianVariableGradient functor (t, x, p, u, v) -> ∂H̃/∂v for the pseudo-Hamiltonian, differentiated at fixed control u.
The ad_backend keyword selects the AD backend (default: the system's own backend).
See also: CTFlows.Systems.get_pseudo_hamiltonian_gradient.
get_pseudo_variable_gradient(
f::CTFlows.Flows.AbstractHamiltonianFlow;
kwargs...
) -> CTFlows.Systems.PseudoHamiltonianVariableGradient{H} where H<:PseudoHamiltonianReturn a callable (t, x, p, u, v) -> ∂H̃/∂v for the pseudo-Hamiltonian of a Hamiltonian flow (differentiated at fixed control), when available. Delegates to CTFlows.Systems.get_pseudo_variable_gradient; the ad_backend keyword (default: the system's backend) selects the AD backend.
CTFlows.MultiPhase.MultiPhaseFlow Type
struct MultiPhaseFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, FS<:Tuple, ST<:(Vector{<:Real}), J<:(Vector)} <: CTFlows.Flows.AbstractFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait}Concrete multi-phase flow combining multiple flows of the same dynamics family with switching times and optional jumps.
The dynamics axis is encoded in D, following the same pattern as Flow:
D = StateDynamics→ state multi-phase flow (aliasMultiPhaseStateFlow)D = HamiltonianDynamics→ Hamiltonian multi-phase flow (aliasMultiPhaseHamiltonianFlow)
flows is a heterogeneous tuple, lifting the previous homogeneous-S/I constraint: phases may wrap systems and integrators of different concrete types.
Type Parameters
TD <: TimeDependence: Time dependence trait (Autonomous or NonAutonomous)VD <: VariableDependence: Variable dependence trait (Fixed or NonFixed)D <: AbstractDynamicsTrait: Dynamics trait (StateDynamicsorHamiltonianDynamics)FS <: Tuple: Tuple ofAbstractFlow{TD,VD,D}(heterogeneous allowed)ST <: Vector{<:Real}: Type of the switching times vectorJ <: Vector{<:Any}: Type of the jumps vector
Fields
flows::FS: Tuple of flows for each phaseswitching_times::ST: Switching times between phasesjumps::J: Optional jump functions applied at switching times
See also: CTFlows.MultiPhase.MultiPhaseStateFlow, CTFlows.MultiPhase.MultiPhaseHamiltonianFlow, CTFlows.Flows.Flow.
CTFlows.MultiPhase.MultiPhaseStateFlow Type
struct MultiPhaseFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.StateDynamics, FS<:Tuple, ST<:(Vector{<:Real}), J<:(Vector)} <: CTFlows.Flows.AbstractFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.StateDynamics}Alias for state multi-phase flows: MultiPhaseFlow{TD,VD,StateDynamics,FS,ST,J}.
See also: CTFlows.MultiPhase.MultiPhaseFlow, CTFlows.MultiPhase.MultiPhaseHamiltonianFlow.
CTFlows.MultiPhase.MultiPhaseHamiltonianFlow Type
struct MultiPhaseFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.HamiltonianDynamics, FS<:Tuple, ST<:(Vector{<:Real}), J<:(Vector)} <: CTFlows.Flows.AbstractFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, CTBase.Traits.HamiltonianDynamics}Alias for Hamiltonian multi-phase flows: MultiPhaseFlow{TD,VD,HamiltonianDynamics,FS,ST,J}.
See also: CTFlows.MultiPhase.MultiPhaseFlow, CTFlows.MultiPhase.MultiPhaseStateFlow.
CTFlows.MultiPhase.AnyMultiPhaseFlow Type
struct MultiPhaseFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait, FS<:Tuple, ST<:(Vector{<:Real}), J<:(Vector)} <: CTFlows.Flows.AbstractFlow{TD<:CTBase.Traits.TimeDependence, VD<:CTBase.Traits.VariableDependence, D<:CTBase.Traits.AbstractDynamicsTrait}Type alias for any multi-phase flow.
See also: CTFlows.MultiPhase.MultiPhaseStateFlow, CTFlows.MultiPhase.MultiPhaseHamiltonianFlow.
CTFlows.MultiPhase.n_phases Function
n_phases(mpf::MultiPhaseFlow) -> Int64Return the number of phases in a multi-phase flow.
Arguments
mpf::MultiPhaseFlow: The multi-phase flow.
Returns
Int: Number of phases.
See also: CTFlows.MultiPhase.get_flow, CTFlows.MultiPhase.get_switching_time.
CTFlows.MultiPhase.get_flow Function
get_flow(mpf::MultiPhaseFlow, i::Int64) -> AnyReturn the flow for a specific phase.
Arguments
mpf::MultiPhaseFlow: The multi-phase flow.i::Int: Phase index (1-based).
Returns
AbstractFlow: The flow for phasei.
See also: CTFlows.MultiPhase.n_phases, CTFlows.MultiPhase.get_switching_time.
CTFlows.MultiPhase.get_flows Function
get_flows(f::CTFlows.Flows.AbstractFlow) -> TupleGet the flows from a single-phase flow as a 1-tuple.
get_flows(mpf::MultiPhaseFlow) -> TupleGet the flows tuple from a multi-phase flow.
CTFlows.MultiPhase.get_switching_time Function
get_switching_time(mpf::MultiPhaseFlow, i::Int64) -> RealReturn the switching time at a specific phase boundary.
Arguments
mpf::MultiPhaseFlow: The multi-phase flow.i::Int: Phase index (1-based). Returns the switching time between phaseiandi+1.
Returns
Real: The switching time.
See also: CTFlows.MultiPhase.n_phases, CTFlows.MultiPhase.get_flow.
CTFlows.MultiPhase.get_switching_times Function
get_switching_times(
_::CTFlows.Flows.AbstractFlow
) -> Vector{<:Real}Get the switching times from a single-phase flow (empty vector).
get_switching_times(mpf::MultiPhaseFlow) -> Vector{<:Real}Get the switching times from a multi-phase flow.
CTFlows.MultiPhase.get_jump Function
get_jump(mpf::MultiPhaseFlow, i::Int64) -> AnyReturn the jump function at a specific phase boundary.
Arguments
mpf::MultiPhaseFlow: The multi-phase flow.i::Int: Phase index (1-based). Returns the jump applied after phasei.
Returns
Union{Nothing, Function, Tuple}: The jump function, ornothingif no jump is defined.
See also: CTFlows.MultiPhase.n_phases, CTFlows.MultiPhase.get_flow.
CTFlows.MultiPhase.get_jumps Function
get_jumps(_::CTFlows.Flows.AbstractFlow) -> VectorGet the jumps from a single-phase flow (empty vector).
get_jumps(mpf::MultiPhaseFlow) -> VectorGet the jumps from a multi-phase flow.
CTSolvers.Integrators.SciML Type
struct SciML{P<:Union{CPU, GPU}, O<:CTBase.Strategies.StrategyOptions, OP<:Dict{Symbol, Any}, OT<:Dict{Symbol, Any}} <: CTSolvers.Integrators.AbstractSciMLIntegratorGeneric SciML ODE integrator strategy.
Wraps any SciML algorithm (e.g. Tsit5, Rodas4) through a unified CTBase.Strategies-backed option system. The full implementation (metadata, builder and solve) is provided by the CTSolversSciMLIntegrator package extension; this file declares the type and stubs that throw ExtensionError until the extension is loaded.
Parameterized on the execution device P:
SciML{CPU}: CPU execution (default);SciML{GPU}: GPU execution (state on device arrays, e.g.CuArray).
SciML(...) builds a SciML{CPU} — the device parameterization is fully backward compatible with existing call sites.
To activate the extension, load any of:
using OrdinaryDiffEqTsit5(minimal)using OrdinaryDiffEqusing DifferentialEquations
Fields
options::CTBase.Strategies.StrategyOptions: Validated option bundle.options_point::Dict{Symbol, Any}: Pre-computed options for point (final-state) integration.options_trajectory::Dict{Symbol, Any}: Pre-computed options for trajectory integration.
CTSolvers.Integrators.AbstractIntegrator Type
abstract type AbstractIntegrator <: CTBase.Strategies.AbstractStrategyAbstract strategy for solving ODE Cauchy problems.
An AbstractIntegrator is a strategy that integrates an ODE problem over a time span. It inherits the CTBase.Strategies strategy contract:
Type-Level Contract (Static Metadata)
Methods defined on the type that describe what the integrator can do:
Strategies.id(::Type{<:S}) → Symbol: Unique identifier for routing and introspection.Strategies.metadata(::Type{<:S}) → StrategyMetadata: Option specifications and validation rules.
Instance-Level Contract (Configured State)
Methods defined on instances that provide the actual configuration:
Strategies.options(s::S) → StrategyOptions: Current option values with provenance tracking.
Concrete Implementation
Concrete integrators implement, typically in a backend extension:
CommonSolve.solve(prob, integrator::S; options, unsafe): integrate the (external) ODE problemprobwith the resolvedoptions, returning anCTSolvers.Integrators.AbstractIntegrationResult.CTSolvers.Integrators.merge: concatenate a sequence of integration results (multi-phase trajectories).
The cached per-call option dictionaries are exposed through the CTSolvers.Integrators.options_point / CTSolvers.Integrators.options_trajectory accessors.
See also: CTSolvers.Integrators.SciML, CTSolvers.Integrators.AbstractIntegrationResult.
CTSolvers.Integrators.AbstractIntegrationResult Type
abstract type AbstractIntegrationResultAbstract supertype for integration results produced by integrators.
This abstraction decouples the consumer (e.g. a trajectory layer) from the concrete types of the underlying ODE solvers (e.g. SciML). Integrators must produce a subtype of AbstractIntegrationResult which provides semantic accessors.
Interface Requirements
Subtypes must implement:
final_state(r::SubType): Return the final state vector.times(r::SubType): Return the vector of time points.evaluate_at(r::SubType, t::Real): Evaluate the continuous solution at timet.status(r::SubType): Return the termination status as aSymbol.successful(r::SubType): Return whether the integration succeeded.
See also: CTSolvers.Integrators.final_state, CTSolvers.Integrators.times, CTSolvers.Integrators.evaluate_at, CTSolvers.Integrators.status, CTSolvers.Integrators.successful.
CTSolvers.Integrators.final_state Function
final_state(r::AbstractIntegrationResult) -> AnyReturn the final state vector from the integration result.
Arguments
r::AbstractIntegrationResult: The integration result.
Throws
CTBase.Exceptions.NotImplemented: If not implemented by the concrete type.
See also: CTSolvers.Integrators.AbstractIntegrationResult, CTSolvers.Integrators.times, CTSolvers.Integrators.evaluate_at.
final_state(
sol::CTFlows.Trajectories.VectorFieldTrajectory
) -> AnyReturn the final state from the solution, coerced to a scalar for a 1-D state (issue #357) — see CTFlows.Systems._coerce_state.
Arguments
sol::VectorFieldTrajectory: The vector field solution.
Returns
- The final state from the integration result.
See also: CTFlows.Systems._coerce_state, CTSolvers.Integrators.AbstractIntegrationResult, CTSolvers.Integrators.final_state.
final_state(
sol::CTFlows.Trajectories.HamiltonianVectorFieldTrajectory
) -> Tuple{Any, Any}Return the raw final ODE state vector [xf; pf] from the integration result.
Delegates directly to the underlying integration result without splitting. Callers that need the split form should use _ham_split_solution explicitly.
Arguments
sol::HamiltonianVectorFieldTrajectory: The Hamiltonian vector field solution.
Returns
AbstractVector: The concatenated final state[xf; pf].
See also: CTSolvers.Integrators.AbstractIntegrationResult, CTSolvers.Integrators.final_state.
final_state(
sol::CTFlows.Trajectories.StateFlowTrajectory
) -> AnyReturn the final state of a StateFlowTrajectory.
final_state(
r::CTSolversSciMLIntegrator.SciMLIntegrationResult
) -> AnyReturn the final state vector from the SciML ODE solution.
CTSolvers.Integrators.evaluate_at Function
evaluate_at(r::AbstractIntegrationResult, t::Real) -> AnyEvaluate the integration result at a specific time t.
Arguments
r::AbstractIntegrationResult: The integration result.t::Real: The time at which to evaluate the solution.
Throws
CTBase.Exceptions.NotImplemented: If not implemented by the concrete type.
See also: CTSolvers.Integrators.AbstractIntegrationResult, CTSolvers.Integrators.final_state, CTSolvers.Integrators.times.
evaluate_at(
r::CTSolversSciMLIntegrator.SciMLIntegrationResult,
t::Real
) -> AnyEvaluate the SciML ODE solution at a specific time t using its interpolation.