Skip to main content

Customized sparse solver with Numba support

Project description

Sparse_Numba

A lightweight, Numba-compatible sparse linear solver designed for efficient parallel computations in Python.

PyPI version Build Status Python Versions

Why Sparse_Numba?

Python is widely used for rapid prototyping and demonstration, despite its limitations in computationally intensive tasks. Existing sparse linear solvers (e.g., SciPy and KVXOPT) are efficient for single-task scenarios but face performance bottlenecks if there are frequent data exchanges and Python's Global Interpreter Lock (GIL).

Sparse_Numba addresses these limitations by providing a sparse linear solver fully compatible with Numba's Just-In-Time (JIT) compilation. This design allows computationally intensive tasks to run efficiently in parallel, bypassing Python's GIL and significantly improving multi-task solving speed.

Installation

pip install sparse-numba

Due to the license issue, this package cannot include DLLs from umfpack. To run the existing function in this package, the user needs to install umfpack by yourself and add the necessary DLLs to the system path or put under:

.venv/site-packages/sparse_numba/vendor/suitesparse/bin

Support for SuperLU solver has been added in the current version (0.1.6). Other solvers might be added soon. Sorry for this inconvenience.

Installing from source (Windows)

If installing from source on Windows, you need to have MinGW installed and configured for Python:

  1. Install MinGW-w64 (x86_64-posix-seh)
  2. Add MinGW bin directory to your PATH
  3. Create or edit your distutils.cfg file:
    • Location: %USERPROFILE%\.distutils.cfg
    • Content:
      [build]
      compiler=mingw32
      
  4. Then:
python -m build --wheel
pip install dist/sparse_numba-%YOURVERSION%.whl

Note: Despite installing MinGW-w64 (64-bit), the compiler setting is still mingw32. This is the correct name for the distutils compiler specification and does not affect the bitness of the compiled extension.

Detailed installation information can be found here.

Usage

import numpy as np
from sparse_numba import umfpack_solve_csc, superlu_solve_csc

# Example with CSC format (Compressed Sparse Column)
# Create a sparse matrix in CSC format
indptr = np.array([0, 2, 3, 6])
indices = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
b = np.array([1.0, 2.0, 3.0])

# Solve the linear system Ax = b
    # umfpack solver
x_umfpack = umfpack_solve_csc(data, indices, indptr, b)
print(x_umfpack)

    # superlu solver
x_superlu = superlu_solve_csc(data, indices, indptr, b)
print(x_superlu)

# More examples for COO and CSR formats...

Performance Comparison

Single Problem Performance

We compare the computational speed with SciPy for solving single problems of different sizes. The test result on an Intel Ultra 7 258V processor.

  1. UMFPACK V.S. SciPy (spsolve):

Single Problem Benchmark

  1. SuperLU V.S. SciPy (spsolve):

Single Problem Benchmark

Multi-Task Performance

We compare the multi-task performance of Sparse_Numba with sequential SciPy.

  1. SuperLU V.S. SciPy (spsolve) with 258V:

Parallel Solver Benchmark Speedup Factor

  1. SuperLU V.S. Scipy (spsolve) with Xeon W-2255:

Parallel Solver Benchmark Speedup Factor

Note: The initialization time is included in single problem benchmarks. This is why the Numba-compatible function is initially slower, but the performance advantage becomes evident as parallelization takes effect.

Features and Limitations

Current Features

  • UMFPACK solver integration with Numba compatibility
  • SuperLU solver integration with Numba compatibility
  • Support for CSC, COO, and CSR sparse matrix formats
  • Efficient parallel solving for multiple systems

Limitations

  • The UMFPACK DLL files are not redistributed in this tool
  • Other solvers are under development
  • Performance may be limited for extremely ill-conditioned matrices
  • Only developed/tested for Windows, the support for other platforms (Linux and MacOS) are added without testing

Roadmap

