Skip to main content

Project logo

pycubool

JB Research Ubuntu License

pycubool is a python wrapper for cuBool library.

cuBool is a linear Boolean algebra library primitives and operations for work with sparse matrices written on the NVIDIA CUDA platform. The primary goal of the library is implementation, testing and profiling algorithms for solving formal-language-constrained problems, such as context-free and regular path queries with various semantics for graph databases. The library provides C-compatible API, written in the GraphBLAS style.

The library is shipped with python package pycubool - wrapper for cuBool library C API. This package exports library features and primitives in high-level format with automated resources management and fancy syntax sugar.

The primary library primitive is a sparse boolean matrix. The library provides the most popular operations for matrix manipulation, such as construction from values, transpose, sub-matrix extraction, matrix-to-vector reduce, matrix-matrix element-wise addition, matrix-matrix multiplication and Kronecker product.

As a fallback library provides sequential backend for mentioned above operations for computations on CPU side only. This backend is selected automatically if Cuda compatible device is not presented in the system. This can be quite handy for prototyping algorithms on a local computer for later running on a powerful server.

Features

  • Matrix creation (empty, from data, with random data)
  • Matrix-matrix operations (multiplication, element-wise addition, kronecker product)
  • Matrix operations (equality, transpose, reduce to vector, extract sub-matrix)
  • Matrix data extraction (as lists, as list of pairs)
  • Matrix syntax sugar (pretty string printing, slicing, iterating through non-zero values)
  • IO (import/export matrix from/to .mtx file format)
  • GraphViz (export single matrix or set of matrices as a graph with custom color and label settings)
  • Debug (matrix string debug markers, logging)

Simple example

Create sparse matrices, compute matrix-matrix product and print the result to the output:

import pycubool as cb

a = cb.Matrix.empty(shape=(2, 3))
a[0, 0] = True
a[1, 2] = True

b = cb.Matrix.empty(shape=(3, 4))
b[0, 1] = True
b[0, 2] = True
b[1, 3] = True
b[2, 1] = True

print(a, b, a.mxm(b), sep="\n")

Transitive closure example

Compute the transitive closure problem for the directed graph and print the result:

import pycubool as cb

a = cb.Matrix.empty(shape=(4, 4))
a[0, 1] = True
a[1, 2] = True
a[2, 0] = True
a[2, 3] = True
a[3, 2] = True

t = a.dup()                             # Duplicate matrix where to store result
total = 0                               # Current number of values

while total != t.nvals:
    total = t.nvals
    t.mxm(t, out=t, accumulate=True)    # t += t * t

print(a, t, sep="\n")

GraphViz example

Generate GraphViz graph script for a graph stored as a set of adjacency matrices:

import pycubool as cb

name = "Test"                           # Displayed graph name   
shape = (4, 4)                          # Adjacency matrices shape
colors = {"a": "red", "b": "green"}     # Colors per label

a = cb.Matrix.empty(shape=shape)        # Edges labeled as 'a'
a[0, 1] = True
a[1, 2] = True
a[2, 0] = True

b = cb.Matrix.empty(shape=shape)        # Edges labeled as 'b'
b[2, 3] = True
b[3, 2] = True

print(cb.matrices_to_gviz(matrices={"a": a, "b": b}, graph_name=name, edge_colors=colors))

Script can be rendered by any gviz tool online and the result can be following:

gviz-example

Contributors

Citation

@online{cuBool,
  author = {Orachyov, Egor and Alimov, Pavel and Grigorev, Semyon},
  title = {cuBool: sparse Boolean linear algebra for Nvidia Cuda},
  year = 2020,
  url = {https://github.com/JetBrains-Research/cuBool},
  note = {Version Alpha}
}

License

This project is licensed under MIT License. License text can be found in the license file.

Acknowledgments

This is a research project of the Programming Languages and Tools Laboratory at JetBrains-Research. Laboratory website link.

Also

The name of the library is formed by a combination of words Cuda and Boolean, what literally means Cuda with Boolean and sounds very similar to the name of the programming language COBOL.

Metadata

Release files for pycubool 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycubool 1.0.0
File Size Uploaded
pycubool-1.0.0.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycubool 1.0.0
File Interpreter ABI Platform
pycubool-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 959.5 kB

Release files / pycubool-1.0.0.tar.gz

Download URL pycubool-1.0.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ad6d958efe0b0d46893aa637071b1a3d8bc872e79a2f2e14bfd2efa3f2aa6e00
BLAKE2b-256 checksum
How to use checksums
6627aca83a7ae78a92be8cd91fd839980a919854f0d07cfda41eb9b711ec5104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5

Release files / pycubool-1.0.0-py3-none-any.whl

Download URL pycubool-1.0.0-py3-none-any.whl
Size 942.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
939108b82da92207f12da82de70e7e55af9df10b6dc8b7ae741f2eb70b86258d
BLAKE2b-256 checksum
How to use checksums
9b27e464bfec6c821043931ca122704d9702a8e31a104cf5677022a3ebc02a67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page