Skip to main content

subgraphsearch

CI PyPI crates.io: subgraphsearch crates.io: subgraphsearch-core

Find induced subgraphs with a prescribed number of vertices and edges in a graph, or with a given total weight in a weighted graph. Searches are fast, reproducible from a seed and come with diagnostics for tuning them, and near misses are reported alongside exact solutions, so the search also works as an approximation algorithm. Many graph formats are supported.

On these targets subgraphsearch finds solutions in milliseconds where general solvers take seconds or give out, and on the maximum diversity problem, choosing items as different from each other as possible, it reaches the best published values in about a second (see How it compares).

The same search finds induced cycles, paths, trees and cliques, regular subgraphs of a given degree, and subgraphs through given vertices.

One random graph with 36 vertices and 156 edges, searched four times and drawn with viz.plot_graph: an induced 12-cycle, an induced path on 15 vertices, an induced tree on 16 vertices and a 5-clique, each drawn in its own shape with the rest of the graph around it

Install

subgraphsearch is on PyPI and requires Python 3.10 or later and NumPy 1.24 or later. With uv:

uv add subgraphsearch                # add the package to your project
uv add "subgraphsearch[all]"         # also plotting and conversions to networkx, igraph and SciPy
uv tool install subgraphsearch       # just the `subgraphsearch` command, on your PATH
uvx subgraphsearch info g.g6         # or run the command without installing it

With pip:

pip install subgraphsearch           # the package and the `subgraphsearch` command
pip install "subgraphsearch[all]"    # also plotting and conversions to networkx, igraph and SciPy
pipx install subgraphsearch          # just the command, in its own environment
pipx run subgraphsearch info g.g6    # or run the command without installing it

Prebuilt wheels cover Linux (including Alpine), macOS and Windows (including ARM), so installing needs no compiler.

To copy the quickstart notebook into the current directory and open it in JupyterLab:

uv run --with "subgraphsearch[all]" --with jupyterlab python -m subgraphsearch quickstart   # with uv
pip install "subgraphsearch[all]" jupyterlab && python -m subgraphsearch quickstart       # with pip

Documentation

Document What it covers
Quickstart notebook A hands-on tour of every kind of search and its applications
BENCHMARKS.md How subgraphsearch compares with other methods on standard benchmarks
ALGORITHM.md How the search works: moves, perturbations, variants, data structures
TUNING.md Which search to use for a goal, and how to set its parameters
GRAPHS.md Random graphs, operations, graphs from vectors and designs, file formats
PORTING.md The original C programs, and how to reproduce their runs exactly
DEVELOPMENT.md Building, testing and releasing

Python

import subgraphsearch as ss
from subgraphsearch import viz

g = ss.generate("exponential", 100, 0.6, seed=1)   # a random graph: 100 vertices, density 0.6

r = ss.search(g, size=11, edges=55)    # 11-cliques
r = ss.search(g, size=30, edges=340)   # 30 vertices spanning exactly 340 edges
r = ss.search(g, size=10, degree=4)    # 4-regular induced subgraphs
big = ss.largest(g, "clique")          # the largest clique the search can find
dense = ss.densest(g, 30)              # the 30 vertices spanning the most edges

print(r.summary())
r.solutions()                                  # the distinct vertex sets found
viz.plot_graph(g, highlight=r.best.vertices)   # draw one
viz.plot_search_summary(r)                     # how the search went
viz.save_html("result.html", r)                # an interactive viewer; viz.show(r) in Jupyter

In Jupyter, graphs and results display as summaries with small charts.

  • Searches: a number of edges (edges=), a regular subgraph (degree=), an induced path (path=True, between two given vertices with endpoints=), a total weight in a weighted graph; any of them connected (connected=True) or through given vertices (fixed=), with near misses alongside exact solutions. ss.largest finds the largest induced path, cycle or tree, clique or independent set the search can reach.
  • Graphs: from edges, files, other libraries (networkx, igraph, SciPy, NumPy), random models, hypercubes and grids, incidence structures such as block designs, and sets of vectors or binary words joined by their inner products or Hamming distances (ss.Graph.from_vectors, ss.Graph.from_words), and weighted graphs from real-valued scores (ss.WeightedGraph.from_scores); complements, induced subgraphs, Seidel switching, and products of graphs (Cartesian, tensor, strong, lexicographic, replacement and zig-zag).
  • Seeing what happened: drawings of graphs and the subgraphs found, diagnostics of a search, spectra, and parameter sweeps for tuning.

The quickstart notebook goes through all of these.

How it compares

Left: CP-SAT's time to find k vertices spanning exactly m edges grows to seconds and then past its 10-second limit as random graphs grow from 20 to 59 vertices. Middle: subgraphsearch finds the same targets in about a millisecond or less. Right: on eight maximum diversity benchmark instances, subgraphsearch reaches every best known value, while CP-SAT after 10 seconds falls up to 8% short

  • Exact edge counts: milliseconds, where general solvers (CP-SAT, and the MIP solvers SCIP, HiGHS and CBC) need seconds at a few dozen vertices and mostly find nothing within 10 seconds past 40.
  • Maximum diversity: the best published values on the MDPLIB benchmark in about a second, where the best general solver, CP-SAT, falls up to 9% short and the MIP solvers up to 38%.
  • Snake-in-the-box: the known records up to the 8-cube, and within 3 vertices of the 9-cube's.
  • Maximum cliques: far faster than a general exact search; a dedicated clique solver is faster still.

