Skip to main content

Red Black Graph - AVOS algebra for graph computation

Project description

Ask DeepWiki CI Coverage PyPi PyPi Python 3.12 Python 3.11 Python 3.10

Red-Black Graph - A DAG of Multiple, Interleaved Binary Trees

Introduction

Red-Black Graphs are a specific type of graph, a directed acyclic graph of interleaved binary trees. This data structure resulted from exploration of efficient representations for family history. This package presents and implements the underlying linear algebra as well as discusses some interesting applications.

This python module extends both scipy and numpy and also conforms to dockerutils conventions for building and running docker images used in module development. There is a script in the bin directory that can be used to setup the project for development or to prep for reading the notebook. (bin/setup-project.sh). You will want to create an activate a virtual environment prior to running the script.

Reading the Notebook

A research paper describing the linear algebra underlying Red-Black graphs as well as examples of application can be found in the Jupyter notebook, "Red Black Graph - A DAG of Multiple, Interleaved Binary Trees.ipynb". To access the notebook after you've setup the project for development, simply:

  • run-image notebook
  • open http://localhost:8888/lab

If you'd prefer to read hard copy, simply run:

`bin/generate-pdf.sh notebooks/Red Black Graph - A DAG of Multiple, Interleaved Binary Trees.ipynb` 

A pdf file will be generated into the build/latex-{datestamped} directory.

To Try Things Out...

Run the following:

# use crawl-fs to extract a sample data set from FamilySearch
pip install fs-crawler
crawl-fs -i <FamilySearch Ids to seed crawl> -o <output-directory> -b <name portion of output file>

# this will generate a <name>.vertices.csv and <name>.edges.csv file which can be ingested into a RedBlackGraph
pip install RedBlackGraph
# use rbgcf to generate both a simple form and cannonical form of a Red Black Graph (xlsx files)
rbgcf -f <directory and base name of vertices and edges file> -o <output-directory>

# Use excel to view output
 

Building from Source

RedBlackGraph uses the Meson build system (as of version 0.5.0, migrated from numpy.distutils).

Requirements

  • Python 3.10, 3.11, or 3.12
  • Meson >= 1.2.0
  • Ninja build tool
  • Cython >= 3.0
  • NumPy 1.26+ (including NumPy 2.x)

Build and Install

# Install build dependencies
pip install meson-python meson ninja cython numpy

# Build and install in development mode
pip install -e . --no-build-isolation

# Or build wheel
pip install build
python -m build

uv users

Meson-python editable installs require --no-build-isolation (the editable loader needs a persistent build directory). A setup script handles this:

./bin/setup-uv.sh           # CPU only
./bin/setup-uv.sh --gpu     # Include CuPy for GPU support
source .venv/bin/activate
pytest tests/

Or manually:

uv venv
uv pip install meson-python meson ninja cython tempita numpy
uv pip install -e ".[test,io]" --no-build-isolation

uv setup script

If you use uv, a convenience script is provided to create a fresh .venv, install build/test dependencies, perform an editable install using pip with --no-build-isolation, and install the test extra:

./bin/setup-uv.sh
source .venv/bin/activate
uv run -m pytest

The script expects:

  • uv on your PATH
  • the ninja build tool installed (e.g. sudo apt install ninja-build on Debian/Ubuntu)
  • the fs-crawler submodule present at ./fs-crawler

The Meson build system compiles all C/C++ extensions and Cython modules automatically.

Building and Publishing Wheels

RedBlackGraph uses cibuildwheel to build wheels for multiple platforms and Python versions.

Quick Start

# Build wheels for current platform
./bin/build-wheels-cibuildwheel.sh

# Or use cibuildwheel directly
pip install cibuildwheel
cibuildwheel --platform auto --output-dir wheelhouse

Automated Release

Wheels are automatically built and published to PyPI when a version tag is pushed:

git tag -a v0.5.1 -m "Release version 0.5.1"
git push origin v0.5.1

For detailed instructions, see:

A Note on Implementations

  • redblackgraph.reference - a pure python implementation. This simple implementation is intended primarily for illustrative purposes.
  • redblackgraph.matrix and redblackgraph.array - a Numpy C-API extension for efficient computation with the matrix multiplication operator, @, overloaded to support avos sum and product.
  • redblackgraph.sparse_matrix - an optimized implementation built on scipy's sparse matrix implementation.
  • redblackgraph.gpu - GPU-accelerated sparse operations using CuPy and inline CUDA kernels. Provides SpGEMM (sparse matrix multiply) and transitive closure on GPU using the AVOS semiring.

GPU Acceleration

The GPU module (redblackgraph.gpu) provides two transitive closure algorithms:

  1. Repeated squaring (transitive_closure_gpu) — works for any graph. Computes TC(A) = A + A² + A⁴ + ... via CUDA SpGEMM with all data GPU-resident between iterations.
  2. Level-parallel DAG propagation (transitive_closure_dag_gpu) — specialized for DAGs (triangular matrices). Processes vertices by topological level with full GPU parallelism within each level.

Performance

Benchmarked on synthesized family DAGs (lower-triangular adjacency matrices). CPU uses the Cython O(V+E+nnz) topological propagation algorithm.

Vertices NNZ CPU-DAG (s) GPU-Sqr (s) GPU-DAG (s) Best GPU/CPU
442 1,226 0.0020 0.0039 0.0032 1.6x CPU
1,326 3,728 0.0080 0.0055 0.0038 2.1x GPU
2,144 5,932 0.0129 0.0059 0.0043 3.0x GPU
4,701 13,103 0.0292 0.0073 0.0057 5.1x GPU
11,012 30,536 0.0700 0.0125 0.0087 8.1x GPU
21,162 58,486 0.1380 0.0268 0.0138 10.0x GPU

