Variable Block Compressed Sparse Row Matrix with MPI support
Project description
Distributed variable-block sparse matrices with fast block kernels + thresholded SpMM. Python-first, MPI-scalable, designed for localized-orbital Hamiltonians and multi-DOF PDE systems.
Why VBCSR?
- Hardware-Accelerated Performance: Leveraging SIMD (AVX/AVX2) instructions, precaching and threading, VBCSR delivers state-of-the-art performance for block-sparse matrix operations.
- Easy Integration: Header-only C++ core for easy inclusion in both Python and C++ projects.
- Pythonic & Intuitive: Perform complex linear algebra using natural Python syntax (
A * x,A + B,A @ B) and standard NumPy arrays. - Scalable & Distributed: Built on MPI to handle massive datasets across distributed computing clusters.
- Seamless Integration: Drop-in compatibility with SciPy solvers (
scipy.sparse.linalg) for easy integration into existing workflows.
Installation
First, please ensure your environment have compilers for c and fortran, also BLAS (OpenBLAS, MKL) and OpenMP are installed. The code also need mpi. You can install them using:
conda install -c conda-forge openblas/mkl openmp openmpi mpi4py compilers
or
sudo apt-get install build-essential gfortran libopenblas-dev libmkl-dev libopenmp-dev libopenmpi-dev
Then, you can install the package using:
pip install .
For advanced installation options (BLAS/MKL, OpenMP), please see doc/advanced_installation.md.
Documentation
- User Guide: Comprehensive guide on concepts, usage, and examples.
- API Reference: Detailed documentation of classes and methods.
- Advanced Installation: Instructions for BLAS/MKL and OpenMP.
VBCSR Performance Benchmark
Comparison of Matrix-Vector Multiplication (SpMV) performance between vbcsr (with MKL) and scipy.sparse.csr_matrix.
Test Configuration
- Block Size: Random [16, 20]
- Density: Adaptive (ensuring ~200 non-zero blocks per row)
- Data Type: float64
- System: Linux, MKL Backend, 32 core 13th Gen Intel(R) Core(TM) i9-13900K
Results
| Blocks | Approx Rows | VBCSR Time (s) | SciPy Time (s) | Speedup |
|---|---|---|---|---|
| 500 | ~9000 | 0.0049 | 0.0209 | 4.21x |
| 1000 | ~18000 | 0.0096 | 0.0392 | 4.07x |
| 5000 | ~90000 | 0.0468 | 0.2029 | 4.33x |
| 10000 | ~180000 | 0.0931 | 0.4151 | 4.46x |
| 20000 | ~360000 | 0.1866 | 0.8377 | 4.49x |
Visualization
Usage Examples
Basic Usage
import numpy as np
import vbcsr
from mpi4py import MPI
# Create a serial matrix
comm = MPI.COMM_WORLD
mat = vbcsr.VBCSR.create_serial(comm, global_blocks=2, block_sizes=[2, 2], adjacency=[[0, 1], [0, 1]])
# Add blocks and assemble
mat.add_block(0, 0, np.eye(2))
mat.assemble()
# Matrix-Vector Multiplication
v = np.array([1.0, 2.0, 3.0, 4.0])
res = mat.mult(v)
print(res.to_numpy())
Distributed Usage
# Run with: mpirun -np 2 python script.py
import numpy as np
import vbcsr
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
# Define distributed structure (2 blocks total, 1 per rank)
owned_indices = [rank]
block_sizes = [2]
adjacency = [[0, 1]] # Both blocks connected to both
mat = vbcsr.VBCSR.create_distributed(comm, owned_indices, block_sizes, adjacency)
# Fill local blocks
mat.add_block(rank, 0, np.eye(2))
mat.add_block(rank, 1, np.eye(2))
mat.assemble()
v = mat.create_vector()
v.set_constant(1.0)
res = mat.mult(v)
print(f"Rank {rank}: {res.to_numpy()}")
SciPy Integration
from scipy.sparse.linalg import cg
# Use VBCSR as a LinearOperator
x, info = cg(mat, v, rtol=1e-5)
Filtered SpMM
To perform sparse matrix-matrix multiplication with filtering (dropping small blocks), use the spmm method directly:
# C = A * B, dropping blocks with Frobenius norm < 1e-6
C = A.spmm(B, threshold=1e-6)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vbcsr-0.1.1.tar.gz.
File metadata
- Download URL: vbcsr-0.1.1.tar.gz
- Upload date:
- Size: 253.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56b6240775901473aa0dd485546312c593fba30a073c696f7032a63d65e7513f
|
|
| MD5 |
135607a16043eb712ab28ae7fef43732
|
|
| BLAKE2b-256 |
93f0cfe266ac2c15e7bb1b2705a7e2b1051a10348b4a44e9852752609b9499c3
|
File details
Details for the file vbcsr-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7325b647620b6b4701711960f3165a606b35296def3c77139f0cd33d7431c76
|
|
| MD5 |
13a2c444569a2761111ec232c7566a29
|
|
| BLAKE2b-256 |
1ef82576b3e1c67f974664b2b1a33a94add8b9fe3904519a03edc54c35c47dd0
|
File details
Details for the file vbcsr-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d4515f3058c0cbe803fab45b2eff3ec3d1963e7c8a27fcbc180226cc44218f1
|
|
| MD5 |
0b3a963858f95c159a84df6a0b3367b3
|
|
| BLAKE2b-256 |
489052506a48cea85d7bb88742154095d18b83edbdb59ac7cf586b7e27b3fafe
|
File details
Details for the file vbcsr-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b37e82c5e711f96b4c75985100fed7ec52ba4699ccde9a85cfac6064fd6cbba
|
|
| MD5 |
03408509711b5ebf8d94b78b36141535
|
|
| BLAKE2b-256 |
6e154e3ad5de30b8e35099d5cacad4c2833b32678a99011a8db3feb03ad116cb
|
File details
Details for the file vbcsr-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19a5ca3bdaf0a13aeef4ef0fd58e8ede373ea666bccd97801e5ca89f34ed8e82
|
|
| MD5 |
85a84401c76d4d65b0f3847285994568
|
|
| BLAKE2b-256 |
d0e45a653e5a349bcea9aaa79a06e8b63357d351b5a6404c60915f83e74c2b55
|
File details
Details for the file vbcsr-0.1.1-cp39-cp39-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3492105f698f10d9e4ca9f9f31f00f2657cbcbbad5b161cc97398d69593e4612
|
|
| MD5 |
36ae3580d2ad435b2721871661a94a65
|
|
| BLAKE2b-256 |
d5366d7d97559c6708737b12b0c8ec39f0ebe5afbe29f4f8dcb337fe91f1db47
|
File details
Details for the file vbcsr-0.1.1-cp38-cp38-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: vbcsr-0.1.1-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f5688cb254e272084ef76cd8311427d24b63207dbfedbede59efb51186f92f0
|
|
| MD5 |
d034eb924510143048cb571098320bc1
|
|
| BLAKE2b-256 |
0bc59988e71eeeb4fb1aa8220705a763057472e265782a1f6bcfc4af29b039b4
|