Pymetis
A Python wrapper around Metis, a graph partitioning package
Install / Use
/learn @inducer/PymetisREADME
PyMetis: A Python Wrapper for METIS
.. image:: https://gitlab.tiker.net/inducer/pymetis/badges/main/pipeline.svg :alt: Gitlab Build Status :target: https://gitlab.tiker.net/inducer/pymetis/commits/main .. image:: https://github.com/inducer/pymetis/actions/workflows/ci.yml/badge.svg :alt: Github Build Status :target: https://github.com/inducer/pymetis/actions/workflows/ci.yml .. image:: https://badge.fury.io/py/PyMetis.svg :alt: Python Package Index Release Page :target: https://pypi.org/project/pymetis/ .. image:: https://zenodo.org/badge/2199177.svg :alt: Zenodo DOI for latest release :target: https://zenodo.org/badge/latestdoi/2199177
PyMetis is a pybind11 <https://pybind11.readthedocs.io/en/stable/>-based
Python wrapper for the METIS <https://github.com/KarypisLab/METIS> graph
partitioning software by George Karypis, Vipin Kumar, and others.
It currently wraps version 5.2.1 of the METIS library.
Links
Documentation <https://documen.tician.de/pymetis>__ (read how things work)Conda Forge <https://anaconda.org/channels/conda-forge/packages/pymetis/overview>__ (download binary packages for Linux, macOS, Windows)Python package index <https://pypi.org/project/pymetis>__ (download releases)C. Gohlke's Windows binaries <https://www.cgohlke.com/#pymetis>__ (download Windows binaries)GitHub <https://github.com/inducer/pymetis>__ (get latest source code, file bugs)
Installation
The following line should do the job::
pip install pymetis
Quick Start
This graph, adapted from Figure 2 of the METIS
manual <https://raw.githubusercontent.com/KarypisLab/METIS/master/manual/manual.pdf>__ to
use zero-based indexing,
.. image:: https://raw.githubusercontent.com/inducer/pymetis/refs/heads/main/doc/_static/tiny_01.png
can be defined and partitioned into two graphs with
.. code:: python
import numpy as np
import pymetis
adjacency_list = [np.array([4, 2, 1]),
np.array([0, 2, 3]),
np.array([4, 3, 1, 0]),
np.array([1, 2, 5, 6]),
np.array([0, 2, 5]),
np.array([4, 3, 6]),
np.array([5, 3])]
n_cuts, membership = pymetis.part_graph(2, adjacency=adjacency_list)
# n_cuts = 3
# membership = [1, 1, 1, 0, 1, 0, 0]
nodes_part_0 = np.argwhere(np.array(membership) == 0).ravel() # [3, 5, 6]
nodes_part_1 = np.argwhere(np.array(membership) == 1).ravel() # [0, 1, 2, 4]
.. image:: https://raw.githubusercontent.com/inducer/pymetis/refs/heads/main/doc/_static/tiny_01_partitioned.png
