Parallelized Python (and Rust) implementation of the Pivoter clique counting algorithm.
Project description
pivoterpy
A one-stop-shop for all your clique counting needs. Python, Rust (and hopefully CUDA soon) implementations of the Pivoter clique counting algorithm.
"I fear not the man who has implemented 1000 clique algorithms, I fear the man who has implemented 1 clique algorithm a thousand times" - Sun Tzu, The Art of War
Let $G=(V,E)$ be a graph with $|V|=n$ nodes and $|E|=m$ edges. Let $C_k$ be the number of global cliques of size $k$. Let $C_k(v)$ and $C_k(e)$ be the number of vertex and edge cliques of size $k$ for vertex $v$ and edge $e$, respectively. Let $\mathcal{K}$ be the size of the largest clique in the graph.
quick start
import pivoterpy as pvt
G = pvt.from_adj_matrix(array)
P = pvt.pivoter(G)
P.global_counts
Documentation
initialization
Use the following constructors to load a graph.
G = pvt.from_adj_matrix(array)
-
Requires a $n \times n$ binary matrix. Only the upper triangle is scanned.
-
Edges are created for entries > 0 (or True).
G = pvt.from_edge_list(array, n=None)
-
Requires a $m \times 2$ edge list.
-
All elements must be integer edge tuples $(u,v)$ such that $0 \le u,v < n$.
-
Number of nodes $n$ is inferred from the largest node provided. Used the argument
nto set a larger value.
G = pvt.from_networkx(graph)
- Requires a NetworkX graph object.
counting
To get started, create simply call the pivoter method with a graph. Default arguments are shown for reference.
P = pvt.pivoter(
G,
resolution='global',
backend='python',
procs=1,
min_k=None,
max_k=None
)
arguments
resolution
- one of
g[lobal],v[ertex], ore[dge]. - because of how math works, global counts can be derived from vertex counts
- the same applies to vertex from edge counts (and thus global from edge counts)
- increasing the reslution does change the complexity class so be careful
backend
- one of
p[ython]orr[ust] - multiprocessing and all resolutions are implemented for both backends
procs
- parallelizes the recursion across the level-1 SCT nodes
- if
procs=1andbackend='python'thenmp.Poolis skipped entirely
min_k
- only cliques of size $k \geq min_k$ will be counted
- all counts with $k < min_k$ will be set to 0
- the length of all counts list will be at least $min_k+1$
max_k
- only cliques of size $k \leq max_k$ will be counted
Note: If
min_kormax_kare set,P.vertex_ec,P.curvatures, andP.global_ecwill be still return values, although they will likely be incorrect.
results
With resolution='edge' the below are available (including vertex and global results).
P.edge_counts # dict of lists, keys are (u,v) with u < v
With resolution='vertex' the below are available (including global results).
P.vertex_counts # jagged list of lists of ints
P.vertex_ec # list of ints, alternating sum of counts
P.curvatures # list of floats
With resolution='global' the below are available.
P.global_counts # list of ints
P.global_ec # int, alternating sum of counts
Extras
the lore...
April 1971
- Bron-Kerbosch algorithm created by... C. Bron and J. Kerbosch.
- Algorithm 457, Finding All Cliques of an Undirected Graph [H]
October 2006
- E. Tomitaa, A. Tanaka, H. Takahashia say this is a difficult problem.
- The worst-case time complexity for generating all maximal cliques and computational experiments
Jun 2010, March 2011
- Double header by D. Eppstein, M. Loffler, D. Strash. (code)
- Listing All Maximal Cliques in Sparse Graphs in Near-optimal Time
- Listing All Maximal Cliques in Large Sparse Real-World Graph
- D. Strash creates
quick-clicksfor maximal cliques. (code)
January 2020
- S. Jain, C. Seshadhri drop an absolute banger:
Pivoter. - The Power of Pivoting for Exact Clique Counting
- Code available on GitHub and BitBucket
implementations
-
Pivoter - Julia implementation by charunupara. (code)
-
PyPivoter - Cython implementation by rckormos. (code)
-
pivoterpy - a new and improved Python/Rust implementation!
citation
You should definitely cite the original Pivoter paper (listed above).
If you're feeling generous, you can also cite this package (BibTeX info below).
@software{anderson_pivoterpy_2026,
author = {Spencer Anderson},
title = {{pivoterpy}},
year = {2026},
version = {2.0.1},
url = {https://github.com/7e6i/pivoterpy}
}
experimental
There is an experimental Rust backend available for resolution='global'. To access it, set G.experimental=True before calling pivoter.
This code parallelizes work for each level 2 node in the SCT (rather than only level 1), and compresses the neighborhoods and degeneracy out neighborhoods for each node. This helps to reduce memory overhead taken up by unused vertices for each recursion path, and helps to balance the load by allowing for improved Rayon work-stealing.
Project details
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 pivoterpy-2.0.1.tar.gz.
File metadata
- Download URL: pivoterpy-2.0.1.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f822d7219aacd88528893c1eb67ad98cb31cd35f1a426bab9cfcd77fe22d2568
|
|
| MD5 |
e549b3d571245b8382204963d450da6d
|
|
| BLAKE2b-256 |
5207b38d3d814c4f8ec8aa7c7e2f16d931cbeff9e13e208564fcf3cb18d3518d
|
Provenance
The following attestation bundles were made for pivoterpy-2.0.1.tar.gz:
Publisher:
publish.yml on 7e6i/pivoterpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pivoterpy-2.0.1.tar.gz -
Subject digest:
f822d7219aacd88528893c1eb67ad98cb31cd35f1a426bab9cfcd77fe22d2568 - Sigstore transparency entry: 1349918216
- Sigstore integration time:
-
Permalink:
7e6i/pivoterpy@8d989eccf675260b5e760d38e7eb57791b53c035 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/7e6i
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d989eccf675260b5e760d38e7eb57791b53c035 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pivoterpy-2.0.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: pivoterpy-2.0.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 295.0 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e3c504ba7664d44e25c775183b28cb843a675e5a0da6698ad1a3d21c2822523
|
|
| MD5 |
f6de77a88e64c9be930c024566bacf15
|
|
| BLAKE2b-256 |
d25b178f5b354965b8cb936988bef99af16bd80023b1d469039d338bbcf2a06c
|
Provenance
The following attestation bundles were made for pivoterpy-2.0.1-cp38-abi3-win_amd64.whl:
Publisher:
publish.yml on 7e6i/pivoterpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pivoterpy-2.0.1-cp38-abi3-win_amd64.whl -
Subject digest:
5e3c504ba7664d44e25c775183b28cb843a675e5a0da6698ad1a3d21c2822523 - Sigstore transparency entry: 1349918467
- Sigstore integration time:
-
Permalink:
7e6i/pivoterpy@8d989eccf675260b5e760d38e7eb57791b53c035 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/7e6i
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d989eccf675260b5e760d38e7eb57791b53c035 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 466.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f8d3b9261da759a10c900944ac769c72a802345ff6aec216e97a339d451f22
|
|
| MD5 |
55bef1faf1b72436d41a157734966188
|
|
| BLAKE2b-256 |
3b89bf33de94d21251fc6b8e3d675ef856774ba96115ba8b3b4cb882d1168867
|
Provenance
The following attestation bundles were made for pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on 7e6i/pivoterpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
f8f8d3b9261da759a10c900944ac769c72a802345ff6aec216e97a339d451f22 - Sigstore transparency entry: 1349918358
- Sigstore integration time:
-
Permalink:
7e6i/pivoterpy@8d989eccf675260b5e760d38e7eb57791b53c035 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/7e6i
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d989eccf675260b5e760d38e7eb57791b53c035 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 805.3 kB
- Tags: CPython 3.8+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16d7b13fc3dda6904d0b1b3aeebd1e1104cbf1338c284fc8e5dc937b4b11f21c
|
|
| MD5 |
a88f9740c7c68b4fd7e5ff0c176de585
|
|
| BLAKE2b-256 |
ce74859fb493683085840b1b52b26a1082d917d071989292ce3198ca299f9295
|
Provenance
The following attestation bundles were made for pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
publish.yml on 7e6i/pivoterpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
16d7b13fc3dda6904d0b1b3aeebd1e1104cbf1338c284fc8e5dc937b4b11f21c - Sigstore transparency entry: 1349918311
- Sigstore integration time:
-
Permalink:
7e6i/pivoterpy@8d989eccf675260b5e760d38e7eb57791b53c035 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/7e6i
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d989eccf675260b5e760d38e7eb57791b53c035 -
Trigger Event:
release
-
Statement type: