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 prescribed total weight in a weighted graph. It finds them 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 for up to 500 items in about a second (How it compares).

The same search finds induced cycles, paths, trees and cliques, regular subgraphs of a given degree, and subgraphs through given vertices. Searches are reproducible from a seed, report near misses alongside exact solutions, and come with diagnostics for tuning; many graph formats are supported.

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 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 MDPLIB values up to 500 items in under a second, where CP-SAT ends up to 9% short and the MIP solvers up to 38%. At 2000 items a heuristic made for the problem is ahead; subgraphsearch comes within 0.02%.
  • Maximum cliques: far faster than an exact search, but a dedicated clique solver is faster still and solves graphs built to trap local search.
  • Snake-in-the-box: the records up to the 8-cube, and within 3 vertices of the 9-cube's.

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 (BENCHMARKS.md).
  • 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 5 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 (BENCHMARKS.md, 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. Vertices just swapped stay tabu for a few moves, longer for larger subgraphs of larger graphs, so the search does not circle back; 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. Experiments run in parallel, and results depend only on the seed. Memory is the only limit on graph size, 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)
--tabu-tenure moves a vertex just swapped stays tabu (0 = automatic) min(k/10, (n-k)/80), at least 1 (1 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 4.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 4.0.0
File Size Uploaded Provenance Actions
subgraphsearch-4.0.0.tar.gz 164.0 kB With provenance Details for subgraphsearch-4.0.0.tar.gz

Built distributions (wheels)

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

Total release size: 9.2 MB

Release files / subgraphsearch-4.0.0.tar.gz

Download URL subgraphsearch-4.0.0.tar.gz
Size 164.0 kB
Tags Source
SHA-256 checksum
How to use checksums
150ce4a4f64802cda5630e0c087ff48f2755d494e2fd6109878f38f8c84a6b17
BLAKE2b-256 checksum
How to use checksums
9e4c012715df18c94f949125096596ada5345c1ea3cfe132396befa53d23d287
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.0.0-cp310-abi3-win_arm64.whl
Size 980.5 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
458379c18c1c17e61b017dabdd203ba7e07411513c8edb09cd3a048e468bfdd2
BLAKE2b-256 checksum
How to use checksums
20201304dcf9585e51a7659ef3f425296caa8b231b770a106ac29a53c916e4c0
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
65c521e7d7e414e2b5b4d4c0981dd1ef95a7ba24b958d1807d398d9c26841f43
BLAKE2b-256 checksum
How to use checksums
eced47d3f92b2f48ab0fbf3fb5ec9be66918450e5f6dc40db86e8da462493ed4
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
8b647c45ed46845bde1ed2330cb9577dcbd5204e383b78e4a4261ee547fa26ff
BLAKE2b-256 checksum
How to use checksums
3811b5bbbe9afa5c2af1d443e51344fc6952ba25915f0f40a9f0f12db37fe336
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
d253045a70c35a33ab88b94023646a65ac65ee6b753281285aaf7d3341de68f7
BLAKE2b-256 checksum
How to use checksums
2affb0f195be081825d1ec294be944470d1ab8f4b85556f518c41dbcdd48be82
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
a066d5195197a237818a2297171814ac102456c8518562a3ca79e63974905c72
BLAKE2b-256 checksum
How to use checksums
046181ae37fa61adaeef8f44d337b1b6ab461d70be43000141f9b36cd79df562
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
7d9dc6735c3b91ea85250c3f6e41173dff786fe70013de07448d262597055310
BLAKE2b-256 checksum
How to use checksums
2784c9572e3eca4d7ea068a57eda33f14b01a5038591847dbb394606f25fba69
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
4b2b9e5f3ea6598bcd8e649ae345b5361b73b20f525ccfee2763bedbc7534adf
BLAKE2b-256 checksum
How to use checksums
c94a5989c82c6a98abbd465471ad5a6f2970f5925301a5d78d728c5f423ca8ff
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 15, 2026.

Transparency log

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

Download URL subgraphsearch-4.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
1059651aa6b04438c7346c9145e69479f6817a83705a8105f0ce01fd4c65b242
BLAKE2b-256 checksum
How to use checksums
796d1b9d072a811e03e01b6633b482c68025217e81287c8993108979c3b4e534
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 15, 2026.

Transparency log

Security for subgraphsearch 4.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-4.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 15, 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

4.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