integrators
Numerical integration schemes for trajectory optimization.
This module provides implementations of numerical integrators used for simulating continuous-time dynamics.
Current Implementations
RK45 Integration: Explicit Runge-Kutta-Fehlberg method (4th/5th order) with both fixed-step and adaptive implementations via Diffrax. Supports a variety of explicit and implicit ODE solvers through the Diffrax backend (Dopri5/8, Tsit5, KenCarp3/4/5, etc.).
Planned Architecture (ABC-based):
A base class will be introduced to enable pluggable integrator implementations. This will enable users to implement custom integrators. Future integrators will implement the Integrator interface:
# integrators/base.py (planned):
class Integrator(ABC):
@abstractmethod
def step(self, f: Callable, x: Array, u: Array, t: float, dt: float) -> Array:
'''Take one integration step from state x at time t with step dt.'''
...
@abstractmethod
def integrate(self, f: Callable, x0: Array, u_traj: Array,
t_span: tuple[float, float], num_steps: int) -> Array:
'''Integrate over a time span with given control trajectory.'''
...
rk45_step(f: Callable[[jnp.ndarray, jnp.ndarray, Any], jnp.ndarray], t: jnp.ndarray, y: jnp.ndarray, h: float, *args: Any) -> jnp.ndarray
¶
Perform a single RK45 (Runge-Kutta-Fehlberg) integration step.
This implements the classic Dorman-Prince coefficients for an explicit 4(5) method, returning the fourth-order estimate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[ndarray, ndarray, Any], ndarray]
|
ODE right-hand side; signature f(t, y, *args) -> dy/dt. |
required |
t
|
ndarray
|
Current time. |
required |
y
|
ndarray
|
Current state vector. |
required |
h
|
float
|
Step size. |
required |
*args
|
Any
|
Additional arguments passed to |
()
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Next state estimate at t + h. |
Source code in openscvx/integrators/runge_kutta.py
solve_ivp_rk45(f: Callable[[jnp.ndarray, jnp.ndarray, Any], jnp.ndarray], tau_final: float, y_0: jnp.ndarray, args: tuple, tau_0: float = 0.0, num_substeps: int = 50, is_not_compiled: bool = False) -> jnp.ndarray
¶
Solve an initial-value ODE problem using fixed-step RK45 integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[ndarray, ndarray, Any], ndarray]
|
ODE right-hand side; signature f(t, y, *args) -> dy/dt. |
required |
tau_final
|
float
|
Final integration time. |
required |
y_0
|
ndarray
|
Initial state at tau_0. |
required |
args
|
tuple
|
Extra arguments to pass to |
required |
tau_0
|
float
|
Initial time. Defaults to 0.0. |
0.0
|
num_substeps
|
int
|
Number of output time points. Defaults to 50. |
50
|
is_not_compiled
|
bool
|
If True, use Python loop instead of
JAX |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Array of shape (num_substeps, state_dim) with solution at each time. |