This package serves as a temporary solution until Python's no-GIL and improved JIT features become widely available. At that time, established libraries like SciPy and KVXOPT will likely offer more comprehensive implementations with parallel computing features.

License

BSD 3-Clause License

License Statement of OpenBLAS:

DLLs of OpenBLAS can be obtained from build: https://github.com/OpenMathLib/OpenBLAS

License Statement of SuperLU:

DLLs of SuperLU can be obtained from build: https://github.com/xiaoyeli/superlu

License Acknowledgment

  • libgcc_s_seh-1.dll
  • libgfortran-5.dll
  • libgomp-1.dll
  • libquadmath-0.dll
  • libwinpthread-1.dll These components are redistributed from the GNU toolchain

Citation

If you use Sparse_Numba in your research, you can consider to cite:

@software{hong2025sparse_numba,
  author = {Hong, Tianqi},
  title = {Sparse_Numba: A Numba-Compatible Sparse Solver},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/th1275/sparse_numba}
}

Contributing to Sparse_Numba

As an entry-level (or baby-level) developer, I still need more time to figure out the workflow. Due to my limited availability, this tool will also be updated very slowly. Please be patient.

Thank you!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sparse_numba-0.1.9-cp312-cp312-win_amd64.whl (16.8 MB view details)

Uploaded CPython 3.12Windows x86-64

sparse_numba-0.1.9-cp311-cp311-win_amd64.whl (16.8 MB view details)

Uploaded CPython 3.11Windows x86-64

sparse_numba-0.1.9-cp310-cp310-win_amd64.whl (16.8 MB view details)

Uploaded CPython 3.10Windows x86-64

sparse_numba-0.1.9-cp39-cp39-win_amd64.whl (16.8 MB view details)

Uploaded CPython 3.9Windows x86-64

sparse_numba-0.1.9-cp38-cp38-win_amd64.whl (16.8 MB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file sparse_numba-0.1.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for sparse_numba-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cf87d4505f265e634b23c04cd3ab3cb9e1b49f5b106167eae276280e924351a2
MD5 0774b4df78b3a270e1d0be40b4fe933e
BLAKE2b-256 2ba9a261576d0551d96a0c00d713e35d3c5807fc649d0c1734ec60add007e749

See more details on using hashes here.

File details

Details for the file sparse_numba-0.1.9-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for sparse_numba-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0d9cf68d8c4ffc50726a3c5e11ae91b2a47fa83f23fed0c3b9ae26a95edfb508
MD5 d0762899d400af4108aa444f776c1004
BLAKE2b-256 9214e4414e137db3dded51b15a834753adc8d8778212607abd95a2895d8ec593

See more details on using hashes here.

File details

Details for the file sparse_numba-0.1.9-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for sparse_numba-0.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e37e7a27073225784c59e572fea795c420d00ca49fa8153d10f411da5d68f978
MD5 96d098ff709b76a6106ded3977bf2775
BLAKE2b-256 2f1df429abcb83046b37b5cff17725fec39008eb36c1897934c55f4fef1058b3

See more details on using hashes here.

File details

Details for the file sparse_numba-0.1.9-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: sparse_numba-0.1.9-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 16.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for sparse_numba-0.1.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b08dbb2abcaf2a07164fd2e9152e9953f846412fe26310faa3514530f4f5a282
MD5 f7c22da955a3186b1b46601bf636e7d4
BLAKE2b-256 c147664a4f1fe11848743a22b807a5d81f8b5f64a7d1219a1a962ed9cdac6012

See more details on using hashes here.

File details

Details for the file sparse_numba-0.1.9-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: sparse_numba-0.1.9-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 16.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for sparse_numba-0.1.9-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bb26b537bdfa780826309b607a437f419cf2decf450ea5ab08938b117cf21929
MD5 3c2ce56e89ef80d19aea1adf95ee926a
BLAKE2b-256 33bce95daac4b3ca796e34f31c4247dbdbc1f58c0fac1eeb4b105ddcf3f4d665

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page