Fast gSpan (frequent subgraph mining) powered by gBolt C++ backend
Project description
fast-gspan
A Python wrapper for frequent subgraph mining powered by the gBolt C++ backend.
Provides a simple API to mine frequent subgraph patterns from NetworkX graphs, with significant speedups over pure-Python gSpan implementations.
Installation
Pre-built wheels are available for Linux (x86_64) and macOS (arm64, x86_64):
pip install fast-gspan
Building from source
If a pre-built wheel is not available for your platform, install from source:
pip install git+https://github.com/Masatsugar/fast-gspan.git
python -m fast_gspan build # compile the C++ backend
Source builds require:
- CMake >= 3.10
- C++ compiler with C++11 support (GCC, Clang)
- OpenMP (optional, for parallel mining)
# Ubuntu/Debian
sudo apt-get install cmake g++ make
# macOS
brew install cmake libomp
Quick start
import networkx as nx
from fast_gspan import FastgSpan
# Prepare your graph database
graphs = [...] # list of NetworkX graphs with 'label' attributes on nodes/edges
# Mine frequent subgraphs
fgs = FastgSpan(min_support=10, max_num_vertices=8)
df = fgs.run_from_graphs(graphs)
print(df[["support", "num_vert", "description"]])
From a gSpan-format file
from fast_gspan import FastgSpan
df = FastgSpan(min_support=10, max_num_vertices=8).run_from_file("graphs.txt")
Parallel mining & progress
fgs = FastgSpan(
min_support=10,
max_num_vertices=8,
num_threads=4, # 0 = all cores (default)
show_progress=True, # show real-time pattern count
)
df = fgs.run_from_graphs(graphs)
API
FastgSpan
High-level interface. Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
gbolt_path |
str | None |
None |
Path to gBolt executable. Auto-detected if None. |
min_support |
int |
2 |
Minimum absolute support threshold. |
min_num_vertices |
int |
1 |
Minimum vertices in a pattern. |
max_num_vertices |
int |
0 |
Maximum vertices in a pattern (0 = unlimited). |
num_threads |
int |
0 |
Number of OpenMP threads (0 = all cores). |
timeout |
float | None |
None |
Timeout in seconds for gBolt execution (None = unlimited). |
show_progress |
bool |
False |
Show progress during mining. |
verbose |
bool |
False |
Print debug information. |
Methods:
run_from_graphs(graphs)-- Mine from a list ofnx.Graph. Returnspd.DataFrame.run_from_file(filepath)-- Read a gSpan-format file and mine. Returnspd.DataFrame.pattern_to_graph(pattern)-- Convert a pattern dict (from raw results) tonx.Graph. Static method.
GBoltWrapper
Low-level wrapper around the gBolt binary. Use this if you need direct access to raw pattern dicts.
mine_frequent_subgraphs(graphs)-- Returnslist[dict]with keys:pattern_id,support,vertices,edges,dfs_codes,graph_data.
Output format
The returned DataFrame has the following columns:
| Column | Description |
|---|---|
support |
Number of graphs containing this pattern |
description |
DFS-code representation: (from, to, from_label, edge_label, to_label) per edge |
num_vert |
Number of vertices in the pattern |
pattern_id |
Pattern ID assigned by gBolt |
vertices |
List of (vertex_id, label) tuples |
edges |
List of (from, to, edge_label) tuples |
graph_ids |
List of graph indices where this pattern occurs (if available) |
gSpan-format file
Input files follow the standard gSpan text format:
t # 0
v 0 1
v 1 2
e 0 1 3
t # 1
v 0 1
v 1 1
v 2 2
e 0 1 3
e 1 2 4
t # -1
Changes from upstream gBolt
This package bundles a modified fork of gBolt with the following changes:
New features
-x, --max-verticesoption -- Limits the maximum number of vertices in mined patterns. Allows early pruning during DFS exploration, reducing both runtime and memory usage.- Projection size guard (
MAX_PROJECTION_SIZE) -- Skips projections exceeding 500,000 entries to prevent memory explosion on dense graphs.
Output format change
- The DFS-code output (
-dflag) now emits the full tuple:
The upstream format only emittede <from> <to> <from_label> <edge_label> <to_label>e <from> <to> <edge_label>. The extended format enables exact reconstruction of canonical DFS codes in the Python wrapper.
Build system
- CMake minimum version raised from 2.6 to 3.10.
- Added macOS (Apple Clang) fallback for OpenMP via Homebrew
libomp.
Bug fixes
- Added
constqualifier to threeoperator()methods ininclude/graph.hto fix compiler warnings and ensure correctness with modern C++ standards.
License
The bundled gBolt C++ source is licensed under the BSD 2-Clause License (Copyright (c) 2017, Keren Zhou). See fast_gspan/vendor/gbolt/LICENSE for details.
The Python wrapper code in this repository is also released under the BSD 2-Clause License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_gspan-0.1.3.tar.gz.
File metadata
- Download URL: fast_gspan-0.1.3.tar.gz
- Upload date:
- Size: 39.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0269a2ff9913dacff6f989b2d8c0b54b92b70174bad08a3a08b8e35717a0bed
|
|
| MD5 |
84297f11dfa4f5c727be7cd05b137d32
|
|
| BLAKE2b-256 |
fc75bb9336b4d1f7a98447bdd3f5ffee8093a9bf7e4484d15bec11fa7a4f941e
|
Provenance
The following attestation bundles were made for fast_gspan-0.1.3.tar.gz:
Publisher:
publish.yml on Masatsugar/fast-gspan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_gspan-0.1.3.tar.gz -
Subject digest:
e0269a2ff9913dacff6f989b2d8c0b54b92b70174bad08a3a08b8e35717a0bed - Sigstore transparency entry: 1239097844
- Sigstore integration time:
-
Permalink:
Masatsugar/fast-gspan@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Masatsugar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fast_gspan-0.1.3-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: fast_gspan-0.1.3-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 166.4 kB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
355ff2f7b96b3b92ad5161b6a51429912b81e2dbcc8084edfb0a456c4a45abc3
|
|
| MD5 |
8ada581d84f899dab16f25ba4f227017
|
|
| BLAKE2b-256 |
87518aeaf590015f5d1c227f0f56d8206a58c6e807dbed08880ab9f93fd83d39
|
Provenance
The following attestation bundles were made for fast_gspan-0.1.3-py3-none-manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on Masatsugar/fast-gspan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_gspan-0.1.3-py3-none-manylinux_2_28_x86_64.whl -
Subject digest:
355ff2f7b96b3b92ad5161b6a51429912b81e2dbcc8084edfb0a456c4a45abc3 - Sigstore transparency entry: 1239097845
- Sigstore integration time:
-
Permalink:
Masatsugar/fast-gspan@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Masatsugar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fast_gspan-0.1.3-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_gspan-0.1.3-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 374.1 kB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e67f62e61753343b383911bd4ac952e68b675364145fb7e9d658f0c262465ab1
|
|
| MD5 |
027b5dbbbefb97ecf5bd598efccf9803
|
|
| BLAKE2b-256 |
d90d28a195cedfc3e0fbdf35f240432467749aa0cef8ce9236930b5e3ad254ac
|
Provenance
The following attestation bundles were made for fast_gspan-0.1.3-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on Masatsugar/fast-gspan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_gspan-0.1.3-py3-none-macosx_11_0_arm64.whl -
Subject digest:
e67f62e61753343b383911bd4ac952e68b675364145fb7e9d658f0c262465ab1 - Sigstore transparency entry: 1239097850
- Sigstore integration time:
-
Permalink:
Masatsugar/fast-gspan@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Masatsugar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d3affd5a08214d4e82bb114abaa80c668c90995 -
Trigger Event:
release
-
Statement type: