Train neural networks via integer optimisation (CP-SAT) instead of gradient descent.
Project description
OptiML
Train neural networks via global mathematical optimisation (MINLP) instead of gradient descent.
OptiML translates a neural network architecture into a system of constraints and decision variables, then uses a MINLP solver (e.g. Couenne, SCIP) to find the weights that provably minimise the training loss. After solving, the model can be exported to PyTorch for inference.
Installation
pip install -e . # core (numpy + pyomo)
pip install -e ".[pytorch]" # with PyTorch export support
pip install -e ".[all]" # everything
You also need a MINLP solver accessible to Pyomo, for example Couenne or SCIP.
Quick start
import optiml
from optiml.losses import MSELoss
# Ultra-small Edge AI classifier — only 9 parameters
model = optiml.Sequential(
optiml.Linear(2, 2),
optiml.ReLU(M=10),
optiml.Linear(2, 1),
)
model.fit(X_train, y_train, loss=MSELoss(reduction='sum'), solver='couenne')
# Export to PyTorch for inference / deployment
pytorch_model = model.export('pytorch')
Available layers
| Layer | Description |
|---|---|
Linear(in, out) |
Fully-connected layer |
Conv1D(in_ch, out_ch, kernel) |
1-D convolution |
Conv2D(in_ch, out_ch, kernel) |
2-D convolution |
ReLU(M) |
ReLU via big-M formulation |
AvgPool2D(kernel) |
2-D average pooling |
Flatten() |
Flatten spatial dimensions |
Available losses
| Loss | Description |
|---|---|
MSELoss(reduction) |
Mean / sum of squared errors |
SSELoss() |
Sum of squared errors |
MAELoss(reduction) |
Mean / sum of absolute errors |
HuberLoss(delta) |
Smooth L1 loss |
Export
After fitting, call model.export('pytorch') to get a torch.nn.Sequential
with the optimal weights loaded.
Example
See examples/binary_classification.py for a full working example.
It trains a 9-parameter Iris flower classifier (versicolor vs virginica
from petal measurements) and compares OptiML with PyTorch + Adam:
- OptiML finds the mathematically optimal weights in ~7 s, achieving 93.3 % test accuracy on 90 unseen samples.
- PyTorch Adam has a 30 % failure rate (stuck at 50 % accuracy) and even the best restart (selected by training loss) only reaches 91.1 %.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file globoptiml-0.3.1.tar.gz.
File metadata
- Download URL: globoptiml-0.3.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442e1f88670cc46df4d5736b0b45957526d208c13cad77f8adbfe14625a52416
|
|
| MD5 |
e299bd7a0f4908512fccb38bdf44c18c
|
|
| BLAKE2b-256 |
88d5bb3e46d0be049f994af58c5534c7ed9dd3b7833180f1e850afa4ceec1cf0
|
Provenance
The following attestation bundles were made for globoptiml-0.3.1.tar.gz:
Publisher:
publish_pypi.yml on modyf01/optiML
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
globoptiml-0.3.1.tar.gz -
Subject digest:
442e1f88670cc46df4d5736b0b45957526d208c13cad77f8adbfe14625a52416 - Sigstore transparency entry: 1070859665
- Sigstore integration time:
-
Permalink:
modyf01/optiML@094fc81e606a1f4dee1673d6bb2231dafb5a6064 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/modyf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@094fc81e606a1f4dee1673d6bb2231dafb5a6064 -
Trigger Event:
push
-
Statement type:
File details
Details for the file globoptiml-0.3.1-py3-none-any.whl.
File metadata
- Download URL: globoptiml-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7097d4c0c5de0e85cb889c4ee9d2d53df297f5bb5ef51ab0ab73b15b01c2886c
|
|
| MD5 |
3a72e3dc17f4a0806a40fff3f06839d9
|
|
| BLAKE2b-256 |
f1cd4068da2c6f851f42da637d054341ed5a5650cd8c7eab5fc809cfc886837d
|
Provenance
The following attestation bundles were made for globoptiml-0.3.1-py3-none-any.whl:
Publisher:
publish_pypi.yml on modyf01/optiML
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
globoptiml-0.3.1-py3-none-any.whl -
Subject digest:
7097d4c0c5de0e85cb889c4ee9d2d53df297f5bb5ef51ab0ab73b15b01c2886c - Sigstore transparency entry: 1070859689
- Sigstore integration time:
-
Permalink:
modyf01/optiML@094fc81e606a1f4dee1673d6bb2231dafb5a6064 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/modyf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@094fc81e606a1f4dee1673d6bb2231dafb5a6064 -
Trigger Event:
push
-
Statement type: