algorithms
Successive convexification algorithms for trajectory optimization.
This module provides implementations of SCvx (Successive Convexification) algorithms for solving non-convex trajectory optimization problems through iterative convex approximation.
All algorithms inherit from :class:Algorithm, enabling pluggable algorithm
implementations and custom SCvx variants:
class Algorithm(ABC):
@abstractmethod
def initialize(self, solver, discretization_solver, jax_constraints,
emitter, params, settings) -> None:
'''Store compiled infrastructure and warm-start solvers.'''
...
@abstractmethod
def step(self, state, params, settings) -> bool:
'''Execute one iteration using stored infrastructure.'''
...
Immutable components (solver, discretization_solver, jax_constraints, etc.) are stored
during initialize(). Mutable configuration (params, settings) is passed per-step
to support runtime parameter updates and tolerance tuning.
:class:AlgorithmState holds mutable state during SCP iterations. Algorithms
that require additional state can subclass it:
Note
AlgorithmState currently combines iteration metrics (costs, weights),
trajectory history, and discretization data. A future refactor may separate
these concerns into distinct classes for clearer data flow:
@dataclass
class AlgorithmState:
# Mutable iteration state
k: int
J_tr: float
J_vb: float
J_vc: float
lam_prox: float
lam_cost: float
lam_vc: ...
lam_vb: float
@dataclass
class TrajectoryHistory:
# Accumulated trajectory solutions
X: List[np.ndarray]
U: List[np.ndarray]
@property
def x(self): return self.X[-1]
@property
def u(self): return self.U[-1]
@dataclass
class DebugHistory:
# Optional diagnostic data (discretization matrices, etc.)
V_history: List[np.ndarray]
VC_history: List[np.ndarray]
TR_history: List[np.ndarray]
Current Implementations:
- :class:
PenalizedTrustRegion: Penalized Trust Region (PTR) algorithm
Algorithm
¶
Bases: ABC
Abstract base class for successive convexification algorithms.
This class defines the interface for SCP algorithms used in trajectory optimization. Implementations should remain minimal and functional, delegating state management to the AlgorithmState dataclass.
The two core methods mirror the SCP workflow:
- initialize: Store compiled infrastructure and warm-start solvers
- step: Execute one convex subproblem iteration
Immutable components (ocp, discretization_solver, jax_constraints, etc.) are stored during initialize(). Mutable configuration (params, settings) is passed per-step to support runtime parameter updates and tolerance tuning.
Statefullness
Avoid storing mutable iteration state (costs, weights, trajectories) on
self. All iteration state should live in :class:AlgorithmState or
a subclass thereof, passed explicitly to step(). This keeps algorithm
classes stateless w.r.t. iteration, making data flow explicit and staying
close to functional programming principles where possible.
Example
Implementing a custom algorithm::
class MyAlgorithm(Algorithm):
def initialize(self, solver, discretization_solver,
jax_constraints, emitter,
params, settings):
# Store compiled infrastructure
self._solver = solver
self._discretization_solver = discretization_solver
self._jax_constraints = jax_constraints
self._emitter = emitter
# Warm-start with initial params/settings...
def step(self, state, params, settings):
# Run one iteration using self._* and per-step params/settings
return converged
Source code in openscvx/algorithms/base.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
citation() -> List[str]
abstractmethod
¶
Return BibTeX citations for this algorithm.
Implementations should return a list of BibTeX entry strings for the papers that should be cited when using this algorithm.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of BibTeX citation strings. |
Example
Getting citations for an algorithm::
algorithm = PenalizedTrustRegion()
for bibtex in algorithm.citation():
print(bibtex)
Source code in openscvx/algorithms/base.py
initialize(solver: ConvexSolver, discretization_solver: callable, jax_constraints: LoweredJaxConstraints, emitter: callable, params: dict, settings: Config) -> None
abstractmethod
¶
Initialize the algorithm and store compiled infrastructure.
This method stores immutable components and performs any setup required before the SCP loop begins (e.g., warm-starting solvers). The params and settings are passed for warm-start but may change between steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
ConvexSolver
|
Convex subproblem solver (e.g., CVXPySolver) |
required |
discretization_solver
|
callable
|
Compiled discretization solver function |
required |
jax_constraints
|
LoweredJaxConstraints
|
JIT-compiled JAX constraint functions |
required |
emitter
|
callable
|
Callback for emitting iteration progress data |
required |
params
|
dict
|
Problem parameters dictionary (for warm-start only) |
required |
settings
|
Config
|
Configuration object (for warm-start only) |
required |
Source code in openscvx/algorithms/base.py
step(state: AlgorithmState, params: dict, settings: Config) -> bool
abstractmethod
¶
Execute one iteration of the SCP algorithm.
This method solves a single convex subproblem, updates the algorithm state in place, and returns whether convergence criteria are met.
Uses stored infrastructure (ocp, discretization_solver, etc.) with per-step params and settings to support runtime modifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Mutable algorithm state (modified in place) |
required |
params
|
dict
|
Problem parameters dictionary (may change between steps) |
required |
settings
|
Config
|
Configuration object (may change between steps) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if convergence criteria are satisfied, False otherwise. |
Source code in openscvx/algorithms/base.py
AlgorithmState
dataclass
¶
Mutable state for SCP iterations.
This dataclass holds all state that changes during the solve process. It stores only the evolving trajectory arrays, not the full State/Control objects which contain immutable configuration metadata.
Trajectory arrays are stored in history lists, with the current guess accessed via properties that return the latest entry.
A fresh instance is created for each solve, enabling easy reset functionality.
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Current iteration number (starts at 1) |
J_tr |
float
|
Current trust region cost |
J_vb |
float
|
Current virtual buffer cost |
J_vc |
float
|
Current virtual control cost |
lam_prox |
float
|
Current trust region weight (may adapt during solve) |
lam_cost |
float
|
Current cost weight (may relax during solve) |
lam_vc |
Union[float, ndarray]
|
Current virtual control penalty weight |
lam_vb |
float
|
Current virtual buffer penalty weight |
n_x |
int
|
Number of states (for unpacking V vectors) |
n_u |
int
|
Number of controls (for unpacking V vectors) |
N |
int
|
Number of trajectory nodes (for unpacking V vectors) |
X |
List[ndarray]
|
List of state trajectory iterates |
U |
List[ndarray]
|
List of control trajectory iterates |
discretizations |
List[DiscretizationResult]
|
List of unpacked discretization results |
VC_history |
List[ndarray]
|
List of virtual control history |
TR_history |
List[ndarray]
|
List of trust region history |
A_bar_history |
List[ndarray]
|
List of state transition matrices |
B_bar_history |
List[ndarray]
|
List of control influence matrices |
C_bar_history |
List[ndarray]
|
List of control influence matrices for next node |
x_prop_history |
List[ndarray]
|
List of propagated states |
Source code in openscvx/algorithms/base.py
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 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 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
V_history: List[np.ndarray]
property
¶
Backward-compatible view of raw discretization matrices.
Note
This is a read-only view. Internal code should prefer
state.discretizations.
lam_cost: float
property
¶
Get current cost weight.
Returns:
| Type | Description |
|---|---|
float
|
Current cost weight (latest entry in lam_cost_history) |
lam_prox: float
property
¶
Get current trust region weight.
Returns:
| Type | Description |
|---|---|
float
|
Current trust region weight (latest entry in lam_prox_history) |
lam_vb: float
property
¶
Get current virtual buffer penalty weight.
Returns:
| Type | Description |
|---|---|
float
|
Current virtual buffer penalty weight (latest entry in lam_vb_history) |
lam_vc: Union[float, np.ndarray]
property
¶
Get current virtual control penalty weight.
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
Current virtual control penalty weight (latest entry in lam_vc_history) |
u: np.ndarray
property
¶
Get current control trajectory array.
Returns:
| Type | Description |
|---|---|
ndarray
|
Current control trajectory guess (latest entry in history), shape (N, n_controls) |
x: np.ndarray
property
¶
Get current state trajectory array.
Returns:
| Type | Description |
|---|---|
ndarray
|
Current state trajectory guess (latest entry in history), shape (N, n_states) |
A_d(index: int = -1) -> np.ndarray
¶
Extract discretized state transition matrix from discretizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index into V_history (default: -1 for latest entry) |
-1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Discretized state Jacobian A_d with shape (N-1, n_x, n_x), or None if no V_history |
Example
After running an iteration, access linearization matrices::
problem.step()
A_d = problem.state.A_d() # Shape (N-1, n_x, n_x), latest
A_d_prev = problem.state.A_d(-2) # Previous iteration
Source code in openscvx/algorithms/base.py
B_d(index: int = -1) -> np.ndarray
¶
Extract discretized control influence matrix (current node).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index into discretization history (default: -1 for latest entry) |
-1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Discretized control Jacobian B_d with shape (N-1, n_x, n_u), or None if empty. |
Example
After running an iteration, access linearization matrices::
problem.step()
B_d = problem.state.B_d() # Shape (N-1, n_x, n_u), latest
B_d_prev = problem.state.B_d(-2) # Previous iteration
Source code in openscvx/algorithms/base.py
C_d(index: int = -1) -> np.ndarray
¶
Extract discretized control influence matrix (next node).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index into discretization history (default: -1 for latest entry) |
-1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Discretized control Jacobian C_d with shape (N-1, n_x, n_u), or None if empty. |
Example
After running an iteration, access linearization matrices::
problem.step()
C_d = problem.state.C_d() # Shape (N-1, n_x, n_u), latest
C_d_prev = problem.state.C_d(-2) # Previous iteration
Source code in openscvx/algorithms/base.py
accept_solution(cand: CandidateIterate) -> None
¶
Accept the given candidate iterate by updating the state in place.
Source code in openscvx/algorithms/base.py
add_discretization(V: np.ndarray) -> None
¶
Append a raw discretization matrix as an unpacked result.
from_settings(settings: Config) -> AlgorithmState
classmethod
¶
Create initial algorithm state from configuration.
Copies only the trajectory arrays from settings, leaving all metadata (bounds, boundary conditions, etc.) in the original settings object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Config
|
Configuration object containing initial guesses and SCP parameters |
required |
Returns:
| Type | Description |
|---|---|
AlgorithmState
|
Fresh AlgorithmState initialized from settings with copied arrays |
Source code in openscvx/algorithms/base.py
x_prop(index: int = -1) -> np.ndarray
¶
Extract propagated state trajectory from the discretization history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index into V_history (default: -1 for latest entry) |
-1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Propagated state trajectory x_prop with shape (N-1, n_x), or None if no V_history |
Example
After running an iteration, access the propagated states::
problem.step()
x_prop = problem.state.x_prop() # Shape (N-1, n_x), latest
x_prop_prev = problem.state.x_prop(-2) # Previous iteration
Source code in openscvx/algorithms/base.py
AugmentedLagrangian
¶
Bases: AutotuningBase
Augmented Lagrangian method for autotuning SCP weights.
This method uses Lagrange multipliers and penalty parameters to handle constraints. The method: - Updates Lagrange multipliers based on constraint violations - Increases penalty parameters when constraints are violated - Decreases penalty parameters when constraints are satisfied
Source code in openscvx/algorithms/autotuning.py
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 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
__init__(rho_init: float = 1.0, rho_max: float = 1000000.0, gamma_1: float = 2.0, gamma_2: float = 0.5, eta_0: float = 0.01, eta_1: float = 0.1, eta_2: float = 0.8, ep: float = 0.5, eta_lambda: float = 1.0, lam_vc_max: float = 100000.0, lam_prox_min: float = 0.001, lam_prox_max: float = 200000.0, lam_cost_drop: int = -1, lam_cost_relax: float = 1.0)
¶
Initialize Augmented Lagrangian autotuning parameters.
All parameters have defaults and can be modified after instantiation
via attribute access (e.g., autotuner.rho_max = 1e7).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho_init
|
float
|
Initial penalty parameter for constraints. Defaults to 1.0. |
1.0
|
rho_max
|
float
|
Maximum penalty parameter. Defaults to 1e6. |
1000000.0
|
gamma_1
|
float
|
Factor to increase trust region weight when ratio is low. Defaults to 2.0. |
2.0
|
gamma_2
|
float
|
Factor to decrease trust region weight when ratio is high. Defaults to 0.5. |
0.5
|
eta_0
|
float
|
Acceptance ratio threshold below which solution is rejected. Defaults to 1e-2. |
0.01
|
eta_1
|
float
|
Threshold above which solution is accepted with constant weight. Defaults to 1e-1. |
0.1
|
eta_2
|
float
|
Threshold above which solution is accepted with lower weight. Defaults to 0.8. |
0.8
|
ep
|
float
|
Threshold for virtual control weight update (nu > ep vs nu <= ep). Defaults to 0.5. |
0.5
|
eta_lambda
|
float
|
Step size for virtual control weight update. Defaults to 1e0. |
1.0
|
lam_vc_max
|
float
|
Maximum virtual control penalty weight. Defaults to 1e5. |
100000.0
|
lam_prox_min
|
float
|
Minimum trust region (proximal) weight. Defaults to 1e-3. |
0.001
|
lam_prox_max
|
float
|
Maximum trust region (proximal) weight. Defaults to 2e5. |
200000.0
|
lam_cost_drop
|
int
|
Iteration after which cost relaxation applies (-1 = never). Defaults to -1. |
-1
|
lam_cost_relax
|
float
|
Factor applied to lam_cost after lam_cost_drop. Defaults to 1.0. |
1.0
|
Source code in openscvx/algorithms/autotuning.py
update_weights(state: AlgorithmState, candidate: CandidateIterate, nodal_constraints: LoweredJaxConstraints, settings: Config, params: dict) -> str
¶
Update SCP weights and cost parameters based on iteration number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Solver state containing current weight values (mutated in place) |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints |
required |
settings
|
Config
|
Configuration object containing adaptation parameters |
required |
params
|
dict
|
Dictionary of problem parameters |
required |
Source code in openscvx/algorithms/autotuning.py
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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
AutotuningBase
¶
Bases: ABC
Base class for autotuning methods in SCP algorithms.
This class provides common functionality for calculating costs and penalties that are shared across different autotuning strategies (e.g., Penalized Trust Region, Augmented Lagrangian).
Subclasses should implement the update_weights method to define their specific
weight update strategy.
Class Attributes
COLUMNS: List of Column specs for autotuner-specific metrics to display. Subclasses override this to add their own columns.
Source code in openscvx/algorithms/autotuning.py
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 | |
calculate_cost_from_state(x: np.ndarray, settings: Config) -> float
staticmethod
¶
Calculate cost from state vector based on final_type and initial_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
State trajectory array (n_nodes, n_states) |
required |
settings
|
Config
|
Configuration object containing state types |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Computed cost |
Source code in openscvx/algorithms/autotuning.py
calculate_nonlinear_penalty(x_prop: np.ndarray, x_bar: np.ndarray, u_bar: np.ndarray, lam_vc: np.ndarray, lam_vb: float, lam_cost: float, nodal_constraints: LoweredJaxConstraints, params: dict, settings: Config) -> Tuple[float, float, float]
staticmethod
¶
Calculate nonlinear penalty components.
This method computes three penalty components: 1. Cost penalty: weighted original cost 2. Virtual control penalty: penalty for dynamics violations 3. Nodal penalty: penalty for constraint violations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_prop
|
ndarray
|
Propagated state (n_nodes-1, n_states) |
required |
x_bar
|
ndarray
|
Previous iteration state (n_nodes, n_states) |
required |
u_bar
|
ndarray
|
Solution control (n_nodes, n_controls) |
required |
lam_vc
|
ndarray
|
Virtual control weight (scalar or matrix) |
required |
lam_vb
|
float
|
Virtual buffer penalty weight (scalar) |
required |
lam_cost
|
float
|
Cost relaxation parameter (scalar) |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints |
required |
params
|
dict
|
Dictionary of problem parameters |
required |
settings
|
Config
|
Configuration object |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float]
|
Tuple of (nonlinear_cost, nonlinear_penalty, nodal_penalty): - nonlinear_cost: Weighted cost component - nonlinear_penalty: Virtual control penalty - nodal_penalty: Constraint violation penalty |
Source code in openscvx/algorithms/autotuning.py
update_weights(state: AlgorithmState, candidate: CandidateIterate, nodal_constraints: LoweredJaxConstraints, settings: Config, params: dict) -> str
abstractmethod
¶
Update SCP weights and cost parameters based on iteration state.
This method is called each iteration to adapt weights based on the current solution quality and constraint satisfaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Solver state containing current weight values (mutated in place) |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints |
required |
settings
|
Config
|
Configuration object containing adaptation parameters |
required |
params
|
dict
|
Dictionary of problem parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Adaptive state string describing the update action (e.g., "Accept Lower") |
Source code in openscvx/algorithms/autotuning.py
ConstantProximalWeight
¶
Bases: AutotuningBase
Constant Proximal Weight method.
This method keeps the trust region weight constant throughout the optimization, while still updating virtual control weights and handling cost relaxation. Useful when you want a fixed trust region size without adaptation.
Source code in openscvx/algorithms/autotuning.py
update_weights(state: AlgorithmState, candidate: CandidateIterate, nodal_constraints: LoweredJaxConstraints, settings: Config, params: dict) -> str
¶
Update SCP weights keeping trust region constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Solver state containing current weight values (mutated in place) |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints |
required |
settings
|
Config
|
Configuration object containing adaptation parameters |
required |
params
|
dict
|
Dictionary of problem parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Adaptive state string (e.g., "Accept", "Reject") |
Source code in openscvx/algorithms/autotuning.py
DiscretizationResult
dataclass
¶
Unpacked discretization data from a multi-shot discretization matrix.
The discretization solver returns a matrix V that stores multiple blocks
(propagated state and linearization matrices) across nodes/time. Historically,
we stored the raw V matrices and re-unpacked them repeatedly via slicing.
This dataclass unpacks once and makes access trivial.
Source code in openscvx/algorithms/base.py
from_V(V: np.ndarray, n_x: int, n_u: int, N: int) -> DiscretizationResult
classmethod
¶
Unpack the final timestep of a raw discretization matrix V.
Source code in openscvx/algorithms/base.py
OptimizationResults
dataclass
¶
Structured container for optimization results from the Successive Convexification (SCP) solver.
This class provides a type-safe and organized way to store and access optimization results, replacing the previous dictionary-based approach. It includes core optimization data, iteration history for convergence analysis, post-processing results, and flexible storage for plotting and application-specific data.
Attributes:
| Name | Type | Description |
|---|---|---|
converged |
bool
|
Whether the optimization successfully converged. |
t_final |
float
|
Final time of the optimized trajectory. |
x_guess |
ndarray
|
Optimized state trajectory at discretization nodes, shape (N, n_states). |
u_guess |
ndarray
|
Optimized control trajectory at discretization nodes, shape (N, n_controls). |
nodes |
dict[str, ndarray]
|
Dictionary mapping state/control names to arrays at optimization nodes. Includes both user-defined and augmented variables. |
trajectory |
dict[str, ndarray]
|
Dictionary mapping state/control names to arrays along the propagated trajectory. Added by post_process(). |
x_history |
list[ndarray]
|
State trajectories from each SCP iteration. |
u_history |
list[ndarray]
|
Control trajectories from each SCP iteration. |
discretization_history |
list[ndarray]
|
Time discretization from each iteration. |
J_tr_history |
list[ndarray]
|
Trust region cost history. |
J_vb_history |
list[ndarray]
|
Virtual buffer cost history. |
J_vc_history |
list[ndarray]
|
Virtual control cost history. |
t_full |
Optional[ndarray]
|
Full time grid for interpolated trajectory. Added by propagate_trajectory_results. |
x_full |
Optional[ndarray]
|
Interpolated state trajectory on full time grid. Added by propagate_trajectory_results. |
u_full |
Optional[ndarray]
|
Interpolated control trajectory on full time grid. Added by propagate_trajectory_results. |
cost |
Optional[float]
|
Total cost of the optimized trajectory. Added by propagate_trajectory_results. |
ctcs_violation |
Optional[ndarray]
|
Continuous-time constraint violations. Added by propagate_trajectory_results. |
plotting_data |
dict[str, Any]
|
Flexible storage for plotting and application data. |
Source code in openscvx/algorithms/optimization_results.py
7 8 9 10 11 12 13 14 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 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 | |
u: np.ndarray
property
¶
Optimal control trajectory at discretization nodes.
Returns the final converged solution from the SCP iteration history.
Returns:
| Type | Description |
|---|---|
ndarray
|
Control trajectory array, shape (N, n_controls) |
x: np.ndarray
property
¶
Optimal state trajectory at discretization nodes.
Returns the final converged solution from the SCP iteration history.
Returns:
| Type | Description |
|---|---|
ndarray
|
State trajectory array, shape (N, n_states) |
get(key: str, default: Any = None) -> Any
¶
Get a value from the results, similar to dict.get().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to look up |
required |
default
|
Any
|
Default value if key is not found |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The value associated with the key, or default if not found |
Source code in openscvx/algorithms/optimization_results.py
to_dict() -> dict[str, Any]
¶
Convert the results to a dictionary for backward compatibility.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the results |
Source code in openscvx/algorithms/optimization_results.py
update(other: dict[str, Any])
¶
Update the results with additional data from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
dict[str, Any]
|
Dictionary containing additional data |
required |
Source code in openscvx/algorithms/optimization_results.py
update_plotting_data(**kwargs: Any) -> None
¶
Update the plotting data with additional information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Key-value pairs to add to plotting_data |
{}
|
PenalizedTrustRegion
¶
Bases: Algorithm
Penalized Trust Region (PTR) successive convexification algorithm.
PTR solves non-convex trajectory optimization problems through iterative convex approximation. Each subproblem balances competing cost terms:
- Trust region penalty: Discourages large deviations from the previous iterate, keeping the solution within the region where linearization is valid.
- Virtual control: Relaxes dynamics constraints, penalized to drive defects toward zero as the algorithm converges.
- Virtual buffer: Relaxes non-convex constraints, similarly penalized to enforce feasibility at convergence.
- Problem objective and other terms: The user-defined cost (e.g., minimum fuel, minimum time) and any additional penalty terms.
The interplay between these terms guides the optimization: the trust region anchors the solution near the linearization point while virtual terms allow temporary constraint violations that shrink over iterations.
Example
Using PTR with a Problem::
from openscvx.algorithms import PenalizedTrustRegion
problem = Problem(dynamics, constraints, states, controls, N, time)
problem.initialize()
result = problem.solve()
Source code in openscvx/algorithms/penalized_trust_region.py
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 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 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
autotuner: AutotuningBase
property
¶
Access the autotuner instance for configuring parameters.
For AugmentedLagrangian method, parameters can be modified via: algorithm.autotuner.rho_max = 1e7 algorithm.autotuner.mu_max = 1e7 etc.
Returns:
| Name | Type | Description |
|---|---|---|
AutotuningBase |
AutotuningBase
|
The autotuner instance |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If algorithm has not been initialized yet |
__init__()
¶
Initialize PTR with unset infrastructure.
Call initialize() before step() to set up compiled components.
Source code in openscvx/algorithms/penalized_trust_region.py
citation() -> List[str]
¶
Return BibTeX citations for the PTR algorithm.
Returns:
| Type | Description |
|---|---|
List[str]
|
List containing the BibTeX entry for the PTR paper. |
Source code in openscvx/algorithms/penalized_trust_region.py
get_columns(verbosity: int = Verbosity.STANDARD) -> List[Column]
¶
Get the columns to display for iteration output.
Combines base PTR columns with autotuner-specific columns, filtered by the requested verbosity level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbosity
|
int
|
Minimum verbosity level for columns to include. MINIMAL (1): Core metrics only (iter, cost, status) STANDARD (2): + timing, penalty terms FULL (3): + autotuning diagnostics |
STANDARD
|
Returns:
| Type | Description |
|---|---|
List[Column]
|
List of Column specs filtered by verbosity level. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If algorithm has not been initialized yet. |
Source code in openscvx/algorithms/penalized_trust_region.py
initialize(solver: ConvexSolver, discretization_solver: callable, jax_constraints: LoweredJaxConstraints, emitter: callable, params: dict, settings: Config) -> None
¶
Initialize PTR algorithm.
Stores compiled infrastructure and performs a warm-start solve to initialize DPP and JAX jacobians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
ConvexSolver
|
Convex subproblem solver (e.g., CVXPySolver) |
required |
discretization_solver
|
callable
|
Compiled discretization solver |
required |
jax_constraints
|
LoweredJaxConstraints
|
JIT-compiled constraint functions |
required |
emitter
|
callable
|
Callback for emitting iteration progress |
required |
params
|
dict
|
Problem parameters dictionary (for warm-start) |
required |
settings
|
Config
|
Configuration object (for warm-start) |
required |
Source code in openscvx/algorithms/penalized_trust_region.py
step(state: AlgorithmState, params: dict, settings: Config) -> bool
¶
Execute one PTR iteration.
Solves the convex subproblem, updates state in place, and checks convergence based on trust region, virtual buffer, and virtual control costs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Mutable solver state (modified in place) |
required |
params
|
dict
|
Problem parameters dictionary (may change between steps) |
required |
settings
|
Config
|
Configuration object (may change between steps) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if J_tr, J_vb, and J_vc are all below their thresholds. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If initialize() has not been called. |
Source code in openscvx/algorithms/penalized_trust_region.py
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 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
RampProximalWeight
¶
Bases: AutotuningBase
Ramp Proximal Weight method.
This method ramps the proximal weight up linearly over the first few iterations, then keeps it constant.
Source code in openscvx/algorithms/autotuning.py
update_weights(state: AlgorithmState, candidate: CandidateIterate, nodal_constraints: LoweredJaxConstraints, settings: Config, params: dict) -> str
¶
Update SCP weights keeping trust region constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AlgorithmState
|
Solver state containing current weight values (mutated in place) |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints |
required |
settings
|
Config
|
Configuration object containing adaptation parameters |
required |
params
|
dict
|
Dictionary of problem parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Adaptive state string (e.g., "Accept", "Reject") |