NLPOptNet
Parametric nonlinear optimization through a neural warm start and differentiable local projection in JAX.
NLPOptNet supplies the nonlinear problem, local approximations, and task policy to the shared OHAGI learning engine and PURIN projection library. It has no independent neural backbone implementation, optimizer step, epoch engine, CP solver, or deployment runtime.
Install
Install or upgrade NLPOptNet and its dependencies from PyPI.
python -m pip install --upgrade nlpoptnet
On Linux with an NVIDIA CUDA 12 GPU, use python -m pip install "nlpoptnet[cuda12]".
From a source checkout, run python -m pip install ..
CPU CI targets Python 3.10–3.14 on Linux, Windows and macOS. Python 3.15 is pending compatible wheels for the Flax dependency chain. The existing training backend uses Flax and Optax through OHAGI. Deployment through OHAGI requires neither Flax nor NLPOptNet.
Define and train a problem
from nlpoptnet import NLPOptNet
model = NLPOptNet(name="example", config={
"epochs": 100, "batch_size": 32, "learning_rate": 1e-3,
"hidden_size": 64, "hidden_layers": 2,
})
p = model.add_parameter(["p"])
y = model.add_variable(["u", "v"])
model.objective((y.u - p.p)**2 + 0.5*y.v**2)
model.constraints.equality.add(y.u + y.v == p.p)
model.constraints.inequality.add(y.u <= 1.5)
model.constraints.box.add(y.u >= 0, y.v >= 0, y.u <= 2, y.v <= 2)
model.box(lower=0.4, upper=1.4, num_samples=1024)
model.build()
result = model.optimize()
The existing NLPOptNet and ProblemBuilder interfaces, configuration aliases,
sampling options, result dictionary, and output filenames remain unchanged.
CSV datasets, simplex/polytope sampling, matrix/vector expressions, and manual
or automatic problem scaling remain supported.
Shared workflow
- Define the objective, equalities, inequalities, bounds, and parameter domain.
- OHAGI constructs the configured backbone, which predicts primal and dual warm starts using its shared Linen MLP head construction.
- NLPOptNet forms the local diagonal quadratic objective and linearized constraints. PURIN solves the local projection and differentiates it.
- NLPOptNet supplies its modified-Lagrangian/consistency loss and reporting policy; OHAGI performs optimizer transitions and compiled epoch execution.
- OHAGI saves the shared JAX model bundle and prepares repeated inference.
cp_mode, Ruiz equilibration, adjoint settings, and k_layer retain their
existing meanings. Warm-up update behavior is preserved explicitly by the
frontend policy. The underlying numerical operations and default initialization
remain unchanged.
Save, load, and infer
Full-model metadata is returned in result["metadata_path"]. Symbolic models
can be reopened with the existing frontend API:
restored = NLPOptNet().load(result["metadata_path"])
predictions = restored.predict(parameter_batch)
Use the loaded model to inspect original-problem KKT residuals at inference:
info = restored.predict_with_info(
parameter_batch, adaptive=True, max_layers=10, primal_tolerance=1e-6
)
print(info["primal_feasible"], info["kkt_satisfied"], info["layers_used"])
print(info["residuals"], info["cp_iterations"])
Pass a single parameter vector or a batch as the first argument. Adaptive depth
stops each sample on primal feasibility and can compile new JAX batch shapes
as samples finish. The KKT check also tests dual feasibility, complementarity
and stationarity in original problem units. Use PURIN from its GitHub main
branch for CP iteration counts. With PURIN 1.0.1, that field returns None.
Regular prediction and training use fixed depth.
For deployment, export once and load using only the metadata path:
model.export_inference("deployment/metadata.json")
from ohagi.inference import load
predictor = load("deployment/metadata.json")
prediction = predictor(single_input)
Keep the referenced .jax_export file alongside metadata.json. Loading warms
one JAX signature; reuse the predictor across requests. predict_jax returns a
JAX array, while predict returns synchronized NumPy output.
The only model format is the shared ohagi_model_v1 JAX bundle. Its parameter
archive uses ohagi_pytree_npz_v1; inference uses ohagi_jax_inference_v1 and
ohagi_jax_program_v1. Deployment loads directly through OHAGI without
reconstructing the nonlinear problem or importing frontends, Flax, or Orbax.
There are no legacy model readers or native export backends.
Source organization
src/nlpoptnet/
├── __init__.py
├── api/
│ ├── __init__.py
│ ├── root.py
│ ├── model.py
│ ├── configuration.py
│ ├── network.py
│ ├── data.py
│ ├── problem.py
│ ├── projection.py
│ ├── objectives.py
│ ├── fit.py
│ ├── predict.py
│ ├── reporting.py
│ ├── deployment.py
│ └── formulation/
│ ├── __init__.py
│ ├── variables.py
│ ├── parameters.py
│ ├── expressions.py
│ ├── constraints.py
│ ├── bounds.py
│ ├── builder.py
│ ├── compiler.py
│ ├── approximation.py
│ └── scaling.py
└── serialization/
├── __init__.py
├── definition.py
└── artifacts.py
model.py binds the existing public methods to small task modules.
formulation/ owns expression handling, variable packing, objective/residual
evaluation, derivatives, scaling, and local subproblem construction. These are
mathematical problem resources, not a second neural training framework.
The flat API adapters supply those resources to OHAGI/PURIN. Serialization records the nonlinear definition and captures the prediction graph for OHAGI's common bundle writer. Standard Flax training state and optimizer transport are provided by OHAGI, rather than a package-specific training-state class.
The old optimization/, problems/, empty adapters/, CP forwarding modules,
and _aliases.py catalog are removed. Obsolete private import paths are retired;
the benchmark-facing model interface is preserved.
Development and validation
Packaging uses the src layout and pyproject.toml. See CONTRIBUTING.md for development guidelines, and
CITATION.cff for citation information.
See CHANGELOG.md, LICENSE, and NOTICE for changes, licensing, and attribution.
License
This project is licensed under the Apache License, Version 2.0.
Original authorship and applicable upstream notices are retained in NOTICE.
Optional sparse inequality projection
Set config["inequality_support"] to one list of structural variable-column
indices per inequality row before building the model. Include every entry that
can be nonzero anywhere in the problem domain. Omitted entries are assumed to
be structurally zero; a sparsity pattern sampled at one point is insufficient.
PURIN packs those entries and uses sparse products in CP and its implicit
adjoint. Equality matrices stay dense, and quadratic diagonals stay vectors.
NLPOptNet 2.0 uses PURIN 1.0.1 or newer for both paths. Omit this option to retain dense behavior. The option is preserved by model
serialization; loading inference still takes only metadata.json.
Paper and experiments
See the NLPOpt-Net paper and the article experiments. The existing Read the Docs site describes the main-branch release. Use the training and inference examples above for this development branch.
Metadata
Release files for nlpoptnet 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nlpoptnet-2.0.0.tar.gz | 72.3 kB | With provenance | Details for nlpoptnet-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nlpoptnet-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for nlpoptnet-2.0.0-py3-none-any.whl |
Total release size: 142.1 kB
Release files / nlpoptnet-2.0.0.tar.gz
| Download URL | nlpoptnet-2.0.0.tar.gz |
|---|---|
| Size | 72.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e1f7f0f7ed00e606af163d0fe357d844b4478777384eeb748e10d20e0529a0f
|
|
BLAKE2b-256 checksum How to use checksums |
45068d97b657dce1f2f5a3277f59c375756482843961a1acd306deddc1c485c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / nlpoptnet-2.0.0-py3-none-any.whl
| Download URL | nlpoptnet-2.0.0-py3-none-any.whl |
|---|---|
| Size | 69.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c294073a1f399c9998714d45eb59d596f4778ea3262279495f4ba467c99442a
|
|
BLAKE2b-256 checksum How to use checksums |
2e1b011e99aa2cb3e6dc772017de1ef2bfda89dcc24728965fbec6f0e96c1a5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for nlpoptnet 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for nlpoptnet-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.