Metadata-Version: 2.4
Name: metis-rs
Version: 0.1.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
License-File: LICENSE
Summary: Python bindings for metis-rs, a pure-Rust graph partitioner (no C/CMake build step)
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/pjuangph/metis-rs-py
Project-URL: metis-rs (Rust core), https://github.com/pjuangph/metis-rs

# Introduction
`metis-rs` is a pure-Rust multilevel k-way graph partitioner inspired by
[METIS](http://glaros.dtc.umn.edu/gkhome/metis/metis/overview). This package
is a thin [PyO3](https://pyo3.rs) wrapper around it — no C dependencies, no
CMake, no local METIS build. `pip install metis-rs` gets you a working
partitioner via prebuilt wheels.

All partitioning logic lives in the [`metis-rs`](https://github.com/pjuangph/metis-rs)
Rust crate, pulled in here as a normal Cargo dependency. Nothing is
reimplemented in Python — bumping the `metis-rs` version in
[`Cargo.toml`](Cargo.toml) is the only thing needed to pick up upstream changes.

## Installation

Installation from pip:
```bash
pip install metis-rs
```

Installation from source using [uv](https://docs.astral.sh/uv/) (requires a
[Rust toolchain](https://rustup.rs)):
```bash
uv sync
```

Importing the python package after installing:
```python
import metis_rs
```

[Link to documentation](https://pjuangph.github.io/metis-rs-py)

# Tutorial
- [Quickstart](https://colab.research.google.com/github/pjuangph/metis-rs-py/blob/main/tutorials/Getting_Started.ipynb) — build a graph, partition it, visualize the result, weighted graphs, and a grid/mesh partitioning example.

## Usage

```python
import metis_rs

# A simple 4-vertex path graph: 0-1-2-3, stored in CSR format
xadj = [0, 1, 3, 5, 6]
adjncy = [1, 0, 2, 1, 3, 2]
g = metis_rs.Graph(4, xadj, adjncy)

edge_cut, part = metis_rs.partition(g, 2)
assert len(part) == 4
assert all(p < 2 for p in part)
```

### Weighted graphs

```python
import metis_rs

g = metis_rs.Graph(
    3,
    [0, 2, 4, 6],
    [1, 2, 0, 2, 0, 1],
    adjwgt=[5, 1, 5, 1, 1, 1],
    vwgt=[10, 1, 10],
)
edge_cut, part = metis_rs.partition(g, 2)
```

## API

### `Graph(n, xadj, adjncy, adjwgt=None, vwgt=None)`

CSR (Compressed Sparse Row) graph representation.

| Argument | Type | Description |
|---|---|---|
| `n` | `int` | Number of vertices |
| `xadj` | `list[int]` | Row pointers (length `n + 1`) |
| `adjncy` | `list[int]` | Column indices (neighbor lists) |
| `adjwgt` | `list[int]`, optional | Edge weights, aligned with `adjncy` (default: all 1) |
| `vwgt` | `list[int]`, optional | Vertex weights, length `n` (default: all 1) |

`Graph` also exposes `.n` and `.edge_cut(part)`.

### `partition(graph, nparts) -> (edge_cut, part)`

Partitions `graph` into `nparts` parts. `part[u]` is the 0-based part ID
assigned to vertex `u`.

## Development

```bash
uv sync --group test
uv run pytest
```

Rebuilding after editing the Rust source:
```bash
uv sync
```

### Building the docs

```bash
uv sync --group docs
uv run sphinx-build -b html docs docs/build/html
```
Open `docs/build/html/index.html`, or see the published docs at
https://pjuangph.github.io/metis-rs-py/.

# License
[MIT](LICENSE)

