KKT-HardNet
Learn surrogate, inverse and optimization models with hard constraint projections in JAX.
Define parameters, variables, constraints and a learning task through a compact frontend. OHAGI supplies one shared training and inference engine; PURIN supplies the projection algorithms that enforce the declared constraints.
- Three tasks: constrained surrogate modeling, inverse parameter estimation and unsupervised optimization.
- Differentiable projections: affine and smooth nonlinear equalities, inequalities and bounds, using the appropriate PURIN solver.
- Flexible backbones: functional JAX networks, custom adapters and optional Flax.
- Reusable deployment: export once, load from
metadata.json, and predict repeatedly.
Installation · Basic API · Load and predict · Documentation · Contributing · Citation
Installation
Requires Python 3.10 or newer. Install from PyPI:
python -m pip install kkt-hardnet
The distribution name is kkt-hardnet; the Python import is kkthn.
For editable installs and optional Flax/Orbax integrations, see
installation options.
Basic API
Constrained surrogate
This self-contained example creates a small CSV and learns two nonnegative outputs whose sum matches the input parameter:
from pathlib import Path
import numpy as np
from kkthn import KKTHardNet
p_values = np.linspace(0.4, 1.2, 8)
data = Path("data.csv")
np.savetxt(data, np.column_stack((p_values, 0.6*p_values, 0.4*p_values)),
delimiter=",", header="p,u,v", comments="")
model = KKTHardNet(name="sum_model", train={
"epochs": 2, "batch_size": 2, "seed": 7,
"pretrain": False, "print_every": 0,
})
p = model.add_parameter(["p"])
y = model.add_variable(["u", "v"])
model.constraints.add(y.u + y.v == p.p, y.u >= 0, y.v >= 0)
model.dataset(parameters=data, variables=data)
result = model.model()
prediction = model.predict([0.7])
Choose a learning task
| Task | Data / definition | Entry point |
|---|---|---|
| Surrogate modeling | Parameters and observed variables | model.model() |
| Unsupervised optimization | Parameters and a symbolic objective | model.optimize() |
| Inverse estimation | Observations and unknown coefficients | model.estimate() |
Select type="optimization" or type="parameter_estimation" when constructing
those tasks. See problem definitions for current observation-loss,
unknown-variable, backbone and projection interfaces.
Load and predict
Reload a trained full model and export its deployment bundle:
model = KKTHardNet().load(result["metadata_path"])
prediction = model.predict([0.7])
model.export_inference("deployment/metadata.json")
The same deployment bundle also works through OHAGI:
from ohagi.inference import load
predictor = load("deployment/metadata.json")
for value in [0.4, 0.7, 1.0]:
prediction = predictor.predict([value])
Keep the referenced .jax_export file with metadata.json. Load once and reuse
the predictor. predict returns synchronized NumPy values; predict_jax keeps
outputs on the JAX device. Deployment uses the shared JAX pathway.
Data convention
CSV headers match the declared parameter and variable names. Surrogate and inverse tasks use parameter and variable observations; optimization uses parameter observations. A single CSV may contain both sets of columns.
The HardNet stack
- KKTHN, DAEHN and NLPOPTNet supply problem formulations and framework-specific processing.
- OHAGI composes models, runs the shared learning engine, and handles checkpoints and JAX deployment.
- PURIN owns projection problems, numerical solvers, sparse kernels and projection differentiation.
Compatibility and validation
The PyPI CPU installation matrix covers Python 3.10–3.15 on Linux, Windows and macOS, plus Linux ARM64 on Python 3.13. It uses current compatible JAX releases; regular CI additionally tests JAX 0.6.2 on Python 3.12. See the release workflow for exact environments; accelerator installation follows the JAX guide.
- CI: tests, distribution builds and installation checks.
- Validation: public APIs, numerical references, documentation and code quality.
- Coverage: at least 90% combined statement and branch coverage; the badge links to the measured report for this branch.
- Security: CodeQL analysis and dependency review.
The frontend validation policy also checks API compatibility, checkpoint resume, types, dependency boundaries and cognitive complexity. See validation details.
Documentation
Read the full documentation — installation, tutorials, user guide and API reference.
The full Sphinx guide follows the Read the Docs style: contents, runnable examples, API reference and build instructions.
| Guide | Contents |
|---|---|
| Installation | Source installs, optional integrations and packaging |
| Problem definitions | Modeling, backbones and training |
| Inference | Export, loading and repeated prediction |
| Version notes | Current development behavior |
| Changelog | Recorded changes |
The independent KKTHN site above documents version 2.0.0. The previous kkt-hardnet site is maintained separately; previous documentation sources are preserved in the v1.0.1 archive.
Contributing
Bug reports, examples and focused pull requests are welcome. Read CONTRIBUTING.md for setup, numerical checks and compatibility requirements. Keep generated results, environments and checkpoints out of Git.
Citation
Use CITATION.bib for a copyable BibTeX entry or GitHub's Cite this repository menu for citation metadata. For the method, also cite Physics-informed neural networks with hard nonlinear equality and inequality constraints.
License
Apache License 2.0. Authorship and upstream attribution are recorded in AUTHORS and NOTICE.
Metadata
Release files for kkt-hardnet 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 |
|---|---|---|---|---|
| kkt_hardnet-2.0.0.tar.gz | 144.9 kB | With provenance | Details for kkt_hardnet-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kkt_hardnet-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for kkt_hardnet-2.0.0-py3-none-any.whl |
Total release size: 204.6 kB
Release files / kkt_hardnet-2.0.0.tar.gz
| Download URL | kkt_hardnet-2.0.0.tar.gz |
|---|---|
| Size | 144.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70c9ff3649e44e8b642cfb5791c052e8cf81172b97aa4b80ea56570cb079eeab
|
|
BLAKE2b-256 checksum How to use checksums |
94b11826819538f0a65096eb41210d14d7aa8e8fdcf76cc5f7d2cb4a1e4efdf0
|
| 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 5, 2026.
Transparency logRelease files / kkt_hardnet-2.0.0-py3-none-any.whl
| Download URL | kkt_hardnet-2.0.0-py3-none-any.whl |
|---|---|
| Size | 59.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
610f3c437c014bf6f9c140efe875977a55199fe85b3a588657590f902f3c9835
|
|
BLAKE2b-256 checksum How to use checksums |
9a4ccac75b1459262e39ebe8029a512ff38ffe39b5d561a2b347cde61329aba9
|
| 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 5, 2026.
Transparency logSecurity for kkt-hardnet 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 kkt_hardnet-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 5, 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.