Skip to main content

rslab (Python bindings)

NumPy/SciPy bindings for RSLAB, a pure-Rust sparse direct solver and preconditioner: complex/real symmetric LDL^T (Bunch-Kaufman), unsymmetric LU, and a KLU-style path for circuit-shaped matrices. A thin wrapper, all numeric work happens in Rust.

Install

pip install rslab

Usage

import numpy as np
import scipy.sparse as sp
import rslab

# Symmetric system (real or complex; the dtype selects the path).
A = sp.random(5000, 5000, density=1e-3, format="csc") + sp.eye(5000) * 10
A = A + A.T
b = np.random.rand(5000)

# One-shot solve.
x = rslab.spsolve(A, b)

# Factor once, solve many right-hand sides.
f = rslab.ldlt(A)
x1 = f.solve(b)
X = f.solve_many(np.random.rand(5000, 8))   # n x nrhs

print(f.n, f.factor_nnz, f.inertia, f.dtype)

Complex-symmetric matrices (EM/FEM, PARDISO mtype 6) work identically:

A = A.astype(np.complex128); A.data += 1j * 0.3 * A.data.real
x = rslab.ldlt(A).solve(np.ones(A.shape[0], dtype=np.complex128))

Unsymmetric matrices use the LU path:

f = rslab.lu(A_general)
x = f.solve(b)

Circuit-shaped matrices (MNA / SPICE-class: very sparse, unsymmetric, near-triangularizable) use the KLU path, bit-deterministic, with a numeric-only refactor for fixed-pattern sweeps:

f = rslab.klu(A_circuit)
x = f.solve(b)
A_circuit.data *= 1.5            # frequency sweep: same pattern, new values
f.refactor(A_circuit.data)       # no symbolic work, no pivot search
x2 = f.solve(b)
y = f.solve_transpose(b)         # A.T @ y = b on the same factors (adjoint)

solve_transpose is the plain transpose; for the conjugate-transpose adjoint use f.solve_transpose(b.conj()).conj().

Preconditioner mode

Never-fail static pivoting plus iterative refinement for hard/indefinite systems:

f = rslab.ldlt(A, preconditioner=1e-4)
x = f.solve(b, refine=20)        # refine against the original A

Configuration (keyword arguments)

By default ldlt, lu and spsolve use RSLAB's deterministic heuristic pick, the adaptive ordering plus an exact nested-dissection bakeoff on large systems (adopted only on a clear predicted win with no fill/memory regression). A one-time rslab.install_diagnose() measures this machine's throughput and speedup curve and caches it; afterwards the default also picks its worker count from the calibration (until then the conservative capped default applies). Keyword arguments override the pick:

kwarg default meaning
threads None (auto) None = calibrated/structural per-matrix pick; int = fixed (0 = all)
preconditioner None static-pivot floor (e.g. 1e-4); never-fail, refine to solve
drop_tol None incomplete-factor threshold (preconditioner)
method "left_looking" "left_looking" or "multifrontal"
memory "low" "low" or "eager" factor emit strategy
force_accept False accept tiny pivots in exact mode instead of failing

klu accepts:

kwarg default meaning
pivot_tol 1e-3 diagonal-preference threshold; 1.0 = plain partial pivoting
row_scaling True divide each row by its max-magnitude entry before factoring
btf True permute to block upper triangular form first (keep it on)
parallel None per-block parallel factor/refactor over the BTF blocks; None = auto gate (>=4 blocks, >=8000 nnz, no dominant block), True/False force on/off; bit-identical result in every mode

Supported dtypes: float64, float32, complex128, complex64.

API

Everything ships in the flat rslab namespace; full parameter documentation lives in the docstrings (help(rslab.klu) etc.).

Functions

function meaning
spsolve(A, b, **kw) one-shot factor-and-solve; detects symmetry and picks the LDL^T or LU path
ldlt(A, **kw) -> Ldlt factor a real/complex symmetric matrix (Bunch-Kaufman LDL^T)
lu(A, **kw) -> Lu factor a general unsymmetric matrix (supernodal multifrontal LU)
klu(A, **kw) -> Klu factor a circuit-shaped matrix (BTF + per-block Gilbert-Peierls LU)
install_diagnose() one-time machine calibration; caches the measured thread-speedup curve

