Skip to main content

Optora

A small, composable, PyTorch-native library for distributionally robust optimization (DRO).

Status: alpha · Python 3.10+ · PyTorch ≥2.2 · MIT License

I started building Optora because most of the DRO code I ran into while reading papers lived inside one-off experiment scripts, hard-wired to whatever setup that particular paper used. Optora is a small, composable set of pieces instead — a divergence, an ambiguity set, a solver — that you wire together yourself rather than calling a fit() that picks an algorithm on your behalf. Everything runs on PyTorch tensors, so gradients flow through the whole pipeline and nothing here blocks running on a GPU.

Quick start

Install the latest release from PyPI:

pip install optora

To develop locally, install from a clone in editable mode:

pip install -e ".[dev,docs]"

Find the decision x that minimizes the worst-case squared error against a KL-ball of plausible distributions over four observed outcomes:

import torch
from optora import GradientDescent, KLAmbiguitySet, MinimaxProblem, MinimaxSolver

nominal = torch.tensor([0.25, 0.25, 0.25, 0.25])
outcomes = torch.tensor([1.0, 2.0, 3.0, 10.0])

problem = MinimaxProblem(
  ambiguity_set=KLAmbiguitySet(
    nominal=nominal,
    radius=0.1,
    dual_solver=GradientDescent(step_size=0.1, max_iter=300, tol=1e-7),
  ),
    loss_fn=lambda x: (outcomes - x) ** 2,
    initial_point=torch.tensor(0.0),
)
outer_solver = GradientDescent(step_size=0.01, max_iter=200, tol=1e-6)
robust_decision = MinimaxSolver(solver=outer_solver).solve(problem).point

What is implemented today

Ambiguity sets (optora.dro), the divergences underneath them (optora.divergences), and the solvers underneath those (optora.solvers) are implemented end to end: KLAmbiguitySet, PhiAmbiguitySet (plus ChiSquareAmbiguitySet and TotalVariationAmbiguitySet), and WassersteinAmbiguitySet, wired together by MinimaxSolver. Every piece is covered by pytest tests checked against known closed-form results, independent grid-search cross-checks, convergence limits, and monotonicity properties, and the whole package is type-checked under mypy's strict mode.

Every main class is importable from the package root (from optora import KLAmbiguitySet) or from its subpackage (from optora.dro import KLAmbiguitySet); both name the same object. Convergence diagnostics and helper functions live in optora.core.

Learn more

  • Full mathematical formulations and design rationale: docs/formulations.md.
  • Training an nn.Module against a DRO objective with torch.optim: docs/training.md.
  • Runnable, visualized DRO examples (GitHub-only, not shipped with the package): examples/ — install with the examples extra (pip install -e ".[examples]").
  • API reference: built with Zensical from source docstrings, see docs/.
  • Contributing: development workflow, coding style, and the PR checklist live in CONTRIBUTING.md.

Development

Optora targets Python 3.10+ and PyTorch 2.2+. From an activated virtual environment in the repository root:

pip install -e ".[dev,docs]"
pytest
ruff check .
ruff format --check .
mypy

Generate the hierarchical API reference, preview it, or build the complete documentation site without maintaining API pages or navigation by hand:

python -m tools.docs generate
python -m tools.docs check
python -m tools.docs serve
python -m tools.docs build

generate writes one page per public module (with its classes and functions) plus a matching index for every subpackage, and rewrites the API navigation in zensical.toml. Because the generated pages are committed, plain zensical serve and zensical build also work from a fresh clone; run python -m tools.docs serve whenever optora/ changes so the pages are regenerated first. check fails when the committed pages drift from the sources, and runs in CI.

Every push to main publishes the site to GitHub Pages through .github/workflows/docs.yml, which enables Pages automatically and deploys the freshly generated build.

License

Optora is distributed under the MIT License; see LICENSE for the full text.

Metadata

Release files for optora 0.1.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 optora 0.1.0
File Size Uploaded Provenance Actions
optora-0.1.0.tar.gz 37.9 kB With provenance Details for optora-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 84.2 kB

Release files / optora-0.1.0.tar.gz

Download URL optora-0.1.0.tar.gz
Size 37.9 kB
Tags Source
SHA-256 checksum
How to use checksums
013426c9bfb344b625d8630dc1fe42ca6577e50588d648e8edaa28010dc1821a
BLAKE2b-256 checksum
How to use checksums
774269acbe72ebdaa1d546074d8ec1ba77b550d00e74bcc4b30aba36494978ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / optora-0.1.0-py3-none-any.whl

Download URL optora-0.1.0-py3-none-any.whl
Size 46.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5024af3000eb08c942b92aaacef338103914ee338c64576e4144fea2cda96f34
BLAKE2b-256 checksum
How to use checksums
059e96ca087b1159278afc900e68423910aae3867d78e8338364d215274dfc9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Security for optora 0.1.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 optora-0.1.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 Oct 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.

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