weights
SCP penalty weights for successive convexification.
Provides the :class:Weights dataclass that holds all penalty weights
(trust region, virtual control, virtual buffer, cost) used in the SCP
objective function. Weights can be constructed from user-friendly inputs
(floats or {name: weight} dicts) via :meth:Weights.build, and
per-constraint virtual buffer arrays are populated via
:meth:Weights.build_vb_arrays.
Weights
dataclass
¶
Penalty weights for the SCP objective function.
Each SCP subproblem minimizes a weighted sum of the original cost, trust region penalty, virtual control penalty, and virtual buffer penalty. This dataclass holds the weights for each term.
Weights can be accessed directly (weights.lam_prox) or through
the algorithm's convenience properties (algorithm.lam_prox).
During SCP iteration, the autotuner may mutate these fields; those
changes are tracked in :class:AlgorithmState weight histories.
Use :meth:build to construct from user-friendly inputs (floats or
{name: weight} dicts). Use :meth:build_vb_arrays to populate
lam_vb_nodal and lam_vb_cross once symbolic constraints are
available.
Attributes:
| Name | Type | Description |
|---|---|---|
lam_prox |
Union[float, ndarray]
|
Trust region (proximal) weight. Scalar (uniform) or
array of shape |
lam_vc |
Union[float, ndarray]
|
Virtual control penalty weight. Scalar (uniform) or
array of shape |
lam_cost |
Union[float, ndarray]
|
Cost weight. Scalar (uniform across all
minimize/maximize states) or array of shape |
lam_vb |
float
|
Global virtual buffer penalty weight. Scalar default
applied to every constraint unless overridden via
|
lam_vb_nodal |
Optional[ndarray]
|
Per-node weights for nodal constraints, shape
|
lam_vb_cross |
Optional[ndarray]
|
Weights for cross-node constraints, shape
|
Source code in openscvx/algorithms/weights.py
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 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 | |
build(lam_prox: Union[float, Dict[str, Union[float, list, np.ndarray]]] = 0.1, lam_vc: Union[float, Dict[str, Union[float, list, np.ndarray]]] = 1.0, lam_cost: Union[float, Dict[str, float]] = 0.01, lam_vb: float = 0.0, states: Optional[List[State]] = None, controls: Optional[List[Control]] = None) -> Weights
classmethod
¶
Construct Weights from user-friendly inputs.
Accepts floats (applied uniformly) or dicts mapping state/control
names to per-variable weights. Dict inputs are expanded to dense
arrays via the resolve_lam_* methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam_prox
|
Union[float, Dict[str, Union[float, list, ndarray]]]
|
Trust region weight. Float or |
0.1
|
lam_vc
|
Union[float, Dict[str, Union[float, list, ndarray]]]
|
Virtual control weight. Float or |
1.0
|
lam_cost
|
Union[float, Dict[str, float]]
|
Cost weight. Float or |
0.01
|
lam_vb
|
float
|
Virtual buffer default weight (scalar). |
0.0
|
states
|
Optional[List[State]]
|
Symbolic State objects (required when any weight is a dict). |
None
|
controls
|
Optional[List[Control]]
|
Symbolic Control objects (required when lam_prox is a dict). |
None
|
Returns:
| Type | Description |
|---|---|
Weights
|
A new Weights instance with resolved numeric values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a dict weight is given without the required states/controls. |
Source code in openscvx/algorithms/weights.py
build_vb_arrays(N: int, nodal_constraints: list, cross_node_constraints: list, n_byof_nodal: int = 0, n_byof_cross: int = 0) -> None
¶
Build per-constraint virtual buffer weight arrays.
Inspects each symbolic constraint's shape (to account for vector
decomposition) and .weight() overrides, then populates
self.lam_vb_nodal and self.lam_vb_cross.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of trajectory nodes. |
required |
nodal_constraints
|
list
|
Symbolic |
required |
cross_node_constraints
|
list
|
Symbolic |
required |
n_byof_nodal
|
int
|
Number of byof nodal constraints (each adds one column with the default weight). |
0
|
n_byof_cross
|
int
|
Number of byof cross-node constraints (each adds one entry with the default weight). |
0
|
Source code in openscvx/algorithms/weights.py
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 | |
resolve_lam_cost(lam_cost: Union[float, Dict[str, Union[float, list, np.ndarray]]], states: Optional[List[State]] = None) -> Union[float, np.ndarray]
staticmethod
¶
Resolve a lam_cost spec to a numeric value.
If lam_cost is a float it is returned as-is. If it is a dict
mapping state names to weights, it is expanded to a dense array
of shape (n_states,) using each state's _slice. States
without a minimize/maximize objective receive weight 0. States
with an objective must appear in the dict.
Dict values may be scalars (broadcast to every component) or
arrays matching the state's shape for per-component weighting,
e.g. {"position": [0, 0, 1e-6]}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam_cost
|
Union[float, Dict[str, Union[float, list, ndarray]]]
|
Scalar weight or |
required |
states
|
Optional[List[State]]
|
Symbolic State objects (required when lam_cost is a dict). |
None
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
float or np.ndarray of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If lam_cost is a dict and states is |
Source code in openscvx/algorithms/weights.py
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 | |
resolve_lam_prox(lam_prox: Union[float, Dict[str, Union[float, list, np.ndarray]]], states: Optional[List[State]] = None, controls: Optional[List[Control]] = None) -> Union[float, np.ndarray]
staticmethod
¶
Resolve a lam_prox spec to a numeric value.
If lam_prox is a float it is returned as-is. If it is a dict
mapping state/control names to weights, it is expanded to a dense
array using each variable's _slice. Variables not in the dict
default to 1.0.
Dict values may be scalars, 1-D arrays (per-component), or 2-D
arrays of shape (K, n_components) for per-node-per-component
weighting. All 2-D entries must agree on K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam_prox
|
Union[float, Dict[str, Union[float, list, ndarray]]]
|
Scalar weight or |
required |
states
|
Optional[List[State]]
|
Symbolic State objects (required when lam_prox is a dict). |
None
|
controls
|
Optional[List[Control]]
|
Symbolic Control objects (required when lam_prox is a dict). |
None
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
float or np.ndarray of shape |
Union[float, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If lam_prox is a dict and states/controls is |
Source code in openscvx/algorithms/weights.py
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 | |
resolve_lam_vc(lam_vc: Union[float, Dict[str, Union[float, list, np.ndarray]]], states: Optional[List[State]] = None) -> Union[float, np.ndarray]
staticmethod
¶
Resolve a lam_vc spec to a numeric value.
If lam_vc is a float it is returned as-is. If it is a dict
mapping state names to weights, it is expanded to a dense array
using each state's _slice. States not in the dict default
to 1.0.
Dict values may be scalars, 1-D arrays (per-component), or 2-D
arrays of shape (K, n_components) for per-node-per-component
weighting. All 2-D entries must agree on K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam_vc
|
Union[float, Dict[str, Union[float, list, ndarray]]]
|
Scalar weight or |
required |
states
|
Optional[List[State]]
|
Symbolic State objects (required when lam_vc is a dict). |
None
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
float or np.ndarray of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If lam_vc is a dict and states is |
Source code in openscvx/algorithms/weights.py
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 | |