penalty
Shared SCP cost / penalty math.
These two functions are the cost machinery the SCP iteration and the autotuners
both lean on: :func:calculate_cost_from_state weights a state trajectory by
its boundary-condition objective, and :func:calculate_nonlinear_penalty
assembles the three-component nonlinear penalty (cost, virtual control, nodal
constraint violation). They are plumbing, not autotuning policy, so they live
as module functions with no dependency beyond jnp and the config typing.
calculate_cost_from_state(x: jnp.ndarray, settings: Config, lam_cost: Union[float, jnp.ndarray] = 1.0) -> jnp.ndarray
¶
Compute the boundary-condition-weighted cost contribution for x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
State trajectory, shape |
required |
settings
|
Config
|
Configuration object carrying scaling matrices and boundary-condition types. |
required |
lam_cost
|
Union[float, ndarray]
|
Per-state cost weight. Scalar or array of shape
|
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Scalar cost (jnp), weighted by |
Source code in openscvx/algorithms/penalty.py
calculate_nonlinear_penalty(x_prop: jnp.ndarray, x_bar: jnp.ndarray, u_bar: jnp.ndarray, lam_vc: jnp.ndarray, lam_vb_nodal: jnp.ndarray, lam_vb_cross: jnp.ndarray, lam_cost: Union[float, jnp.ndarray], nodal_constraints: LoweredJaxConstraints, params: dict, settings: Config) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]
¶
Compute the three components of the nonlinear penalty.
This is JAX-traceable: the Python loops over
nodal_constraints.nodal / cross_node unroll at trace time
(the lists are static-length lists of compiled closures built by
:class:Problem).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_prop
|
ndarray
|
Propagated state, shape |
required |
x_bar
|
ndarray
|
Nodal state, shape |
required |
u_bar
|
ndarray
|
Nodal control, shape |
required |
lam_vc
|
ndarray
|
Virtual control weight, scalar or matrix. |
required |
lam_vb_nodal
|
ndarray
|
Nodal virtual-buffer weights, shape |
required |
lam_vb_cross
|
ndarray
|
Cross-node virtual-buffer weights, shape |
required |
lam_cost
|
Union[float, ndarray]
|
Cost weight, scalar or shape |
required |
nodal_constraints
|
LoweredJaxConstraints
|
Lowered JAX constraints. |
required |
params
|
dict
|
Problem parameter dictionary. |
required |
settings
|
Config
|
Configuration object. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
scalar jnp arrays. |