Skip to content

inducer/pymetis

Repository files navigation

PyMetis: A Python Wrapper for METIS

Gitlab Build Status Github Build Status Python Package Index Release Page Zenodo DOI for latest release

PyMetis is a pybind11-based Python wrapper for the METIS graph partitioning software by George Karypis, Vipin Kumar, and others.

It currently wraps version 5.2.1 of the METIS library.

Links

Installation

The following line should do the job:

pip install pymetis

Quick Start

This graph, adapted from Figure 2 of the METIS manual to use zero-based indexing,

https://raw.githubusercontent.com/inducer/pymetis/refs/heads/main/doc/_static/tiny_01.png

can be defined and partitioned into two graphs with

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]

https://raw.githubusercontent.com/inducer/pymetis/refs/heads/main/doc/_static/tiny_01_partitioned.png

About

A Python wrapper around Metis, a graph partitioning package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 18