Package: pycubool
pycuboolpycuboolis a python wrapper forcuBoollibrary.cuBoolis 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
solvingformal-language-constrained problems, such ascontext-freeandregularpath queries with various semantics for graph databases.
The library provides C-compatible API, written in the GraphBLAS style.The libraryis shipped with python packagepycubool- 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 primitivesare sparse matrix and sparse vector of boolean values.
The library provides the most popular operations for matrix manipulation,
such as construction from values, transpose, sub-matrix/sub-vector extraction, matrix-to-vector reduce,
element-wise addition, matrix-matrix, matrix-vector, vector-matrix multiplication, and Kronecker product.As a fallbacklibrary 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.FeaturesCuda backend for computationsCpu backend for computationsMatrix/vector creation (empty, from data, with random data)Matrix-matrix operations (multiplication, element-wise addition, kronecker product)Matrix-vector operations (matrix-vector and vector-matrix multiplication)Vector-vector operations (element-wise addition)Matrix operations (equality, transpose, reduce to vector, extract sub-matrix)Vector operations (equality, reduce to value, extract sub-vector)Matrix/vector data extraction (as lists, as list of pairs)Matrix/vector syntax sugar (pretty string printing, slicing, iterating through non-zero values)IO (import/export matrix from/to.mtxfile format)GraphViz (export single matrix or set of matrices as a graph with custom color and label settings)Debug (matrix string debug markers, logging)PerformanceSparse Boolean matrix-matrix multiplication evaluation results are listed bellow.
Machine configuration: PC with Ubuntu 20.04, Intel Core i7-6700 3.40GHz CPU, DDR4 64Gb RAM, GeForce GTX 1070 GPU with 8Gb VRAM.The matrix data is selected from the SuiteSparse Matrix Collectionlink.Matrix name# RowsNnz MNnz/rowMax Nnz/rowNnz M^2SNAP/amazon0312400,7273,200,4407.91014,390,544LAW/amazon-2008735,3235,158,3887.01025,366,745SNAP/web-Google916,4285,105,0395.545629,710,164SNAP/roadNet-PA1,090,9203,083,7962.897,238,920SNAP/roadNet-TX1,393,3833,843,3202.7128,903,897SNAP/roadNet-CA1,971,2815,533,2142.81212,908,450DIMACS10/netherlands_osm2,216,6884,882,4762.278,755,758Detailed comparison is available in the full paper text atlink.Simple exampleCreate sparse matrices, compute matrix-matrix product and print the result to the output:importpycuboolascba=cb.Matrix.empty(shape=(2,3))a[0,0]=Truea[1,2]=Trueb=cb.Matrix.empty(shape=(3,4))b[0,1]=Trueb[0,2]=Trueb[1,3]=Trueb[2,1]=Trueprint(a,b,a.mxm(b),sep="\n")Vector exampleCreate sparse matrix and vector, compute matrix-vector and vector-matrix products and print the result:importpycuboolascbm=cb.Matrix.empty(shape=(3,4))m[0,1]=Truem[1,0]=Truem[1,3]=Truem[2,2]=Truev=cb.Vector.empty(nrows=4)v[0]=Truev[2]=Truet=cb.Vector.empty(nrows=3)t[0]=Truet[2]=Trueprint(m.mxv(v),t.vxm(m),sep="\n")Transitive closure exampleCompute the transitive closure problem for the directed graph and print the result:importpycuboolascba=cb.Matrix.empty(shape=(4,4))a[0,1]=Truea[1,2]=Truea[2,0]=Truea[2,3]=Truea[3,2]=Truet=a.dup()# Duplicate matrix where to store resulttotal=0# Current number of valueswhiletotal!=t.nvals:total=t.nvalst.mxm(t,out=t,accumulate=True)# t += t * tprint(a,t,sep="\n")GraphViz exampleGenerate GraphViz graph script for a graph stored as a set of adjacency matrices:importpycuboolascbname="Test"# Displayed graph nameshape=(4,4)# Adjacency matrices shapecolors={"a":"red","b":"green"}# Colors per labela=cb.Matrix.empty(shape=shape)# Edges labeled as 'a'a[0,1]=Truea[1,2]=Truea[2,0]=Trueb=cb.Matrix.empty(shape=shape)# Edges labeled as 'b'b[2,3]=Trueb[3,2]=Trueprint(cb.matrices_to_gviz(matrices={"a":a,"b":b},graph_name=name,edge_colors=colors))Script can be rendered by anygviz toolonline and the result can be following:ContributorsEgor Orachyov (Github:EgorOrachyov)Pavel Alimov (Github :Krekep)Semyon Grigorev (Github:gsvgit)Citation@MISC{cuBool,
  author = {Orachyov, Egor and Alimov, Pavel and Grigorev, Semyon},
  title = {cuBool: sparse Boolean linear algebra for Nvidia Cuda},
  year = 2021,
  url = {https://github.com/JetBrains-Research/cuBool},
  note = {Version 1.1.0}
}LicenseThis project is licensed under MIT License. License text can be found in thelicense file.AcknowledgmentsThis is a research project of the Programming Languages and Tools Laboratory
at JetBrains-Research. Laboratory websitelink.AlsoThe name of the library is formed by a combination of wordsCudaandBoolean,
what literally meansCuda with Booleanand sounds very similar to the name of
the programming languageCOBOL.