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, discretizer: Discretizer) -> callable
¶
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
|
Dynamics
|
Dynamics object containing state derivative function. |
required |
settings
|
Config
|
Configuration settings for propagation. |
required |
discretizer
|
Discretizer
|
Discretizer instance (used for |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable |
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, state_dot: callable, foh_mask: np.ndarray, N: int, params: dict) -> np.ndarray
¶
Compute the augmented dynamics for propagation.
This function computes the time-dilated dynamics for propagating the system
state, taking into account the per-control hold type (ZOH or FOH). The
time-dilation multiplication is already included in state_dot
symbolically.
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 |
state_dot
|
callable
|
Function computing time-dilated state derivatives. |
required |
foh_mask
|
ndarray
|
Float array of shape |
required |
N
|
int
|
Number of nodes in trajectory. |
required |
params
|
dict
|
Dictionary of additional parameters passed to state_dot. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Time-dilated state derivatives. |
Source code in openscvx/propagation/propagation.py
propagate_trajectory_results(params: dict, settings: Config, result: OptimizationResults, propagation_solver: callable, dynamics_discrete: Optional[Callable] = None, algebraic_prop: Optional[dict] = None, discretizer: Optional[Discretizer] = None) -> 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.
When states_prop includes propagation-only states (e.g. via dynamics_prop /
states_prop), x_full has shape (n_times, n_prop_states) with
n_prop_states > n_opt_states. The discrete dynamics and cost use only the
optimization-state portion; propagation-only states are preserved from the last
propagated step and included in trajectory.
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 |
dynamics_discrete
|
callable
|
Discrete dynamics map used to apply node-wise impulsive/discrete updates before continuous propagation. |
None
|
algebraic_prop
|
dict
|
Dictionary mapping output names to vmapped JAX functions. |
None
|
discretizer
|
Optional[Discretizer]
|
Discretizer instance (used for |
None
|
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 - trajectory: Dict containing each variables values at full propagation fidelity |
Source code in openscvx/propagation/post_processing.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
s_to_t(x: np.ndarray, u: np.ndarray, settings: Config, discretizer: Discretizer) -> list[float]
¶
Convert normalized time s to real time t.
This function converts the normalized time variable s to real time t based on the hold type of the time-dilation control.
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 |
discretizer
|
Discretizer
|
Discretizer instance (used for |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
list[float]: List of real time points. |
Source code in openscvx/propagation/propagation.py
simulate_nonlinear_time(params: dict, x: np.ndarray, u: np.ndarray, tau_vals: np.ndarray, t: np.ndarray, settings: Config, propagation_solver: callable, dynamics_discrete: Optional[Callable] = None) -> np.ndarray
¶
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
|
dict
|
System parameters. |
required |
x
|
ndarray
|
State trajectory array, shape (N, n_states). |
required |
u
|
ndarray
|
Control trajectory array, shape (N, n_controls). |
required |
tau_vals
|
ndarray
|
Normalized time points for simulation. |
required |
t
|
ndarray
|
Real time points. |
required |
settings
|
Config
|
Configuration settings. |
required |
propagation_solver
|
callable
|
Function for propagating the system state. |
required |
dynamics_discrete
|
Optional[Callable]
|
Optional discrete dynamics map f_discrete(x, u, node, params) used to apply impulsive/discrete updates at each node before continuous propagation. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Simulated state trajectory. |
Source code in openscvx/propagation/propagation.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
t_to_tau(u: np.ndarray, t: np.ndarray, t_nodal: np.ndarray, settings: Config, discretizer: Discretizer) -> tuple[np.ndarray, np.ndarray]
¶
Convert real time t to normalized time tau.
This function converts real time t to normalized time tau and interpolates the control inputs according to each control's hold type.
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 |
discretizer
|
Discretizer
|
Discretizer instance (used for |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: (tau, u_interp) where tau is normalized time and u_interp is interpolated controls. |