propagation
Trajectory propagation for trajectory optimization.
This module provides implementations of trajectory propagation methods that simulate the nonlinear system dynamics forward in time. Propagation is used to evaluate solution quality, verify constraint satisfaction, and generate high-fidelity trajectories from optimized control sequences.
Current Implementations
Forward Simulation: The default propagation method that integrates the nonlinear dynamics forward in time using adaptive or fixed-step numerical integration (via Diffrax). Supports both ZOH and FOH control interpolation schemes.
Planned Architecture (ABC-based):
A base class will be introduced to enable pluggable propagation methods. This will enable users to implement custom propagation methods. Future propagators will implement the Propagator interface:
# propagation/base.py (planned):
class Propagator(ABC):
def __init__(self, integrator: Integrator):
'''Initialize with a numerical integrator.'''
self.integrator = integrator
@abstractmethod
def propagate(self, dynamics, x0, u_traj, time_grid) -> Array:
'''Propagate trajectory forward in time.
Args:
dynamics: Continuous-time dynamics object
x0: Initial state
u_traj: Control trajectory
time_grid: Time points for dense output
Returns:
State trajectory evaluated at time_grid points
'''
...
get_propagation_solver(state_dot: Dynamics, settings: Config)
¶
Create a propagation solver function.
This function creates a solver that propagates the system state using the specified dynamics and settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dot
|
callable
|
Function computing state derivatives. |
required |
settings
|
Config
|
Configuration settings for propagation. |
required |
param_map
|
dict
|
Mapping of parameter names to values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A function that solves the propagation problem. |
Source code in openscvx/propagation/propagation.py
prop_aug_dy(tau: float, x: np.ndarray, u_current: np.ndarray, u_next: np.ndarray, tau_init: float, node: int, idx_s: int, state_dot: callable, dis_type: str, N: int, params) -> np.ndarray
¶
Compute the augmented dynamics for propagation.
This function computes the time-scaled dynamics for propagating the system state, taking into account the discretization type (ZOH or FOH) and time dilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tau
|
float
|
Current normalized time in [0,1]. |
required |
x
|
ndarray
|
Current state vector. |
required |
u_current
|
ndarray
|
Control input at current node. |
required |
u_next
|
ndarray
|
Control input at next node. |
required |
tau_init
|
float
|
Initial normalized time. |
required |
node
|
int
|
Current node index. |
required |
idx_s
|
int
|
Index of time dilation variable in control vector. |
required |
state_dot
|
callable
|
Function computing state derivatives. |
required |
dis_type
|
str
|
Discretization type ("ZOH" or "FOH"). |
required |
N
|
int
|
Number of nodes in trajectory. |
required |
params
|
Dictionary of additional parameters passed to state_dot. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Time-scaled state derivatives. |
Source code in openscvx/propagation/propagation.py
propagate_trajectory_results(params: dict, settings: Config, result: OptimizationResults, propagation_solver: callable) -> OptimizationResults
¶
Propagate the optimal trajectory and compute additional results.
This function takes the optimal control solution and propagates it through the nonlinear dynamics to compute the actual state trajectory and other metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
System parameters. |
required |
settings
|
Config
|
Configuration settings. |
required |
result
|
OptimizationResults
|
Optimization results object. |
required |
propagation_solver
|
callable
|
Function for propagating the system state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OptimizationResults |
OptimizationResults
|
Updated results object containing: - t_full: Full time vector - x_full: Full state trajectory - u_full: Full control trajectory - cost: Computed cost - ctcs_violation: CTCS constraint violation |
Source code in openscvx/propagation/post_processing.py
s_to_t(x: np.ndarray, u: np.ndarray, settings: Config)
¶
Convert normalized time s to real time t.
This function converts the normalized time variable s to real time t based on the discretization type and time dilation factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
State trajectory array, shape (N, n_states). |
required |
u
|
ndarray
|
Control trajectory array, shape (N, n_controls). |
required |
settings
|
Config
|
Configuration settings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of real time points. |
Source code in openscvx/propagation/propagation.py
simulate_nonlinear_time(params, x, u, tau_vals, t, settings, propagation_solver)
¶
Simulate the nonlinear system dynamics over time.
This function simulates the system dynamics using the optimal control sequence and returns the resulting state trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
System parameters. |
required | |
x
|
State trajectory array, shape (N, n_states). |
required | |
u
|
Control trajectory array, shape (N, n_controls). |
required | |
tau_vals
|
ndarray
|
Normalized time points for simulation. |
required |
t
|
ndarray
|
Real time points. |
required |
settings
|
Configuration settings. |
required | |
propagation_solver
|
callable
|
Function for propagating the system state. |
required |
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Simulated state trajectory. |
Source code in openscvx/propagation/propagation.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
t_to_tau(u: np.ndarray, t, t_nodal, settings: Config)
¶
Convert real time t to normalized time tau.
This function converts real time t to normalized time tau and interpolates the control inputs accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Control trajectory array, shape (N, n_controls). |
required |
t
|
ndarray
|
Real time points. |
required |
t_nodal
|
ndarray
|
Nodal time points. |
required |
settings
|
Config
|
Configuration settings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(tau, u_interp) where tau is normalized time and u_interp is interpolated controls. |