GPU crossover is ~1,000 vertices. The DAG kernel nearly doubles the speedup over repeated squaring at scale.

Requirements

pip install cupy-cuda12x  # or cupy-cuda11x for older CUDA

GPU features are optional — all functionality gracefully falls back to CPU when CuPy is unavailable.

Quick Start

from redblackgraph.gpu import CSRMatrixGPU, transitive_closure_dag_gpu

# Transfer sparse matrix to GPU
A_gpu = CSRMatrixGPU.from_cpu(my_sparse_matrix)

# Compute transitive closure
closure, diameter = transitive_closure_dag_gpu(A_gpu)

# Transfer result back to CPU
result = closure.to_cpu()

Run python bench_closure.py to reproduce the benchmark on your hardware.

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

redblackgraph-0.7.0.tar.gz (893.1 kB view details)

Uploaded Source

Built Distributions

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

redblackgraph-0.7.0-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

redblackgraph-0.7.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

redblackgraph-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (852.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

redblackgraph-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl (890.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

redblackgraph-0.7.0-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

redblackgraph-0.7.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

redblackgraph-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (853.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

redblackgraph-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl (900.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

redblackgraph-0.7.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

redblackgraph-0.7.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

redblackgraph-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (860.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

redblackgraph-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl (907.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file redblackgraph-0.7.0.tar.gz.

File metadata

  • Download URL: redblackgraph-0.7.0.tar.gz
  • Upload date:
  • Size: 893.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for redblackgraph-0.7.0.tar.gz
Algorithm Hash digest
SHA256 2b1cc3d12bd44419258708306cadb320e292a5d195f41d1c474fd776bdef5fc0
MD5 5243b0f3e5cf097f2dd9821fcbf83c2d
BLAKE2b-256 d57f252e256d69fed4b260fadfe011b6d28aef305c622c53e4f33a22d052208d

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0.tar.gz:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ca7876c1eac77d412a95cfef02c046ca25450586078bead6a0ab7590c1c89a5f
MD5 877fbf496e4d3426c165368d6da3d4c6
BLAKE2b-256 db0fec129a15de7adc98e3b802654c49ffb1a812faeca56c4fa794062b31cfc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 214ea2bb6b910e1728805a36dd26a68feabd78439e1021bfc6094d85f8ece9b2
MD5 c30747c230bb9eb4be8fbeac7cdb913d
BLAKE2b-256 648ec994c7221ab8771ebb3968e7675e1a49c57505ef277858f30662fa280226

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75694bff7a9b6b9d50cd73b4a07c9e117c433d3d91fb399195bd1fb5ad5f9659
MD5 5697b50d83732c6c30def65727cc02c3
BLAKE2b-256 44d15296cd853d44680e87c5bea51de4ffbcf2a8812476192079c5772089de79

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6cd4eeb41d220482aaad2580a0d41043b071c45ccdb38e18fcb47c22eaf9e632
MD5 35a28301af69420678f7ded9b51c941f
BLAKE2b-256 5659fb9de87962e020ce9a8979bec8a156acdba3412f4b243774cf771a1fd877

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 584da7e3979b24a56e4cd2c8d971d1a490f65cfb545cce68f44e1c0e2ef7d23a
MD5 a17bf076b8394f1a2c038328b75ec016
BLAKE2b-256 99d5142f5efe5bbc8875c4eb257a67be3d8edf92fc808e0ebb58a07f6e4d5595

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c9d14bb163d52b33b5f68c05ba70bb5e3cf22e4e18fab6471216607818d963a1
MD5 d6aa5ba816e202b5c87bb6a4815efc70
BLAKE2b-256 81e21fea7de61eef2dab72c134524a329f48b1719c25ddf248c55f9f14d578aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d52cd62525c63b7c0cf40efde7434009ff2d7deb6c49ac3ecbdff5dbcbd8915c
MD5 1beaea2040d169e0ba9b44ccff431d04
BLAKE2b-256 c6d07243ecaadaf0949de3b6eba7239b9ee11c227f90adc1f1f7c5b810778533

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 603fc6a1b560c43b6ee64d03548e843b5c99da0b326d696f19c27cff16cc559c
MD5 c6e4fc04d0153972f6afc3e768561db4
BLAKE2b-256 3a582587e8790a8cda792756b1b5965fc9b82757fbfbc828227e2220c94f9b44

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5f0b5fed54341beb8a66f751178593102da7861f4c06d10c87176829777ecab2
MD5 47b577ff93775829b43b8845a0132c95
BLAKE2b-256 501f5af462419237f1c9a47cdc6493fe917ee14d711d2eb7c8ddc7872aa15f5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 559afbd194f9f9a06aafcb20cf327ac17da6b0b8c3443989ccca528dffc355cd
MD5 808772274e99fb4d487fa5c8dccf3b86
BLAKE2b-256 6c4358d53a1adf806f12e6c395f5a5bb4cea8fa853eb1c6a3adcb11ac1a6cc0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e79f053003731015a4a639281c79421b77763440d62b5a612630e3db2c16b2e
MD5 05ca1750c4b8e914cefc5258007b09f6
BLAKE2b-256 c5c988ed9d9d351b00c54404cd5bef8f9460f5f526d32810321c8b14ba331e65

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on rappdw/redblackgraph

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

File details

Details for the file redblackgraph-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for redblackgraph-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d573786c565138d7f707358991b0a090bdde0fd2137489ef5400bceb2fba9fb5
MD5 18138c13dd1efeb5f0cfb54e30decbbb
BLAKE2b-256 9c7bf60c71dd99f424ad6e02f1b2a9406a23917b0491bda44d5cd4063737a66e

See more details on using hashes here.

Provenance

The following attestation bundles were made for redblackgraph-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: release.yml on rappdw/redblackgraph

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