base
Base class for dynamics linearization and discretization.
This module defines the abstract interface for discretizers — components that convert continuous-time nonlinear dynamics into discrete-time linear approximations around a reference trajectory.
Discretization and linearization are inherently coupled in trajectory optimization. Different schemes may:
- Linearize then discretize: Compute continuous-time Jacobians (df/dx, df/du), then integrate the variational equations to obtain discrete-time matrices.
- Discretize then linearize: Integrate the nonlinear dynamics to form a discrete map, then differentiate through the integrator.
- Analytical methods: Use matrix exponentials, Euler approximations, etc.
Since the ordering of these operations changes the intermediate types, a single base class handles both, keeping the input/output contract consistent regardless of internal strategy.
Discretizer
¶
Bases: ABC
Abstract base class for dynamics linearization and discretization.
This class defines the interface for converting continuous-time nonlinear dynamics into discrete-time linear approximations suitable for convex subproblems in successive convexification.
The lifecycle mirrors other OpenSCvx ABCs:
Setup (called once):
- get_solver: Build a callable that computes discrete-time matrices
Per-iteration (via the returned callable):
- The callable is invoked with a reference trajectory and parameters, returning discretized matrices (A_d, B_d, C_d, x_prop)
Discretization parameters (hold type, integrator, tolerances) live on each concrete subclass as instance attributes.
Subclasses must implement the get_solver and citation methods.
Example
Implementing a custom discretizer::
class EulerDiscretizer(Discretizer):
def get_solver(self, dynamics, settings):
def solver(x, u, params):
# Euler discretization of dynamics
...
return A_d, B_d, C_d, x_prop, V
return solver
def citation(self):
return []
Source code in openscvx/discretization/base.py
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 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 | |
citation() -> List[str]
abstractmethod
¶
Return BibTeX citations for this discretization method.
Implementations should return a list of BibTeX entry strings for the papers that should be cited when using this discretization scheme.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of BibTeX citation strings. |
Source code in openscvx/discretization/base.py
get_solver(dynamics: Dynamics, settings: Config) -> callable
abstractmethod
¶
Create a discretization solver callable.
Called once during problem initialization. Returns a function that computes linearized discrete-time dynamics matrices around a reference trajectory. The returned callable will be JIT-compiled and cached by the framework.
Implementations are responsible for computing any Jacobians they need.
The dynamics object always provides dynamics.f (the continuous-
time nonlinear dynamics). Implementations that linearize first may
compute Jacobians via jax.jacfwd(dynamics.f, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Dynamics
|
System dynamics object. |
required |
settings
|
Config
|
Problem configuration (node count, scaling matrices, etc.). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable
|
Callable with signature |
|
callable
|
|
|
where |
callable
|
|
callable
|
|
|
callable
|
|
|
callable
|
|
|
callable
|
|
|
callable
|
|
Source code in openscvx/discretization/base.py
DiscretizerSpec
¶
Bases: BaseModel
Validates discretizer configuration from dict/YAML input.
A single spec covers all discretizer types. The type field selects
the concrete class; custom_integrator and args are only used by
the two vectorized variants and are silently ignored by the others.