GraphCalc
Overview
GraphCalc is a Python library for computing a broad range of graph-theoretic invariants, purpose-built to support research in combinatorics, network science, and automated reasoning. It offers exact implementations of over 100 functions, spanning classical invariants (e.g., independence number, chromatic number, spectral radius) and a wide array of lesser-known parameters central to contemporary graph theory.
Originally developed as the invariant engine for the automated conjecturing system TxGraffiti, GraphCalc has since matured into a general-purpose research tool that facilitates the large-scale construction of structured, high-resolution invariant datasets. These datasets, often organized into tabular “knowledge tables,” form the basis for symbolic pattern mining, hypothesis generation, and downstream machine reasoning. For example,
>>> import graphcalc.graphs as gc
>>> from graphcalc.graphs.polytopes.generators import cube_graph, octahedron_graph
>>> graphs = [cube_graph(), octahedron_graph()]
>>> functions = ["order", "size", "spectral_radius", "independence_number"]
>>> gc.compute_knowledge_table(functions, graphs)
order size spectral_radius independence_number
0 8 12 3.0 4
1 6 12 4.0 2
Features
- Maximum Clique: Finds the maximum clique in a given graph.
- Chromatic Number: Computes the minimum number of colors required for graph coloring.
- Vertex and Edge Cover: Determines vertex and edge covers.
- Matching and Independence: Calculates maximum matching and independent sets.
- Domination Number and its Variants: Calculates the domination number, total domination number, and many other domination variants.
- Degree Sequence Invariants: Calculates the residue, annihilaiton number, the slater number and more!
- Zero Forcing: Calculates the zero forcing number, the total zero forcing number, the positive semidefinite zero forcing number, and the power domination number.
Installation
To install graphcalc, make sure you have Python 3.7 or higher, then install it:
pip install graphcalc
Linear and Integer Programming Solvers
Many of the NP-hard graph invariant computations of GraphCalc depend on third-party solvers.At least one of the following is required if you intend to use solver-based functions (e.g., gc.maximum_independent_set(G)):
- CBC (recommended):
brew install cbc # macOS
sudo apt install coinor-cbc # Debian/Ubuntu
GraphCalc will attempt to automatically detect the solver if it is installed. You can also manually specify the solver in API calls.
Example Graph Usage
from graphcalc import (
independence_number,
domination_number,
zero_forcing_number,
)
from graphcalc.graphs.generators import petersen_graph
# Calculate and print the independence number of the Petersen graph.
G = petersen_graph()
print(f"Petersen graph independence number = {independence_number(G)}")
# Calculate and print the domination number of the Petersen graph.
print(f"Petersen graph domination number = {domination_number(G)}")
# Calculate and print the zero forcing number of the Petersen graph.
print(f"Petersen graph zero forcing number = {zero_forcing_number(G)}")
Example Polytope Usage
import graphcalc.graphs as gc
from graphcalc.graphs.polytopes.generators import (
cube_graph,
octahedron_graph,
dodecahedron_graph,
tetrahedron_graph,
icosahedron_graph,
convex_polytopes_text_example,
)
# Generate polytope graphs (cubes, octahedra, etc.)
G1 = cube_graph()
G2 = octahedron_graph()
G3 = dodecahedron_graph()
G4 = tetrahedron_graph()
G5 = icosahedron_graph()
G6 = convex_polytopes_text_example(1)
G7 = convex_polytopes_text_example(2)
# Function names to compute
function_names = [
"order", # number of vertices
"size", # number of edges
"p_vector",
"independence_number",
"vertex_cover_number",
"maximum_degree",
"average_degree",
"minimum_degree",
"spectral_radius",
"diameter",
"radius",
"girth",
"algebraic_connectivity",
"largest_laplacian_eigenvalue",
"second_largest_adjacency_eigenvalue",
"smallest_adjacency_eigenvalue",
"fullerene",
]
# Compute properties for multiple polytopes
graphs = [G1, G2, G3, G4, G5, G6, G7]
df = gc.compute_knowledge_table(function_names, graphs)
Creating Simple Graphs, Polytope Graphs, and Simple Polytope Graphs
import graphcalc.graphs as gc
# Draw a simple graph
G = gc.SimpleGraph(name="Example Graph")
G.add_edges_from([(0, 1), (1, 2), (2, 3)])
G.draw()
Author
Randy Davila, PhD Email: rrd6@rice.edu
Release files for graphcalc 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| graphcalc-2.0.0.tar.gz | 193.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| graphcalc-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 422.0 kB
Release files / graphcalc-2.0.0.tar.gz
| Download URL | graphcalc-2.0.0.tar.gz |
|---|---|
| Size | 193.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a98a35b8a1a4cfa8192c034b9ab8b6befef2177e44c4dd1e8fbbfbb635a7e9d
|
|
BLAKE2b-256 checksum How to use checksums |
d9a48c1e30169e5a65065b3af26c0d816a6b53e26a78913dbe933274a963dd2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 10, 2026.
Transparency logRelease files / graphcalc-2.0.0-py3-none-any.whl
| Download URL | graphcalc-2.0.0-py3-none-any.whl |
|---|---|
| Size | 228.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23f1629983ea36ab4cb1757a15d2fc0f5ae27334a55f1957d93c4b5b48ee93a0
|
|
BLAKE2b-256 checksum How to use checksums |
47e13bfeb8b5d3509af3c149095cfb5a2721c3a5e59ff53e43b7ddea689c2d33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 10, 2026.
Transparency log