Optimization API
This module contains package-native projected quadratic-program layers and an optional CVXPYlayers bridge. Its method lineage is OptNet [8], differentiable convex optimization layers [9], and the CVXPYlayers implementation [40].
For the source-to-package derivation and citation scope, see Method Adaptation Atlas.
Package-Native Projected QP
The core layer solves
The implemented fixed-point map is projected gradient descent:
Supported package-native constraint choices are:
constraint |
Constraint set |
|---|---|
"none" |
unconstrained quadratic |
"nonnegative" |
\(z_j\ge 0\) |
"box" |
\(\ell_j\le z_j\le u_j\) |
"simplex" |
\(z_j\ge 0,\ \sum_j z_j=m\) |
"affine" |
\(A_{\rm eq}z=b_{\rm eq}\) |
from silva_networks import SolverConfig, silva_projected_qp_layer
layer = silva_projected_qp_layer(
in_dim=8,
state_dim=4,
constraint="simplex",
simplex_mass=1.0,
config=SolverConfig(solver="picard", max_iter=50, alpha=1.0),
)
z_star = layer(x)
CVXPYlayers Bridge
For general disciplined parametrized convex programs, install the optional optimization extra on Python 3.11+:
Then use silva_cvxpy_layer(...) to wrap a DPP-compliant CVXPY problem. This
path follows CVXPYlayers and is separate from the core projected-QP layer.
Public Names
| Preferred name | Compatibility name |
|---|---|
SILVAProjectedQPLayer |
SILVAConstrainedQuadraticLayer |
silva_projected_qp_layer |
silva_constrained_quadratic_layer |
Citation Map
| Feature | Cite |
|---|---|
| projected quadratic SILVA layer | SILVA package; projected-gradient methods |
| differentiable QP/optimization layer framing | OptNet |
| general CVXPYlayers bridge | Differentiable Convex Optimization Layers, CVXPYlayers |
API Docs
SILVA optimization layers and constrained quadratic projections.
The package-native layer in this module solves structured quadratic programs with projected fixed-point iterations in PyTorch. It is intended for small and medium differentiable optimization blocks that fit naturally into the SILVA solver and device APIs.
For fully general disciplined convex programs, use silva_cvxpy_layer with
the optional cvxpylayers dependency. That path follows Agrawal et al. (2019)
and keeps the general convex modeling language outside the core runtime
dependencies.
References
- Silva, "SILVA Networks as Structured Implicit Layers and Vector Attractors via Dynamic Interaction Fields", 2026.
- Amos and Kolter, "OptNet: Differentiable Optimization as a Layer in Neural Networks", ICML 2017.
- Agrawal, Amos, Barratt, Boyd, Diamond, and Kolter, "Differentiable Convex Optimization Layers", NeurIPS 2019.
SILVAConstrainedQuadraticLayer
Bases: Module
Projected fixed-point layer for constrained quadratic programs.
For each input row \(x_i\), the layer builds \(b_i=B_\theta x_i+c\) and solves the package-native optimization problem
The fixed-point map is projected gradient descent:
This layer is not a complete cone-programming system. It covers common
constraints used in package examples: nonnegativity, boxes, simplex rows,
and affine equalities. Use silva_cvxpy_layer for a full CVXPYlayers-style
disciplined convex-program interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_dim
|
int
|
Number of input features. |
required |
state_dim
|
int
|
Number of optimization variables. |
required |
constraint
|
ConstraintKind
|
Constraint family: |
'none'
|
ridge
|
float
|
Positive diagonal term in \(A\). |
1.0
|
step_size
|
float
|
Projected-gradient step size. |
0.2
|
lower_bound
|
float | Tensor | None
|
Lower box bound when |
None
|
upper_bound
|
float | Tensor | None
|
Upper box bound when |
None
|
simplex_mass
|
float
|
Row sum when |
1.0
|
equality_matrix
|
Tensor | None
|
Matrix \(A_{\rm eq}\) for |
None
|
equality_rhs
|
Tensor | None
|
Right-hand side \(b_{\rm eq}\) for |
None
|
projection_ridge
|
float
|
Stabilizer for affine projection. |
1e-08
|
config
|
SolverConfig | None
|
Fixed-point solver configuration. |
None
|
reengage
|
bool
|
Whether to run one differentiable projected step after the numerical solve. |
True
|
Source code in src/silva_networks/optimization.py
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 | |
energy
Return one quadratic objective value per batch row.
Source code in src/silva_networks/optimization.py
exact_unconstrained_solution
Return the direct solution of \(Az=b_\theta(x)\), ignoring constraints.
gradient
matrix
Return the positive-definite matrix \(A=L L^\top+\lambda I\).
Source code in src/silva_networks/optimization.py
project
Project a candidate optimizer state onto the configured constraint.
Source code in src/silva_networks/optimization.py
projected_residual
Return \(\|T(z)-z\|_2\) for the configured projected map.
rhs
Return \(b_\theta(x)\) with shape (batch, state_dim).
Source code in src/silva_networks/optimization.py
transition
SILVACvxpyLayer
Bases: Module
Optional bridge to cvxpylayers.torch.CvxpyLayer.
This wrapper is provided for users who need a full CVXPYlayers-style disciplined convex-program layer. It is intentionally optional because the dependency stack is heavier than the core SILVA package and currently has its own Python-version requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Any
|
A DPP-compliant CVXPY problem. |
required |
parameters
|
list[Any]
|
CVXPY parameters supplied at runtime. |
required |
variables
|
list[Any]
|
CVXPY variables returned by the layer. |
required |
layer_kwargs
|
Any
|
Additional keyword arguments forwarded to
|
{}
|
Source code in src/silva_networks/optimization.py
forward
Solve the wrapped convex problem for PyTorch tensor parameters.
Source code in src/silva_networks/optimization.py
SILVAProjectedQPLayer
Bases: SILVAConstrainedQuadraticLayer
SILVA-style public name for the projected quadratic-program layer.
This class is equivalent to SILVAConstrainedQuadraticLayer. The
projected-QP name makes the implemented mathematical object explicit:
projected fixed-point steps for positive-definite quadratic objectives with
selectable simple constraints.
Source code in src/silva_networks/optimization.py
project_affine_equality
Project onto an affine equality set.
The projection solves
A small ridge is added to \(AA^\top\) for numerical stability when the equality rows are nearly dependent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Tensor with shape |
required |
equality_matrix
|
Tensor
|
Matrix \(A\) with shape |
required |
equality_rhs
|
Tensor
|
Right-hand side \(b\), shape |
required |
ridge
|
float
|
Diagonal regularization for the normal equations. |
1e-08
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor projected onto the affine equality set. |
Source code in src/silva_networks/optimization.py
project_box
Project onto elementwise box constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Tensor whose final dimension is the optimization variable. |
required |
lower
|
float | Tensor | None
|
Optional lower bound, scalar or broadcastable tensor. |
None
|
upper
|
float | Tensor | None
|
Optional upper bound, scalar or broadcastable tensor. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor satisfying the requested elementwise bounds. |
Source code in src/silva_networks/optimization.py
project_nonnegative
Project onto the nonnegative orthant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Tensor whose final dimension is the optimization variable. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with all entries clamped below by zero. |
Source code in src/silva_networks/optimization.py
project_simplex
Project each row onto a probability simplex.
The projection solves
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Tensor whose final dimension is the simplex variable. |
required |
mass
|
float | Tensor
|
Desired simplex sum. A scalar or batch-broadcastable tensor. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with nonnegative rows whose final-dimension sums equal |
Tensor
|
up to floating-point tolerance. |
Source code in src/silva_networks/optimization.py
silva_constrained_quadratic_layer
Create a package-native constrained quadratic SILVA layer.
Source code in src/silva_networks/optimization.py
silva_cvxpy_layer
Create an optional CVXPYlayers bridge layer.
Source code in src/silva_networks/optimization.py
silva_projected_qp_layer
Create a SILVA projected quadratic-program layer.
Where to Go Next
| Question | Page |
|---|---|
| Where is a constrained layer executed? | Constrained Optimization Example |
| How do optimization layers fit the implicit-layer viewpoint? | Implicit Layers Bridge |
| Can I run the quadratic derivation? | Optimization Layers Notebook |