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

  • as many as you are willing to sacrifice for speed.
  • if procs=0 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

Below is the preferred BibTeX citation for this repository.

@software{anderson_pivoterpy_2026,
  author       = {Spencer Anderson},
  title        = {{pivoterpy}},
  year         = {2026},
  version      = {2.0.0},
  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.0.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.0-cp38-abi3-win_amd64.whl (294.9 kB view details)

Uploaded CPython 3.8+Windows x86-64

pivoterpy-2.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (466.1 kB view details)

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

pivoterpy-2.0.0-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.0.tar.gz.

File metadata

  • Download URL: pivoterpy-2.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d45445829d0dc2b8f3e421aa02f8bc81321342c8372e79f9e8fa3bf0362a720d
MD5 a5ca480d6e62e6580badab5f78f7f2fd
BLAKE2b-256 a72c3d2800043aa5fab5402ac44d6778dbb5215e92ffde870808124b2ec02e33

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.0.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.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pivoterpy-2.0.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 294.9 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.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fc3b4012e2f4efb075a952b0f0b739beb93a5ce35a5000a1d11d69210bd27821
MD5 0223d59e1bd12455bfe72507ecdc8199
BLAKE2b-256 5e959d2198233e36b2026c20b3b2fc18c9b44632166dac271f576b8ccbee0563

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.0-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.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pivoterpy-2.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69ccd8e258412fd74773e9f1b21e2b5a8c7eb8fdfaf1c47a2703ff1ce841fa39
MD5 b6cdc4a28d306696661cfeaeb8293131
BLAKE2b-256 6a6e7be46b583d35c406063ce0366368ccb40da95baf019d8e59573cfdcc0c44

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.0-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.0-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.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 338407f63c6fe7353f1ccdb785d9ecb53d59079942ac598175588bc4425d2ef3
MD5 7d95ddaa85b2f6ac313fc33f9e53e292
BLAKE2b-256 fe8ce87d9bec9a20b2a403d82e2f1b762ed7068f2d11b5371466f5b05e7a0e27

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoterpy-2.0.0-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