NCET¶
NCET (Neural-network Constraint Embedding Toolkit) converts supported PyTorch neural networks into exact mixed-integer linear constraints. Its graph-aware frontend preserves branches, shared tensors, and residual/skip connections instead of restricting models to sequential structures.
Installation¶
Install the published package from PyPI:
For a local editable installation, run from the repository root:
Minimal use¶
import cvxpy as cp
import numpy as np
from ncet import Bounds, form_milp
model.eval()
bounds = Bounds(
lower=np.array([-1.0, -1.0]),
upper=np.array([1.0, 1.0]),
)
encoding = form_milp(model, bounds, relu_binary_mode="reduced")
y = encoding.outputs[0]
problem = cp.Problem(cp.Maximize(y[0]), encoding.constraints)
problem.solve(solver=cp.SCIPY)
Input bounds do not include a batch dimension
Bounds describe exactly one sample. Use (features,) for an MLP or
(channels, height, width) for an image, not (batch, features) or
(batch, channels, height, width).
See the form_milp() user interface for every argument,
accepted bound form, return field, and public exception.
Documentation map¶
For regular users, please refer to User interface, Examples, and Supported operators for detailed usage and examples.
For developers, please refer to Developer reference for detailed implementation details.
Mathematical background is available in Knowledge.
| Section | Purpose |
|---|---|
| User interface | Build and consume an exact NCET encoding |
| Examples | Representative notebooks and applications |
| Supported operators | Authoritative current capability boundary |
| Exactness contract | Model assumptions and semantic guarantee |
| Mathematical background | Bound propagation and exact formulations |
| Developer reference | FX, GraphIR, propagation, and backend internals |