Skip to main content

OHAGI logo

OHAGI

One JAX engine for building, training and deploying hard-constrained neural models.

CI Validation CodeQL Dependency review Coverage

Python 3.10–3.15 CPU platforms JAX License: Apache 2.0 Citation: BibTeX

Combine a neural backbone, a differentiable projection and a loss in one learning workflow. OHAGI powers KKTHN, DAEHN and NLPOPTNet while leaving framework-specific problem processing in the frontends and numerical projection in PURIN.

  • Composable models: shared backbone, projection and loss interfaces.
  • Flexible training: functional JAX networks, optional Flax/Optax adapters, and optional Orbax checkpoints for training continuation.
  • One deployment pathway: JAX export and metadata.json loading across frontends.
  • Repeated inference: load and warm the exported signature once, then reuse it.

Installation · Basic API · Load and predict · Documentation · Contributing · Citation

Installation

Requires Python 3.10 or newer. Install from PyPI:

python -m pip install ohagi

From a local stack checkout, use python -m pip install ./purin ./ohagi. Optional integrations are available as ohagi[flax,orbax,optax,plotting].

Basic API

Train a small projected network whose outputs satisfy u + v = b:

import jax
import jax.numpy as jnp
from purin import Distance, Projection
from ohagi import Adam, ProjectedModel, Trainer
from ohagi.nn import MLPAdapter, MLPBackbone
from ohagi.losses import supervised_mse
from ohagi.training.engine import create_train_state

jax.config.update("jax_enable_x64", True)

problem = Projection()
p = problem.add_parameter(["b"])
y = problem.add_variable(["u", "v"])
problem.objective = 0.0
problem.constraints.add(y.u + y.v == p.b)

projection = Distance(problem, "linear-equality").prepare(batch_size=4)
backbone = MLPAdapter(MLPBackbone(hidden_sizes=(16, 16)))
model = ProjectedModel(backbone, projection)
optimizer = Adam(learning_rate=1e-3)
state = create_train_state(
    backbone, optimizer, jax.random.PRNGKey(0), input_dim=1, output_dim=2
)
data = {
    "inputs": jnp.ones((8, 1)),
    "theta": jnp.ones((8, 1)),
    "solution": jnp.tile(jnp.array([0.8, 0.2]), (8, 1)),
}
result = Trainer(model, supervised_mse(), optimizer).fit(
    state, data, epochs=2, batch_size=4
)
outputs, _ = model.apply(
    result.state.parameters, result.state.model_state, jnp.ones((4, 1))
)
print(outputs["projected"])

The backbone predicts a candidate; PURIN projects it onto the constraint set; OHAGI evaluates the loss and updates the model through the shared training engine. Choose solver tolerances and numerical precision for the problem.

Load and predict

A trained frontend can export its graph using model.export_inference("deployment/metadata.json"). Load that bundle once:

from ohagi.inference import load

predictor = load("deployment/metadata.json")
for value in [0.4, 0.7, 1.0]:
    prediction = predictor.predict([value])

Use inputs matching the exported signature. Keep the referenced .jax_export file with metadata.json; metadata alone is not the complete model. predict returns synchronized NumPy values, while predict_jax returns a JAX array. The deployment graph does not require the originating frontend, Flax or Orbax. Orbax training checkpoints are separate from inference bundles.

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.

Optional Flax, Optax and Orbax integrations and exported inference bundles are also exercised across Linux, Windows and macOS.

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.

Resource Contents
Artifacts and checkpoints Model bundles, JAX deployment and training continuation
Contribution guide Engine boundaries, development setup and validation
Validation policy API, numerical and quality checks
Changelog Initial release scope and changes

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.

License

Apache License 2.0. Authorship and upstream attribution are recorded in AUTHORS and NOTICE.

Changelog · Report an issue

Metadata

Release files for ohagi 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ohagi 1.0.0
File Size Uploaded Provenance Actions
ohagi-1.0.0.tar.gz 884.2 kB With provenance Details for ohagi-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ohagi 1.0.0
File Interpreter ABI Platform Actions
ohagi-1.0.0-py3-none-any.whl Python 3 none any Details for ohagi-1.0.0-py3-none-any.whl

Total release size: 985.6 kB

Release files / ohagi-1.0.0.tar.gz

Download URL ohagi-1.0.0.tar.gz
Size 884.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1712f969b615a93091067750819e33a3e15fd639feec0638648d6c605e1d69b5
BLAKE2b-256 checksum
How to use checksums
5cc5eec5d69eba3bfa34328074e3d826f175ad265249eb32ea17ce58fa7377a9
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 log

Release files / ohagi-1.0.0-py3-none-any.whl

Download URL ohagi-1.0.0-py3-none-any.whl
Size 101.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3772f093ecdc179cf31df810606c67a0193a2da7eedd128d5f3f5b38292c947
BLAKE2b-256 checksum
How to use checksums
6050507487e2b9be736a951ab7ce8f3fa575b88d611f3f9ca047437cc288b6a1
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 log

Security for ohagi 1.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.

Select from 2 files

Attestation for ohagi-1.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 log

A 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page