Public API
This page lists exported symbols of CTFlows.Common.
From CTFlows.Common
CTFlows.Common [Module]
CTFlows.Common — Module
CommonShared utilities and types for CTFlows.
This module provides fallback implementations for grid invariance (IND) support:
deepvalue(x::Real)— Base case for extracting primal valuesreal_norm(u::Real, t)— Base case for internal norm computation
ForwardDiff-specific implementations are provided in CTFlowsForwardDiff when ForwardDiff is loaded.
ODEParameters [Struct]
CTFlows.Common.ODEParameters — Type
struct ODEParameters{V}Wrapper type for parameters passed through SciML's p slot.
This type formalizes the contract for what transits in the ODE problem's parameter slot. For CTFlows, the primary content is the variable parameter for NonFixed systems (or nothing for Fixed systems).
The wrapper makes the contract explicit and extensible — additional fields can be added later (callbacks, extra data) without breaking existing code.
Fields
variable::V: The variable parameter (ornothingforFixedsystems).
Constructor Validation
Vcan beNothing(forFixedsystems) or any concrete type (forNonFixed).- No validation is performed at construction — the system's
VariableDependencedetermines whethervariableshould be used.
Example
using CTFlows.Common
# Fixed system: variable is nothing
params_fixed = ODEParameters(nothing)
# NonFixed system: variable is a value
params_nonfixed = ODEParameters(0.5)
# NonFixed system: variable is a vector
params_vector = ODEParameters([1.0, 2.0])Notes
- This type is used exclusively by the SciML extension to wrap the variable before passing it to
ODEProblem. - The RHS functor reads
variable(p)to access the actual variable value.
See also: CTBase.Traits.VariableDependence, CTBase.Traits.Fixed, CTBase.Traits.NonFixed.
__hvf_inplace [Function]
CTFlows.Common.__hvf_inplace — Function
__hvf_inplace() -> Bool
Default value for in-place flag in hamiltonianvectorfield getter.
Returns false by default, meaning the getter returns out-of-place vector fields unless specified otherwise.
__unsafe [Function]
CTFlows.Common.__unsafe — Function
__unsafe() -> Bool
Default value for unsafe flag in integration functions.
Returns false by default, meaning ODE solver retcodes are checked and failures throw exceptions unless explicitly bypassed.
__variable [Function]
CTFlows.Common.__variable — Function
__variable() -> CTBase.Core.NotProvidedType
Default value for variable parameter in user-facing API calls.
Returns CTBase.Core.NotProvided by default, meaning the variable parameter is optional unless required by the system's trait (e.g., NonFixed systems).
See also: CTBase.Traits.VariableDependence, CTBase.Traits.Fixed, CTBase.Traits.NonFixed.
__variable_costate [Function]
CTFlows.Common.__variable_costate — Function
__variable_costate() -> Bool
Default value for variable_costate flag in Hamiltonian flow calls.
Returns false by default, meaning the flow does not integrate the augmented variable costate equation ṗᵥ = -∂H/∂v unless explicitly requested.
Returns
Bool: The default value for thevariable_costateparameter.
See also: CTFlows.Configs.AugmentedHamiltonianEndPointConfig.
deepvalue [Function]
CTFlows.Common.deepvalue — Function
deepvalue(x::Number) -> Number
Extract the primal value from a number. Base case for scalar numbers.
This is a fallback implementation used when AD backends are not loaded. ForwardDiff-specific implementations are provided in CTFlowsForwardDiff for recursive extraction from nested dual numbers.
Arguments
x::Number: A number (e.g.,Float64,ComplexF64).
Returns
Number: The input value unchanged for real and complex numbers.
Example
julia> using CTFlows.Common
julia> deepvalue(3.14)
3.14
julia> deepvalue(1.0 + 2.0im)
1.0 + 2.0imNotes
- For
ForwardDiff.Dualnumbers, the more specific method inCTFlowsForwardDiffrecursively extracts the primal value viadeepvalue(value(x)). - This method serves as the base case for all
Numbersubtypes not handled by extensions.
See also: CTFlows.Common.real_norm.
deepvalue(x::ForwardDiff.Dual) -> Number
Recursively extract the primal (real) value from a ForwardDiff dual number.
Handles nested dual numbers for higher-order differentiation (e.g., second-order derivatives where the partials themselves are dual numbers). This extends the fallback Common.deepvalue(x::Real) to support ForwardDiff.
Arguments
x::ForwardDiff.Dual: A ForwardDiff dual number (possibly nested).
Returns
Real: The primal (Float64) part of the dual number.
Example
julia> using ForwardDiff
julia> d1 = ForwardDiff.Dual{:Tag}(3.0, 1.0)
Dual{:Tag}(3.0, 1.0)
julia> CTFlowsForwardDiff.deepvalue(d1)
3.0
julia> d2 = ForwardDiff.Dual{:Tag2}(d1, d1) # Nested dual
Dual{:Tag2}(Dual{:Tag}(3.0, 1.0), Dual{:Tag}(3.0, 1.0))
julia> CTFlowsForwardDiff.deepvalue(d2)
3.0See also: Common.deepvalue, real_norm
real_norm [Function]
CTFlows.Common.real_norm — Function
real_norm(u::Number, t) -> Any
Compute the internal norm for a scalar number.
This is a fallback implementation used when AD backends are not loaded. ForwardDiff-specific implementations are provided in CTFlowsForwardDiff.
Arguments
u::Number: A scalar number (real or complex).t: Time parameter (unused but required by SciML interface).
Returns
Number: The absolute value for real numbers, or magnitude for complex numbers.
Example
julia> using CTFlows.Common
julia> real_norm(3.0, 0.0)
3.0
julia> real_norm(3.0 + 4.0im, 0.0)
5.0Notes
- For real numbers, returns
abs(u). - For complex numbers, returns
abs(u)(the magnitude). - Used by SciML integrators for step-size control in grid-invariant computations.
See also: CTFlows.Common.deepvalue.
real_norm(u::ForwardDiff.Dual, t) -> Any
Compute the internal norm for a scalar ForwardDiff dual number using only its primal part.
This extends the fallback Common.real_norm(u::Real, t) to support ForwardDiff dual numbers, ensuring grid invariance (IND) when integrating ODEs with dual numbers.
Arguments
u::ForwardDiff.Dual: A scalar dual number.t: Time parameter (unused but required by SciML interface).
Returns
Real: The absolute value of the primal part.
See also: Common.real_norm, deepvalue
real_norm(u::AbstractArray, t) -> Any
Compute the internal norm for adaptive step-size control using only the primal parts of dual numbers.
This function ensures grid invariance (IND) when integrating ODEs with ForwardDiff dual numbers: the adaptive time grid chosen by the solver is identical whether integrating with real numbers or dual numbers. Without this, the step-size controller would make decisions based on dual values, breaking grid invariance.
This implementation uses Common.deepvalue to extract primal parts and DiffEqBase.ODE_DEFAULT_NORM to compute the norm. When ForwardDiff is loaded, Common.deepvalue is extended to handle dual numbers via CTFlowsForwardDiff.
Arguments
u::AbstractArray: State vector (may contain dual numbers).t: Time parameter (unused but required by SciML interface).
Returns
Real: The norm computed on the primal parts only.
Example
julia> using ForwardDiff
julia> u_real = [1.0, 2.0, 3.0]
julia> u_dual = ForwardDiff.Dual{:T}.(u_real, ones(3))
julia> CTFlowsSciMLIntegrator.real_norm(u_real, 0.0) ≈ CTFlowsSciMLIntegrator.real_norm(u_dual, 0.0)
trueSee also: CTFlows.Common.deepvalue, CTFlows.Common.real_norm.
variable [Function]
CTFlows.Common.variable — Function
variable(p::CTFlows.Common.ODEParameters) -> Any
Accessor for the variable field of ODEParameters.
Returns the variable parameter stored in the ODEParameters wrapper. For Fixed systems, this is nothing. For NonFixed systems, this is the actual variable value (scalar or vector).
Arguments
p::ODEParameters: The ODEParameters instance.
Returns
- The variable value (or
nothingfor Fixed systems).
Example
julia> using CTFlows.Common
julia> params_fixed = ODEParameters(nothing)
ODEParameters{Nothing}(nothing)
julia> variable(params_fixed)
nothing
julia> params_nonfixed = ODEParameters(0.5)
ODEParameters{Float64}(0.5)
julia> variable(params_nonfixed)
0.5See also: CTFlows.Common.ODEParameters, CTBase.Traits.VariableDependence.