state
JAX-traceable iterate state for SCP algorithms.
This module holds the pytrees that move through the SCP iteration:
- :class:
AlgorithmState— the frozen, JAX-registered current iterate (state/control/weights/diagnostics). Every autotuner'smeth:
~openscvx.algorithms.autotuner.base.AutotuningBase.update_weightsis a pure functional update on this pytree, so the SCP body composes withjax.jit,jax.vmap, andjax.grad. - :class:
CandidateIterate— the just-solved subproblem result the fused iteration body hands to the autotuner. - :class:
AdaptiveStateCode— the int32 outcome the autotuner records on the state, plus :func:adaptive_state_code_to_strfor the printing path.
It sits in the middle of the algorithms import order: it depends on
:mod:openscvx.algorithms.hyperparams and is depended on by
:mod:openscvx.algorithms.history.
AdaptiveStateCode
¶
Bases: IntEnum
Outcome of one autotuner update_weights call.
The autotuner stores its decision as an int32 on
attr:
AlgorithmState.adaptive_state_code so the pytree remains
JAX-traceable. The SCP printing path maps the code back to a human-readable
string via :func:adaptive_state_code_to_str.
Source code in openscvx/algorithms/state.py
AlgorithmState
dataclass
¶
Current-iterate pytree for SCP iterations.
Every field is a JAX array (or scalar). The state moves between iterations
by way of pure functional updates: meth:
replace returns a new state
rather than mutating in place. Registered as a JAX pytree so the SCP body
composes with jax.jit / jax.vmap / jax.grad.
Append-only iteration histories (X, U, discretizations, ...) live on
:class:AlgorithmHistory, which is CPU-side and grown by the SCP loop.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Nodal state trajectory, shape |
u |
ndarray
|
Nodal control trajectory, shape |
x_prop |
ndarray
|
Continuous-time propagation of |
x_prop_plus |
ndarray
|
Impulsive/discrete dynamics evaluated at |
lam_prox |
ndarray
|
Trust-region weight, shape |
lam_vc |
ndarray
|
Virtual-control penalty weight, shape |
lam_cost |
ndarray
|
Cost weight, shape |
lam_cost_init |
ndarray
|
Initial cost weight ( |
lam_vb_nodal |
ndarray
|
Nodal virtual-buffer weights, shape |
lam_vb_cross |
ndarray
|
Cross-node virtual-buffer weights, shape |
k |
ndarray
|
Iteration counter (starts at 1). |
J_tr |
ndarray
|
Current trust-region cost (scalar). |
J_vb |
ndarray
|
Current virtual-buffer cost (scalar). |
J_vc |
ndarray
|
Current virtual-control cost (scalar). |
J_nonlin |
ndarray
|
Nonlinear-objective value for the current accepted iterate. |
predicted_reduction |
ndarray
|
Predicted reduction in |
actual_reduction |
ndarray
|
Actual reduction in |
acceptance_ratio |
ndarray
|
|
adaptive_state_code |
ndarray
|
:class: |
x_init_pin |
ndarray
|
Initial-state boundary condition, shape |
x_term_pin |
ndarray
|
Terminal-state boundary condition, shape |
ep_tr |
ndarray
|
Convergence threshold on |
ep_vb |
ndarray
|
Convergence threshold on |
ep_vc |
ndarray
|
Convergence threshold on |
k_max |
ndarray
|
SCP iteration cap (scalar, |
hyper |
HyperParams
|
Autotuner-declared hyperparameters — an instance of the
autotuner's :class: |
Source code in openscvx/algorithms/state.py
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 | |
from_settings(settings: Config, weights: Weights, *, ep_tr: float, ep_vb: float, ep_vc: float, k_max: int, hyper: HyperParams) -> AlgorithmState
classmethod
¶
Construct the initial iterate from configuration.
Copies trajectory guesses, expands weights to dense arrays, and seeds
the diagnostic scalars to zero / attr:
AdaptiveStateCode.INITIAL.
x_prop and x_prop_plus are zero-initialized; the autotuner
fills them when it carries the first accepted candidate onto the
state (see :meth:AutotuningBase.update_weights).
The SCP loop constants (ep_tr / ep_vb / ep_vc / k_max)
and the autotuner's declared hyperparameters (hyper, from
:attr:AutotuningBase.hyper) are snapshotted onto the pytree here —
the caller passes them off the algorithm and its autotuner (see
Problem._default_state), and per-solve overrides land via
state.replace.
Source code in openscvx/algorithms/state.py
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 | |
replace(**changes) -> AlgorithmState
¶
CandidateIterate
dataclass
¶
Subproblem candidate the fused iteration hands to the autotuner.
Built once, in-trace, by the SCP iteration body
(scvx/iteration.py): it carries the just-solved subproblem trajectory
(x / u), its propagation (x_prop / x_prop_plus), and the
linearized cost (J_lin) into meth:
AutotuningBase.update_weights,
which copies the accepted fields onto the next :class:AlgorithmState. It
is the autotuner's input and nothing else — host-side history recording
takes its arrays through meth:
AlgorithmHistory.record_iteration's
explicit keyword arguments rather than through this type.
Source code in openscvx/algorithms/state.py
adaptive_state_code_to_str(code: Union[int, jnp.ndarray, np.ndarray]) -> str
¶
Map an :class:AdaptiveStateCode value (int or 0-d array) to its label.