BENCHMARKS.md has the tables, settings and sources.

Applications

Many combinatorial objects are induced subgraphs of the right graph, so one search finds them all.

  • Choosing diverse items. Picking k of n items so that the total distance between the chosen ones is as large as possible, the maximum diversity problem, is a weighted search: the items are vertices and the distances edge weights. See BENCHMARKS.md for how it fares on the standard benchmark.
  • Error-correcting codes. A binary code of minimum distance d is a clique in the graph of words joined when they differ in at least d places. examples/codes.py finds codes of the largest possible size for lengths 9 to 12, among them the 72-word code of length 11 and distance 4 in about 3 seconds.
  • Strongly regular graphs. Switching a strongly regular graph with respect to a regular subgraph the search finds can give a new one with the same parameters: the Shrikhande graph from the 4×4 rook's graph, and the three Chang graphs from the triangular graph T(8).
  • Spectral bounds. Eigenvalues bound how large an independent set (Hoffman) or a clique (Delsarte) can be, and more generally how many edges any k vertices can span: the expander mixing lemma, and Cheeger's inequality on expansion. The search finds sets that meet these bounds in the rook's graph, the triangular graphs and the hypercubes, so the bounds are sharp there; finds the sparse cuts a small spectral gap promises in a poor expander; and in good expanders, random regular and Paley graphs, shows how close to random every set must be.
  • Hadamard matrices. The rows of a Hadamard matrix are pairwise orthogonal ±1 vectors, so it is a clique in the graph of such vectors joined when orthogonal. examples/hadamard.py finds matrices of orders 8 to 20 this way, the order-20 graph having 31,752 vertices and 169 million edges.
  • Snakes and coils in hypercubes. The longest induced paths and cycles in the n-cube are the snake-in-the-box and coil-in-the-box problems; the path search reaches the known records up to the 8-cube (see BENCHMARKS.md and examples/snake_9cube.py).
  • Equiangular lines. Lines whose vectors have inner products ±c form a clique; the search finds the 16 equiangular lines in 6 dimensions, the most there can be.

The quickstart notebook works through each of these.

How the search works

subgraphsearch is a randomized tabu search with perturbations. Each move swaps one subgraph vertex for one outside vertex, chosen among the swaps that bring the edge count (or total weight) closest to the target; recently swapped vertices are tabu, so the search does not cycle; and every few hundred moves a perturbation, random moves or a region kick that rebuilds the part of the subgraph nearest a random vertex, moves it out of local minima. Independent experiments run in parallel, and results depend only on the seed. There is no fixed limit on the size of a graph; memory is the limit, mostly one bit per pair of vertices, about 1.25 GB at 100,000 vertices (details). ALGORITHM.md describes the method in full, and TUNING.md how to choose a search and its settings.

Command line

The subgraphsearch command comes with the Python package (see Install); with a Rust toolchain, cargo install subgraphsearch builds the same command from crates.io.

# make a graph
subgraphsearch generate exponential -n 100 -d 0.6 -s 1 -o g.g6    # random: 100 vertices, density 0.6
subgraphsearch generate hypercube --dimension 7 -o q7.g6           # or a standard one: the 7-cube

# search it
subgraphsearch search g.g6 -k 11 -m 55                            # 11-cliques
subgraphsearch search g.g6 -k 30 -m 340 --max-conflict 2          # 30 vertices, 340 edges; near misses too
subgraphsearch search g.g6 -k 30 --densest                        # the 30 vertices spanning the most edges
subgraphsearch search g.g6 -k 10 --degree 4                       # 4-regular subgraphs
subgraphsearch search q7.g6 -k 36 --degree 2 --connected          # induced 36-cycles
subgraphsearch search q7.g6 -k 40 --path --endpoints 0,127        # induced 40-vertex paths from 0 to 127
subgraphsearch largest q7.g6 --shape path                         # the longest induced path: 51, the record

# look at the results
subgraphsearch search g.g6 -k 11 -m 55 --json result.json         # save them
python -m subgraphsearch explore g.g6 --result result.json        # explore them in an interactive page
subgraphsearch convert g.g6 g.dot --highlight 3,17,42             # draw a subgraph with Graphviz

Other subcommands print statistics (info), apply operations such as complements, induced subgraphs, switching and products (op), and build graphs from block designs (incidence); search --weighted searches for a total weight, and search --all every graph in a file. subgraphsearch --help lists everything.

subgraphsearch search exits with status 2 when nothing is found.

