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.
Real-World Applications
VBCSR is designed for complex physics and engineering simulations where block-sparse structures are natural.
1. Linear-Scaling Quantum Chemistry (McWeeny Purification)
Compute the density matrix of a large-scale system using McWeeny Purification. VBCSR's filtered SpMM ensures the matrix remains sparse throughout the iteration. See /examples/ex07_graphene_purification.py for a full implementation.
# 1. Create a large-scale tight-binding Hamiltonian (e.g., 5000 blocks)
H = VBCSR.create_random(global_blocks=5000, block_size_min=4, block_size_max=8)
# 2. Simple spectral scaling
H.scale(0.1); H.shift(0.5)
# 3. McWeeny Purification: P_{n+1} = 3P_n^2 - 2P_n^3
P = H.copy()
for _ in range(10):
P2 = P.spmm(P, threshold=1e-5)
P = 3.0 * P2 - 2.0 * P2.spmm(P, threshold=1e-5)
# P is now the density matrix, distributed across your MPI cluster!
2. Stochastic Trace Estimation & DOS (KPM)
Compute the Density of States (DOS) using the Kernel Polynomial Method (KPM) with stochastic trace estimation. See examples/ex08_graphene_dos.py for a full implementation.
energies, dos = compute_kpm_dos(H, num_moments=200, num_random_vecs=10)
3. Quantum Dynamics & PDE Solving
- Quantum Dynamics: Propagate wavepackets in time using Chebyshev expansion (
examples/ex09_graphene_dynamics.py).
- Variable-Block PDEs: Solve heterogeneous systems (e.g., mixed Truss/Beam elements) with variable DOFs per node (
examples/ex10_variable_pde.py).
Installation
VBCSR requires a C++ compiler, MPI, and BLAS/LAPACK (OpenBLAS or MKL).
Quick Start (Recommended)
conda install -c conda-forge openblas/mkl openmpi mpi4py
pip install vbcsr
From Source
git clone https://github.com/yourusername/vbcsr.git
cd vbcsr
pip install .
For advanced installation options (MKL, OpenMP, etc.), see doc/advanced_installation.md.
Documentation
- User Guide: Concepts, usage, and examples.
- API Reference: Detailed documentation of classes and methods.
- Advanced Installation: BLAS/MKL and OpenMP tuning.
Performance at a Glance
VBCSR is designed for high-performance block-sparse operations, significantly outperforming standard CSR implementations for block-structured matrices.
| 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 |
Pythonic Usage
VBCSR matrices behave like first-class Python objects, supporting standard arithmetic and seamless integration with the SciPy ecosystem.
1. Easy Initialization from SciPy
Convert any SciPy sparse matrix (BSR or CSR) to a distributed VBCSR matrix in one line.
import scipy.sparse as sp
from vbcsr import VBCSR
# Create a SciPy BSR matrix
A_scipy = sp.bsr_matrix(np.random.rand(100, 100), blocksize=(10, 10))
# Convert to VBCSR (automatically distributed if MPI is initialized)
A = VBCSR.from_scipy(A_scipy)
2. Natural Arithmetic & Operators
Use standard Python operators for matrix-vector and matrix-matrix operations.
# Matrix-Vector Multiplication (SpMV)
y = A @ x # or A.mult(x)
# Filtered Sparse Matrix-Matrix Multiplication (SpMM)
C = A @ B # or A.spmm(B, threshold=1e-4)
# Matrix Arithmetic
D = 2.0 * A + B - 0.5 * C
3. Distributed Computing Made Simple
VBCSR handles the complexity of MPI communication behind the scenes.
from mpi4py import MPI
comm = MPI.COMM_WORLD
# Create a distributed matrix with 100 blocks
A = VBCSR.create_random(global_blocks=100, block_size_min=4, block_size_max=8, comm=comm)
# Perform distributed SpMV
x = A.create_vector()
x.set_constant(1.0)
y = A @ x
4. Custom Distributed Creation
For full control, define your own block distribution and connectivity pattern.
# Create the distributed matrix structure
A = VBCSR.create_distributed(owned_indices, block_sizes, adjacency, comm=comm)
# Fill blocks (can add local or remote blocks; VBCSR handles the exchange)
A.add_block(rank, rank, np.eye(2))
A.add_block(rank, (rank + 1) % comm.size, np.ones((2, 2)))
# Finalize assembly to synchronize remote data
A.assemble()
5. SciPy Solver Integration
VBCSR implements the LinearOperator interface, making it compatible with all SciPy iterative solvers.
from scipy.sparse.linalg import cg
# Solve Ax = b using Conjugate Gradient
x, info = cg(A, b, rtol=1e-6)
Metadata
Release files for vbcsr 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vbcsr-0.2.2.tar.gz | 894.0 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| vbcsr-0.2.2-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| vbcsr-0.2.2-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| vbcsr-0.2.2-cp311-cp311-manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64 | Details |
| vbcsr-0.2.2-cp310-cp310-manylinux_2_28_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.28+ x86-64 | Details |
| vbcsr-0.2.2-cp39-cp39-manylinux_2_28_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.28+ x86-64 | Details |
| vbcsr-0.2.2-cp38-cp38-manylinux_2_28_x86_64.whl | CPython 3.8 | CPython 3.8 | Linux glibc 2.28+ x86-64 | Details |
Total release size: 98.5 MB
Release files / vbcsr-0.2.2.tar.gz
| Download URL | vbcsr-0.2.2.tar.gz |
|---|---|
| Size | 894.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04e0d99fad262af85f084031be94713e20c6bdbc264f4503935967b125e31edc
|
|
BLAKE2b-256 checksum How to use checksums |
c48ffd913110765c9ab654a79b70637d9ea5bda607d4ae12ae524169c574d5df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
0b277b73e8c3f158d6488793d726d35803c9339a4eb5eee3ceb309cb6d15dae6
|
|
BLAKE2b-256 checksum How to use checksums |
e342f41923737424d5cfe1ee50673861f781e40e581cfab6614634782109a822
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
7a50e336c5bd1fcc69dc724393fcf1bd8e4460e1a9e6266201973022a2cb5b1c
|
|
BLAKE2b-256 checksum How to use checksums |
5ce6c2931daf8daa7aa2faa082dc4fca237963a6097a0989f5de2d37b76c900f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1993d24d065f8ccaec0f709de493e33b3a7d6884023ec9e83a5bd1ff852233af
|
|
BLAKE2b-256 checksum How to use checksums |
45e89b9ecb3fa9fe6cc5958fec9988302ae888a37e8664f639bec5f614efc26f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
5bfafe2c1299ba4c3693cccd4eded5c5cdbfdbcbaaf5e8f318a9179d90c3a309
|
|
BLAKE2b-256 checksum How to use checksums |
07a4a970f1f847667a1d2742a68b4e39b44b8bbcfff0f4eebc95c11284a7efd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp39-cp39-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp39-cp39-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
945a03d16fd56117f895b10751fbf73220dd1bfc5c0c01541564026b7abf3074
|
|
BLAKE2b-256 checksum How to use checksums |
557255326573dffc4ef4a223e5499f50cfbc8b1fd94ab6a196fd6cf933da4fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / vbcsr-0.2.2-cp38-cp38-manylinux_2_28_x86_64.whl
| Download URL | vbcsr-0.2.2-cp38-cp38-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
be4586e8297af9f83e7c86c9dabe95d04ab19a6ec30fc0d5b6e9eb8faaca427d
|
|
BLAKE2b-256 checksum How to use checksums |
c6203052ea286b0724e81de9561df7e1a1b09806d5e92b8aa58eca48c941666e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|