Package: pyspbla
pyspblapyspblais a python wrapper forspblalibrary.spblais a linear Boolean algebra library primitives and operations for
work with sparse matrices written for CPU, Cuda and OpenCL platforms. 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 packagepyspbla- wrapper for
spbla 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 primitiveis 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 fallbacklibrary provides sequential backend for mentioned above operations
for computations on CPU side only. This backend is selected automatically
if Cuda/OpenCL 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 computationsOpenCL backend for computationsCpu backend for computationsMatrix 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.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:importpyspblaasspa=sp.Matrix.empty(shape=(2,3))a[0,0]=Truea[1,2]=Trueb=sp.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")Transitive closure exampleCompute the transitive closure problem for the directed graph and print the result:importpyspblaasspa=sp.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:importpyspblaasspname="Test"# Displayed graph nameshape=(4,4)# Adjacency matrices shapecolors={"a":"red","b":"green"}# Colors per labela=sp.Matrix.empty(shape=shape)# Edges labeled as 'a'a[0,1]=Truea[1,2]=Truea[2,0]=Trueb=sp.Matrix.empty(shape=shape)# Edges labeled as 'b'b[2,3]=Trueb[3,2]=Trueprint(sp.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)Maria Karpenko (Github:mkarpenkospb)Pavel Alimov (Github :Krekep)Semyon Grigorev (Github:gsvgit)Citation@online{spbla,
  author = {Orachyov, Egor and Karpenko, Maria and Alimov, Pavel and Grigorev, Semyon},
  title = {spbla: sparse Boolean linear algebra for CPU, Cuda and OpenCL computations},
  year = 2021,
  url = {https://github.com/JetBrains-Research/spbla},
  note = {Version 1.0.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.