Skip to main content

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 n to 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], or e[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] or r[ust]
  • multiprocessing and all resolutions are implemented for both backends

procs

  • parallelizes the recursion across the level-1 SCT nodes
  • if procs=1 and backend='python' then mp.Pool is 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_k or max_k are set, P.vertex_ec, P.curvatures, and P.global_ec will 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

October 2006

Jun 2010, March 2011

January 2020

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

pivoterpy-2.0.1.tar.gz (25.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pivoterpy-2.0.1-cp38-abi3-win_amd64.whl (295.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (466.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (805.3 kB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

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

Hashes for pivoterpy-2.0.1.tar.gz
Algorithm Hash digest
SHA256 f822d7219aacd88528893c1eb67ad98cb31cd35f1a426bab9cfcd77fe22d2568
MD5 e549b3d571245b8382204963d450da6d
BLAKE2b-256 5207b38d3d814c4f8ec8aa7c7e2f16d931cbeff9e13e208564fcf3cb18d3518d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.1.tar.gz:

Publisher: publish.yml on 7e6i/pivoterpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pivoterpy-2.0.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5e3c504ba7664d44e25c775183b28cb843a675e5a0da6698ad1a3d21c2822523
MD5 f6de77a88e64c9be930c024566bacf15
BLAKE2b-256 d25b178f5b354965b8cb936988bef99af16bd80023b1d469039d338bbcf2a06c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.1-cp38-abi3-win_amd64.whl:

Publisher: publish.yml on 7e6i/pivoterpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pivoterpy-2.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8f8d3b9261da759a10c900944ac769c72a802345ff6aec216e97a339d451f22
MD5 55bef1faf1b72436d41a157734966188
BLAKE2b-256 3b89bf33de94d21251fc6b8e3d675ef856774ba96115ba8b3b4cb882d1168867

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

File hashes

Hashes for pivoterpy-2.0.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 16d7b13fc3dda6904d0b1b3aeebd1e1104cbf1338c284fc8e5dc937b4b11f21c
MD5 a88f9740c7c68b4fd7e5ff0c176de585
BLAKE2b-256 ce74859fb493683085840b1b52b26a1082d917d071989292ce3198ca299f9295

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page