Option Meaning Default
-k, --vertices subgraph vertices required
-m, --edges subgraph edges (total weight, with --weighted) required, unless --densest, --sparsest, --degree or --path
--densest, --sparsest instead, the subgraph with the most (fewest) edges, or total weight
-d, --degree instead, a subgraph regular of this degree
--path instead, an induced path
--endpoints with --path, the two vertices the path runs between, e.g. 0,7 none
--connected require a connected subgraph off
--fixed vertices the subgraph must contain none
-n, --experiments independent restarts 40
--moves maximum moves per experiment 250
--div-freq, --div-dur make div-dur random moves at the start of every div-freq moves 250, 4
--kick-size, --kick-ban region kicks in place of the random moves of every cycle after the first: vertices rebuilt per kick, and moves they stay out (0 turns kicks off) 4, 20 (no kicks with --degree, --path, --rng legacy)
-s, --seed random seed 1
--weighted read edge weights; -m is then a total weight off

Rust

The search, generators and formats are also a Rust library, subgraphsearch-core, which needs Rust 1.87 or later. Add it with cargo add subgraphsearch-core; its API is documented on docs.rs.

use subgraphsearch_core::{Graph, SearchParams, search};

// find induced 4-vertex paths (3 edges) in a 12-cycle
let g = Graph::from_edges(12, (0..12).map(|i| (i, (i + 1) % 12))).unwrap();
let result = search(&g, &SearchParams::new(4, 3)).unwrap();
let found = result.experiments.iter().find(|e| e.success).unwrap();
assert_eq!(g.induced_edge_count(&found.vertices), 3);

License

MIT

Metadata

Release files for subgraphsearch 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for subgraphsearch 3.0.0
File Size Uploaded Provenance Actions
subgraphsearch-3.0.0.tar.gz 161.8 kB With provenance Details for subgraphsearch-3.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for subgraphsearch 3.0.0
File Actions
subgraphsearch-3.0.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for subgraphsearch-3.0.0-cp310-abi3-win_arm64.whl
subgraphsearch-3.0.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for subgraphsearch-3.0.0-cp310-abi3-win_amd64.whl
subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_x86_64.whl
subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_aarch64.whl
subgraphsearch-3.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for subgraphsearch-3.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
subgraphsearch-3.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for subgraphsearch-3.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
subgraphsearch-3.0.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for subgraphsearch-3.0.0-cp310-abi3-macosx_11_0_arm64.whl
subgraphsearch-3.0.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for subgraphsearch-3.0.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 9.2 MB

Release files / subgraphsearch-3.0.0.tar.gz

Download URL subgraphsearch-3.0.0.tar.gz
Size 161.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5d7dbec8a1ce808fbdeab0e55b41383e94e07405ffb81d3b84a0039eaf776b6
BLAKE2b-256 checksum
How to use checksums
bc673f2e34aaaf673861773469a4b1d38cf7c90770df596df6f941a88c4fdd9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-win_arm64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-win_arm64.whl
Size 966.5 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
d7703dcf2319a0eae73686a389cb026e85785dc92746bd7fb2a99406f05c39e0
BLAKE2b-256 checksum
How to use checksums
3c830cebc220048320705bdc53b65158479b8c96d1f1165e92f9742405ea0c3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-win_amd64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9c1b4a5c428e11818ab80f77d942a6e5c498f37e32fda0c1acf0f0ae35e098c1
BLAKE2b-256 checksum
How to use checksums
bc94b019557c89380c6046f25b5c72b69f2f81f081aba1a1f7d9ada369ac4967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
036038aa594dc89aaed19e17a0243b07edcfeb9b25716e43268d59ae9d829644
BLAKE2b-256 checksum
How to use checksums
09b99faeb7f6a7029d5fcbfc5f68444ad1b86c4714724a987747f448717e1d58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.3 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
e188bc5e694e7a2069821abbe9882d628769102fafb7261eacae10be97bba99f
BLAKE2b-256 checksum
How to use checksums
d10f5f0b0c3143e4d8291e4cc682229e93d12e70f48cae625533f1c0e3e45e21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
801eacc1dbe907b31ff6d66a166da8f8a9a63ca7587f956045f227102846b61a
BLAKE2b-256 checksum
How to use checksums
85c721334687560a4675bcdf6f6ff019c64c20ff8773838fd94d685799eb0e6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
91ab26875fe0eb005c2a14f0544d77bf89c0748552342729803b11fae68d82b6
BLAKE2b-256 checksum
How to use checksums
00a2d1481dc6bb70161d035c5442c07b91e2303bc8c1227aea81554c4ade4ee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
eb3840adf0a9409172270919fe7f9bc8c71ef904741bb384fa72f21781a0e417
BLAKE2b-256 checksum
How to use checksums
f55f9b175e69464c2578f952f719b63c2d4c5798b57bc50b760e67918497d204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / subgraphsearch-3.0.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL subgraphsearch-3.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0edcfa524c3c0b75568c4bf435ebe95957ece007a193a2531f7773efdabb5058
BLAKE2b-256 checksum
How to use checksums
e5a99fe4cdc0d3407bb879481eb9a8bb263f44f7f729d78e1b9a4d6ceb3c8381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for subgraphsearch 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for subgraphsearch-3.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.0 This release

9 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page