Skip to main content

Optora

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

Status: pre-alpha (v0.0.3) · 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

Optora is pre-alpha and not yet published on PyPI; install it from a local 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.dro import 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),
    loss_fn=lambda x: (outcomes - x) ** 2,
    initial_point=torch.tensor(0.0),
)
robust_decision = MinimaxSolver().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.

Learn more

  • Full mathematical formulations and design rationale: docs/formulations.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/.

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

License

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optora-0.0.5.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optora-0.0.5-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file optora-0.0.5.tar.gz.

File metadata

  • Download URL: optora-0.0.5.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for optora-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7bf771d77451024396347da2eb9f68cc88a8e2d88b944b7f30eef028c07fc455
MD5 a9e700a817fe16d96279f41c4ae2dc7e
BLAKE2b-256 39b450ec0ed269e40867a01634e46acac4cd94ea855966fac2b9793b30559c58

See more details on using hashes here.

Provenance

The following attestation bundles were made for optora-0.0.5.tar.gz:

Publisher: release.yml on navidsharifi/optora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file optora-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: optora-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for optora-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1b9eea902ce5ac5931111793863501503cc9c57efe35c8bda8ed8f0115e138a4
MD5 4299c36e96b5fcc9a4d9d897a6cd185f
BLAKE2b-256 7999991e5e2c2c7ee0830c669141d4226987f02c89c80596efe36c97b57558cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for optora-0.0.5-py3-none-any.whl:

Publisher: release.yml on navidsharifi/optora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

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