Skip to main content

Python bindings for the sparse-ir-capi library

Project description

Python bindings for sparse-ir-capi

This is a low-level binding for the sparse-ir-capi Rust library.

Requirements

  • Python >= 3.10
  • Rust toolchain (for building the Rust library)
  • uv (for building and managing Python dependencies)
  • numpy >= 1.26.4
  • scipy

BLAS Support

This package automatically uses SciPy's BLAS backend for optimal performance. No additional BLAS installation is required - SciPy will provide the necessary BLAS functionality.

Build

Install Dependencies and Build

# Build the package (Rust library will be built automatically)
cd python
uv build

This will:

  • Automatically build the Rust sparse-ir-capi library using Cargo (via CMake)
  • Copy the built library and header files to the Python package
  • Create both source distribution (sdist) and wheel packages

Development Build

For development:

# Install in development mode (will auto-prepare if needed)
uv sync

Note for CI/CD: The Rust library is built automatically during the Python package build. No separate build step is needed:

# In CI/CD scripts
cd python
uv build

See .github-workflows-example.yml for a complete GitHub Actions example.

BLAS Configuration

The package automatically uses SciPy's BLAS backend, which provides optimized BLAS operations without requiring separate BLAS installation. The build system is configured to use SciPy's BLAS functions directly.

Clean Build Artifacts

To remove build artifacts and files copied from the parent directory:

uv run clean

This will remove:

  • Build directories: build/, dist/, *.egg-info
  • Compiled libraries: pylibsparseir/*.so, pylibsparseir/*.dylib, pylibsparseir/*.dll
  • Cache directories: pylibsparseir/__pycache__

Build Process Overview

The build process works as follows:

  1. CMake Configuration: scikit-build-core invokes CMake, which:

    • Finds the Cargo executable
    • Sets up build targets for the Rust library
  2. Rust Library Build: CMake calls Cargo to build sparse-ir-capi:

    • Compiles the Rust library to a shared library (.so, .dylib, or .dll)
    • Generates C header file (sparseir.h) using cbindgen (via build.rs)
    • Copies the library and header to the pylibsparseir directory
  3. Python Package Building: uv build or uv sync:

    • Packages everything into distributable wheels and source distributions
  4. Installation: The built package includes the compiled shared library and Python bindings

Conda Build

This package can also be built and distributed via conda-forge. The conda recipe is located in conda-recipe/ and supports multiple platforms and Python versions.

Building conda packages locally:

# Install conda-build
conda install conda-build

# Build the conda package
cd python
conda build conda-recipe

# Build for specific platforms
conda build conda-recipe --platform linux-64
conda build conda-recipe --platform osx-64
conda build conda-recipe --platform osx-arm64

Supported platforms:

  • Linux x86_64
  • macOS Intel (x86_64)
  • macOS Apple Silicon (ARM64)

Supported Python versions:

  • Python 3.11, 3.12, 3.13

Supported NumPy versions:

  • NumPy 2.1, 2.2, 2.3

The conda build automatically:

  • Uses SciPy's BLAS backend for optimal performance
  • Cleans up old shared libraries before building
  • Builds platform-specific packages with proper dependencies

Performance Notes

BLAS Support

This package automatically uses SciPy's optimized BLAS backend for improved linear algebra performance:

  • Automatic BLAS: Uses SciPy's BLAS functions for optimal performance
  • No additional setup: SciPy provides all necessary BLAS functionality

The build system automatically configures BLAS support through SciPy. You can verify BLAS support by checking the build output for messages like:

export SPARSEIR_DEBUG=1
python -c "import pylibsparseir"

This will show:

BLAS support enabled
Registered SciPy BLAS dgemm @ 0x...

Troubleshooting

Build fails with missing Cargo:

# Make sure Rust toolchain is installed
# Install from https://rustup.rs/
# Then retry:
cd python
uv build

Clean rebuild:

# Remove all build artifacts
uv run clean
cd ../sparse-ir-capi
cargo clean
cd ../python
uv build

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.

pylibsparseir-0.8.4-cp313-cp313-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pylibsparseir-0.8.4-cp313-cp313-macosx_15_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pylibsparseir-0.8.4-cp312-cp312-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pylibsparseir-0.8.4-cp312-cp312-macosx_15_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pylibsparseir-0.8.4-cp311-cp311-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pylibsparseir-0.8.4-cp311-cp311-macosx_15_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pylibsparseir-0.8.4-cp310-cp310-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pylibsparseir-0.8.4-cp310-cp310-macosx_15_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pylibsparseir-0.8.4-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2592eb2e6155b41a5222063928f813be20423642bc24893f7f2da25411ad783b
MD5 730f25ad0394989fec143a3584a16a5e
BLAKE2b-256 2100cef599a3dddfe0db7cfc4a76587b12cef6544e416deab34ac9b63640ac63

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0e76190615e5e8184d27e814ed58bc404257f0e38d5af5c61b186f63729dd51b
MD5 10b26967b7c3c446d9990118576fb8a5
BLAKE2b-256 f0db8750e8abab53335f409bee694bdebabb397bee55736dcff6bcdda42d57d6

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1cf017d765d015403e002268a4071078034482d439ad26ada1ed7dba75504160
MD5 d26582f4eadb17c302a21fd210a72ed2
BLAKE2b-256 72e6dc776b377385029cee63c30bab5714d381ae74bf419cb7f85915d3598abc

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 70e7be864b98c82d146cd9e478bb768774391caeee2072671f491c14b03752fd
MD5 0bdce60255cbfbf0d2e689d9cebb9234
BLAKE2b-256 8bc90fd0e9a9d85ae2a2be1c20f33c87b3a5a4b04f0b33c50d9e02c9900c3e2f

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 74e09534065b70938347f2441bb984022c13de2c007c45ca995fc9339c2fcfaa
MD5 391b98809a1a3a9b924d92428136bb8e
BLAKE2b-256 ae9f6ab1e6d7a746e8cab1fb9de69087316a8376da56c2f80ebed692296568db

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 dd3f9284416900bca037256986cdd43c63c80bb81b679ffe131cc8e35f512e9b
MD5 7b20a601b486275bf9d5c98336b612d6
BLAKE2b-256 e88180a5015e3eea538f10fa03bcefb5e6805ea5874d8b940f59c4b30e94a2de

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f85505e9a2cbc8a0ceddcff466b6ec0a3a9a257a62bf4b7b549e50f3e0589d1
MD5 4ec088a7025dadb1e944bbb30473cef5
BLAKE2b-256 6bf4d2b37a1a22895c11d97fe52e4be825ebeff4003ed3e108506557fd4cc218

See more details on using hashes here.

File details

Details for the file pylibsparseir-0.8.4-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pylibsparseir-0.8.4-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c312886df4d4ea066b9cacd56f65710ec0de1715da43b806f4c535b8d2301ac6
MD5 05226dbe541676323ff4a2af4b3d2bf6
BLAKE2b-256 18912d9ff37975031b39d4f3a0b2eb1f115a8ca75b7fba248da8dfe2fb199896

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