{"id":21767,"library":"pymetis","title":"PyMetis","description":"PyMetis is a Python wrapper for METIS, a set of serial graph partitioning algorithms. It provides both low-level and high-level interfaces for partitioning graphs. Version 2025.2.2 supports Python >=3.10. The package is actively maintained with periodic releases.","status":"active","version":"2025.2.2","language":"python","source_language":"en","source_url":"https://github.com/inducer/pymetis","tags":["graph partitioning","METIS","combinatorial optimization"],"install":[{"cmd":"pip install pymetis","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for array-like inputs and handling of adjacency structures.","package":"numpy","optional":false}],"imports":[{"note":"Correct import.","wrong":null,"symbol":"pymetis","correct":"import pymetis"},{"note":"part_graph is a function in the pymetis module; direct import may work but less conventional.","wrong":"from pymetis import part_graph","symbol":"pymetis.part_graph","correct":"import pymetis\npart = pymetis.part_graph(nparts, adjacency=adjacency)"}],"quickstart":{"code":"import numpy as np\nimport pymetis\n\n# Define adjacency list for a small graph\n# Each entry is a list of neighbor indices\nadjacency = [[1, 2], [0, 2], [0, 1, 3], [2]]\nnparts = 2\n\ncut, parts = pymetis.part_graph(nparts, adjacency=adjacency)\nprint(f\"Edge cut: {cut}\")\nprint(f\"Partition assignments: {parts}\")","lang":"python","description":"Basic graph partitioning using pymetis."},"warnings":[{"fix":"Preprocess your graph to remove duplicates and self-loops before calling pymetis.","message":"METIS requires that graph adjacency lists contain no duplicate edges and no self-loops. pymetis does not validate inputs; passing invalid graphs can cause silent errors or crashes.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `zero_copy=False` if you need the old behavior of copying the adjacency list.","message":"In v2025.2, the zero-copy mode was introduced. If you rely on adjacency being modified by the C code (e.g., reordering), note that zero-copy may change behavior. The option `zero_copy=True` can be passed to `part_graph` to disable copying.","severity":"breaking","affected_versions":">=2025.2"},{"fix":"Ensure sufficient memory and consider using iterative partitioning for large graphs.","message":"METIS functions can segfault if the graph is too large or if memory is insufficient. pymetis does not provide graceful error handling for such cases.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install pymetis with `pip install pymetis` or upgrade Python.","cause":"pymetis is not installed or Python version is <3.10.","error":"ImportError: No module named pymetis"},{"fix":"Ensure adjacency is a list of lists of ints, e.g., `[[1,2],[0,2]]`.","cause":"Adjacency list contains non-integer elements (e.g., floats) or is not a list of lists.","error":"ValueError: adjacency must be a list of lists of integers"},{"fix":"Update code to unpack two values: cut, parts = pymetis.part_graph(...)","cause":"Using older version where part_graph returned a single value; modern pymetis returns a tuple (cut, parts).","error":"pymetis.part_graph returns only one argument (unexpected)","affected_versions":">=2022.1"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}