Factor handles - factor once, then:

method / attribute Ldlt Lu Klu meaning
solve(b, refine=0) yes yes yes solve one RHS, optional iterative-refinement steps against the original A
solve_many(B) yes yes yes solve n x nrhs RHS in one batched pass
solve_transpose(b) - - yes solve A^T y = b on the same factors (plain transpose, not conjugate)
refactor(data) - - yes numeric-only re-factorization for new values on the same pattern (no symbolic work, no pivot search)
gmres(b, tol=1e-8, maxit=400, restart=None, x0=None, recycle=None) yes yes yes GMRES with this factor as preconditioner
gmres_block(B, tol=1e-8, maxit=400, restart=None, x0=None) yes yes yes block GMRES for multiple RHS
recycle(k) yes yes yes a Recycle workspace holding up to k deflation vectors across gmres calls
n, factor_nnz, n_perturbed, dtype yes yes yes dimension, stored factor entries, perturbed pivots (always 0 for Klu), NumPy dtype name
inertia yes - - (n_pos, n_neg, n_zero) eigenvalue counts from LDL^T
n_blocks - - yes number of BTF diagonal blocks

Recycle - deflation-subspace carrier for sweeps: attributes k, active, dtype; clear() resets it.

License

MIT.

Release files for rslab 0.28.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rslab 0.28.1
File Size Uploaded
rslab-0.28.1.tar.gz 1.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for rslab 0.28.1
File
rslab-0.28.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
rslab-0.28.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
rslab-0.28.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
rslab-0.28.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
rslab-0.28.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 11.4 MB

Release files / rslab-0.28.1.tar.gz

Download URL rslab-0.28.1.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
78535fe9c1c143f8e792bf8e0ce43d4eb660ef8bd5de0bfac10607ff4b916ff3
BLAKE2b-256 checksum
How to use checksums
c1f6116c2ec717d2d9d23812ea5068bb4669efb545b4c069084f76c205e0e43d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / rslab-0.28.1-cp39-abi3-win_amd64.whl

Download URL rslab-0.28.1-cp39-abi3-win_amd64.whl
Size 2.0 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
80be0b091f9eddc5aa5fbe89a20e9ca1504bb41d4964fbc6e9cf0616aa02fbaa
BLAKE2b-256 checksum
How to use checksums
3cdc1c2e4bb2c5a3ac70cf8539b8f5ac2c3d9cc9c74083eb431ee7bef221e79b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / rslab-0.28.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rslab-0.28.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ab18d70a078d15323f52e0b6c688bb999741264a7e82fa9cc31f184abc94357a
BLAKE2b-256 checksum
How to use checksums
1c87041f9491f0c3a188f23966f5f85b31fea73ecc6b162ba5cfbf3a92fd5b75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / rslab-0.28.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rslab-0.28.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.0 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
86541d2b0bee2af96f7063210076d1bcae72d7c4bbacd560b9b3265c5726e89f
BLAKE2b-256 checksum
How to use checksums
df2ea37096303cb488c9282049b6e588c6ce4052611a98397118678d47677442
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / rslab-0.28.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL rslab-0.28.1-cp39-abi3-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0ea1df82bd1852b63f83a6de23e50ccd7855e1cd8d4efb044b044ac06b7de8f7
BLAKE2b-256 checksum
How to use checksums
fcfa37000f5cf0a8208ddffe18196af53d36f206021e321983dc4d8d84de7bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / rslab-0.28.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL rslab-0.28.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.0 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5453dd51e96d927ef05b5c526ed71db72fe6b264b4af8753668d8ed1db944ba8
BLAKE2b-256 checksum
How to use checksums
cbae23611777a951556431d3cebe6255e741a5e332b788e3a16c9ffdd91d718e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page