Metadata-Version: 2.4
Name: ohagi
Version: 1.0.0
Summary: Composable constrained learning and differentiable sparse optimization in JAX
Author: SOULS-TAMU contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/SOULS-TAMU/Ohagi
Project-URL: Repository, https://github.com/SOULS-TAMU/Ohagi
Project-URL: Documentation, https://ohagi.readthedocs.io/en/latest/
Keywords: jax,constrained-learning,differentiable-optimization
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: purin<2.0.0,>=1.0.0
Requires-Dist: jax>=0.4.30
Requires-Dist: numpy>=1.26
Requires-Dist: scipy>=1.11
Requires-Dist: absl-py
Requires-Dist: flatbuffers
Provides-Extra: docs
Requires-Dist: Sphinx<9,>=8.2; extra == "docs"
Requires-Dist: sphinx-rtd-theme<4,>=3.1; extra == "docs"
Requires-Dist: myst-parser<5,>=4; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: pytest-cov>=5; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: osqp>=1; extra == "dev"
Requires-Dist: absl-py; extra == "dev"
Requires-Dist: flatbuffers; extra == "dev"
Provides-Extra: plotting
Requires-Dist: matplotlib>=3.8; extra == "plotting"
Provides-Extra: flax
Requires-Dist: flax>=0.8.5; extra == "flax"
Provides-Extra: orbax
Requires-Dist: orbax-checkpoint>=0.6.4; extra == "orbax"
Provides-Extra: optax
Requires-Dist: optax>=0.2.4; extra == "optax"
Provides-Extra: export
Requires-Dist: absl-py; extra == "export"
Requires-Dist: flatbuffers; extra == "export"
Provides-Extra: nlpoptnet
Requires-Dist: flax>=0.8.5; extra == "nlpoptnet"
Requires-Dist: optax>=0.2.4; extra == "nlpoptnet"
Requires-Dist: matplotlib>=3.8; extra == "nlpoptnet"
Requires-Dist: absl-py; extra == "nlpoptnet"
Requires-Dist: flatbuffers; extra == "nlpoptnet"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/SOULS-TAMU/Ohagi/main/assets/ohagi-logo.png" alt="OHAGI logo" width="200">
</p>

# OHAGI

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

[![CI](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/ci.yml?query=branch%3Amain)
[![Validation](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/validation.yml/badge.svg?branch=main)](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/validation.yml?query=branch%3Amain)
[![CodeQL](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/codeql.yml?query=branch%3Amain)
[![Dependency review](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/dependency-review.yml/badge.svg?branch=main)](https://github.com/SOULS-TAMU/Ohagi/actions/workflows/dependency-review.yml?query=branch%3Amain)
[![Coverage](https://raw.githubusercontent.com/SOULS-TAMU/Ohagi/codex/coverage/coverage.svg)](https://github.com/SOULS-TAMU/Ohagi/tree/codex/coverage)

[![Python 3.10–3.15](https://img.shields.io/badge/Python-3.10%E2%80%933.15-3776AB?logo=python&logoColor=white)](https://github.com/SOULS-TAMU/Ohagi/blob/main/.github/workflows/release.yml)
[![CPU platforms](https://img.shields.io/badge/CPU-Linux%20%7C%20Windows%20%7C%20macOS-555555)](https://github.com/SOULS-TAMU/Ohagi/blob/main/.github/workflows/ci.yml)
[![JAX](https://img.shields.io/badge/Powered_by-JAX-8A2BE2)](https://docs.jax.dev/)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/SOULS-TAMU/Ohagi/blob/main/LICENSE)
[![Citation: BibTeX](https://img.shields.io/badge/Cite-BibTeX-6F4E37)](https://github.com/SOULS-TAMU/Ohagi/blob/main/CITATION.bib)

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](#installation) · [Basic API](#basic-api) · [Load and predict](#load-and-predict) · [Documentation](#documentation) · [Contributing](#contributing) · [Citation](#citation)

## Installation

Requires **Python 3.10 or newer**. Install from PyPI:

```shell
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**:

```python
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:

```python
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](https://github.com/SOULS-TAMU/kkt-hardnet/tree/main),
  [DAEHN](https://github.com/SOULS-TAMU/dae-hardnet/tree/main) and
  [NLPOPTNet](https://github.com/SOULS-TAMU/nlpoptnet)** supply problem formulations
  and framework-specific processing.
- **[OHAGI](https://github.com/SOULS-TAMU/Ohagi/tree/main)** composes models,
  runs the shared learning engine, and handles checkpoints and JAX deployment.
- **[PURIN](https://github.com/SOULS-TAMU/Purin/tree/main)** 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](https://github.com/SOULS-TAMU/Ohagi/blob/main/.github/workflows/release.yml)
for exact environments; accelerator installation follows the
[JAX guide](https://docs.jax.dev/en/latest/installation.html).

- **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](https://ohagi.readthedocs.io/en/latest/)** — installation, tutorials, user guide and API reference.

The full Sphinx guide follows the Read the Docs style: [contents](https://github.com/SOULS-TAMU/Ohagi/blob/main/docs/index.rst),
[runnable examples](https://github.com/SOULS-TAMU/Ohagi/blob/main/docs/examples/index.rst), [API reference](https://github.com/SOULS-TAMU/Ohagi/blob/main/docs/api/index.rst)
and [build instructions](https://github.com/SOULS-TAMU/Ohagi/blob/main/docs/BUILD.md).

| Resource | Contents |
| --- | --- |
| [Artifacts and checkpoints](https://github.com/SOULS-TAMU/Ohagi/blob/main/docs/artifacts.md) | Model bundles, JAX deployment and training continuation |
| [Contribution guide](https://github.com/SOULS-TAMU/Ohagi/blob/main/CONTRIBUTING.md) | Engine boundaries, development setup and validation |
| [Validation policy](https://github.com/SOULS-TAMU/Ohagi/blob/main/.github/validation/README.md) | API, numerical and quality checks |
| [Changelog](https://github.com/SOULS-TAMU/Ohagi/blob/main/CHANGELOG.md) | Initial release scope and changes |

## Contributing

Bug reports, examples and focused pull requests are welcome. Read
[CONTRIBUTING.md](https://github.com/SOULS-TAMU/Ohagi/blob/main/CONTRIBUTING.md) for setup, numerical checks and compatibility
requirements. Keep generated results, environments and checkpoints out of Git.

## Citation

Use [CITATION.bib](https://github.com/SOULS-TAMU/Ohagi/blob/main/CITATION.bib) for a copyable BibTeX entry or GitHub's
**Cite this repository** menu for [citation metadata](https://github.com/SOULS-TAMU/Ohagi/blob/main/CITATION.cff).

## License

[Apache License 2.0](https://github.com/SOULS-TAMU/Ohagi/blob/main/LICENSE). Authorship and upstream attribution are recorded
in [AUTHORS](https://github.com/SOULS-TAMU/Ohagi/blob/main/AUTHORS) and [NOTICE](https://github.com/SOULS-TAMU/Ohagi/blob/main/NOTICE).

[Changelog](https://github.com/SOULS-TAMU/Ohagi/blob/main/CHANGELOG.md) · [Report an issue](https://github.com/SOULS-TAMU/Ohagi/issues)
