Metadata-Version: 2.4
Name: faster-or-curvature
Version: 1.2.2
Summary: Exact Ollivier-Ricci curvature for graphs, computed with one minimum cut per edge
Author: Giorgio Micaletto
License-Expression: MIT
Project-URL: Repository, https://github.com/GiorgioMB/faster-or-curvature
Project-URL: Changelog, https://github.com/GiorgioMB/faster-or-curvature/blob/main/CHANGELOG.md
Keywords: ollivier-ricci,curvature,graphs,optimal transport,minimum cut
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numba>=0.62
Requires-Dist: numpy>=2.2
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: networkx>=3.3; extra == "dev"
Requires-Dist: scipy; extra == "dev"
Dynamic: license-file

# faster-or-curvature

[![PyPI version](https://img.shields.io/pypi/v/faster-or-curvature.svg)](https://pypi.org/project/faster-or-curvature/)
[![Downloads](https://img.shields.io/pepy/dt/faster-or-curvature)](https://pepy.tech/project/faster-or-curvature)
[![License](https://img.shields.io/pypi/l/faster-or-curvature.svg)](https://pypi.org/project/faster-or-curvature/)

Exact Ollivier–Ricci curvature of every edge of an unweighted graph, with one
minimum cut per edge, in exact integer arithmetic and without a distance matrix.

```bash
pip install faster-or-curvature        # imports as orcut
```

Any two vertices of the closed neighbourhoods of an edge are at distance at most
three, so the Kantorovich dual of the edgewise transport problem has an integral
optimum with potentials in {0, 1, 2, 3}. Written in unary, it is a maximum-weight
closure, solved by one s–t minimum cut. Its arcs come from adjacency and common
neighbours only (pairs at distance three give none), and with one relay node per
common neighbour the network is linear in the adjacency lists of the vertices that
carry net mass. The same holds for any one-step measures (lazy, non-lazy, any idleness,
weighted walks), and, with 2r layers, for measures supported on balls of radius r.

```python
import orcut
g = orcut.Graph.from_edges([(0, 1), (1, 2), (2, 0), (2, 3)])  # or a networkx graph / PyG Data
orcut.curvature(g)                      # lazy (idleness 1/(deg+1)), aligned with g.edges (u < v)
orcut.curvature(g, "lly")               # Lin–Lu–Yau; also "nonlazy", a number p (idleness p),
orcut.curvature(g, orcut.Walk(weights=w, idleness=0.5))   # or a weighted walk (integer weights)
orcut.curvature(g, exact_fraction=True) # also W1 as an exact integer fraction per edge
c = orcut.certify(g, (0, 1))            # an optimal plan and an optimal 1-Lipschitz potential
c.verified, c.verify(g)                 # checked exactly when built, and re-checkable from scratch
orcut.ball_curvature(g, 2)              # Ollivier's ball measures, radius 2 (layered closure)
orcut.walk_curvature(g, 2)              # two-step lazy random walk
orcut.affected_edges(g2, changed_pairs) # after inserting/deleting pairs: the only edges to recompute
```

## Installation

Python 3.10 or later; numpy and numba come with it. From a clone, `pip install -e ".[dev]"` adds what
the tests need (pytest, networkx, scipy), and `pytest -q` runs them.

Without a package index (for example on a cluster without PyPI access), copy the wheel over from a
machine that has it:

```bash
pip download faster-or-curvature --no-deps -d wheels/                # where PyPI is reachable
conda install -c conda-forge "numpy>=2.2" "numba>=0.62"               # on the cluster
pip install --no-index --no-deps wheels/faster_or_curvature-*.whl
```

## Versions

* **1.2.0** is the version described in *The Min-Cut Formulation of Ollivier–Ricci Curvature*
  (Giorgio Micaletto, arXiv, forthcoming); `pip install faster-or-curvature==1.2.0` reproduces it.
  It adds witness relays (one zero-weight relay per common neighbour) for the pairs at distance 2
  that the bitset network would list one by one, chosen per edge when the network gets smaller, and a
  bound on the bitset work (four words per adjacency entry) beyond which an edge is solved on the
  linear-size witness network (`orcut._witness`, also usable on its own). Values
  unchanged (tested). 1.2.1 and 1.2.2 change documentation only.
* **1.1.0**: `orcut.curvature` (any one-step measure, exact fractions, diagnostics, ablation
  flags), certificates (`orcut.certify`), the layered closure for supports of radius r
  (`ball_curvature`, `walk_curvature`), and exact incremental updates (`affected_edges`). The kernel of 1.0.0 is kept unchanged in
  `orcut/_kernels.py`, and `orcut.curvature` returns the same values bit for bit (tested).
* **1.0.0** is the solver used for every exact curvature in Micaletto and Nigrelli,
  *From Proxy to Certificate: Two-Sided Ollivier–Ricci Bounds from Balanced Forman Curvature*:
  its compiled kernels (`orcut/_kernels.py`) are those of `curvature_transfer`.

## Layout

| Path | Contents |
| --- | --- |
| `orcut/graph.py` | CSR graph, canonical undirected edges, networkx / PyG / edge-list constructors |
| `orcut/_kernels.py` | the 1.0.0 kernel (frozen): lazy, non-lazy, LLY, and the TLW certificate |
| `orcut/_core.py` | the general one-step kernel: per-vertex masses, bitsets, relays, witness relays, ablation flags, diagnostics |
| `orcut/_witness.py` | the linear-size witness network on its own (one relay per common neighbour; no bitsets, no distances) |
| `orcut/_layered.py` | W1 on bounded integer metrics by a layered closure; ball and multi-step measures; certificates |
| `orcut/measures.py` | measure specifications (`"lazy"`, `"nonlazy"`, `"lly"`, idleness p, `Walk`) |
| `orcut/certify.py` | per-edge certificates (plan and potential) and their exact verification |
| `orcut/_reference.py` | independent oracle: full local distance matrix, three-level closure, recursive Dinic |
| `orcut/api.py` | `curvature`, `ball_curvature`, `walk_curvature`, `affected_edges`, `exact` (1.0.0 API), thread control |
| `tests/` | kernels against each other (bit for bit), against the oracle, and against linear programming |

## Citation

Version 1.2.0 is the version described in *The Min-Cut Formulation of Ollivier–Ricci Curvature*
(Giorgio Micaletto), which will appear on arXiv. Until then, please cite the software:

```bibtex
@misc{faster-or-curvature,
  author       = {Giorgio Micaletto},
  title        = {faster-or-curvature: Exact Ollivier--Ricci curvature in exact integer arithmetic},
  year         = {2026},
  version      = {1.2.0},
  howpublished = {\url{https://github.com/GiorgioMB/faster-or-curvature}},
  note         = {Version 1.2.0, described in ``The Min-Cut Formulation of Ollivier--Ricci Curvature''},
}
```

GitHub's "Cite this repository" button gives the same entry, from `CITATION.cff`.
<!--
When the paper is on arXiv, replace the entry above with the preprint (and fill in the
preferred-citation block at the end of CITATION.cff):

@misc{micaletto2026mincut,
  author        = {Giorgio Micaletto},
  title         = {The Min-Cut Formulation of {Ollivier--Ricci} Curvature},
  year          = {2026},
  eprint        = {XXXX.XXXXX},
  archivePrefix = {arXiv},
}

and, once the conference version is out, with @inproceedings{..., booktitle = {...}, pages = {...}}.
-->
