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

ldlt, lu and spsolve take a Settings object (or the same keywords directly), klu a KluSettings. By default the factor uses RSLAB's deterministic heuristic pick: the adaptive ordering plus an exact nested-dissection bakeoff on large systems, and at most 4 workers (the calibrated count after a one-time rslab.install_diagnose()). Keywords override the pick:

s = rslab.Settings(ordering="metis", threads=2, preconditioner=1e-4)
f = rslab.ldlt(A, settings=s)
f = rslab.lu(A, ordering="amd", pivot_u=0.5)        # the same, as keywords
print(s.to_dict())
Settings keyword default meaning
ordering heuristic pick "auto", "auto_race", "amd", "amf", "metis", "rcm"
nemin, relax, reorder 16, on, "hybrid_liu" supernode amalgamation and elimination-tree reordering
threads predictor, max 4 int (0 = all cores), "auto", "ambient"; the factor is bit-identical either way
preconditioner None static-pivot floor (e.g. 1e-4): never-fail, refine to solve
force_accept False accept tiny pivots in exact mode instead of failing
drop_tol None incomplete-factor threshold (ILU-style preconditioner)
method, memory "left_looking", "low" numeric schedule and factor emit strategy
pivot_u 0.1 threshold-pivoting tolerance of the LU path
scaling "one_pass" LDL^T equilibration: "inf_norm", "mc64", "auto", "identity"
blr, panel_nb off, 64 block-low-rank tolerance, dense panel width
scalar_gate, par_gemm, par_cdiv, use_gemm_schur calibrated kernel tuning knobs
interrupt None an rslab.Interrupt cancellation flag

KluSettings: pivot_tol (1e-3), row_scaling (on), btf (on), parallel (None = structural auto gate, True / False force), interrupt.

Settings a path ignores are reported under diagnostics()["warnings"].

Symbolic reuse

The analysis depends only on the sparsity pattern. Pay it once and factor each value set of a sweep on it:

sym = rslab.analyze(A, path="lu")                # LdltSymbolic / LuSymbolic / KluSymbolic
print(sym.factor_nnz, sym.estimate_memory()["factor_mb"])
for omega in frequencies:
    f = sym.factor((K + 1j * omega * C).data)    # same pattern, new values
    x = f.solve(b)

Krylov solvers

gmres, gmres_block, cocg and cocr run on any matrix, optionally preconditioned by any factor handle (an incomplete factor, or the factor of a nearby matrix):

M = rslab.lu(A, drop_tol=1e-3)                   # ILU-style preconditioner
x, converged, iters, res, stop = rslab.gmres(A, b, M, tol=1e-10)
r = rslab.gmres(A_next, b, M, recycle=M.recycle(8))   # reuse M, deflate across solves

Logging

rslab.set_log_level("info")                      # or the RLA_LOG environment variable
log = logging.getLogger("rslab")
rslab.set_log_sink(lambda level, msg: log.log(logging.getLevelName(level.upper()), msg))

API

The full reference, generated from the docstrings, is in docs/api.md (help(rslab.ldlt) etc. show the same text).

name 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 LU)
klu(A, **kw) -> Klu factor a circuit-shaped matrix (BTF + per-block Gilbert-Peierls LU)
analyze(A, path, **kw) the symbolic analysis alone; .factor(data) per value set
Settings, KluSettings, Interrupt configuration objects
gmres, gmres_block, cocg, cocr Krylov solvers, M= any factor handle
install_diagnose() one-time machine calibration
set_log_level, log_level, set_log_sink the core's logger

Factor handles share solve(b, refine=0, target=None, measure="normwise"), solve_many(B), gmres, gmres_block, cocg, cocr, recycle(k), diagnostics() and the attributes n, factor_nnz, n_perturbed, dtype; Ldlt adds inertia, Klu adds n_blocks, solve_transpose(b) and the numeric-only refactor(data).

Supported dtypes: float64, float32, complex128, complex64.

License

MIT.

Release files for rslab 0.32.0

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.32.0
File Size Uploaded
rslab-0.32.0.tar.gz 1.2 MB Details

Built distributions (wheels)

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

Total release size: 12.6 MB

Release files / rslab-0.32.0.tar.gz

Download URL rslab-0.32.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
9f81c78b6ee7e1dd75d170f61c5dad2f9c5b4e5c28808e28a1329e797158543f
BLAKE2b-256 checksum
How to use checksums
50bde635505a184c323473e07563c775bfa4ff3764544bb463e5f10924d51c42
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 Sep 6, 2026.

Transparency log

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

Download URL rslab-0.32.0-cp39-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c72231c0712c998dfd2a991801a9a24c2e69bf08da6f6cc26ac4f9b5f94f3a81
BLAKE2b-256 checksum
How to use checksums
82cf306d44e44b195adf125265d1dbc37ca282bcf5ca0bb3acf1dc2bb9676026
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 Sep 6, 2026.

Transparency log

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

Download URL rslab-0.32.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
103e0c7ba3ccf90d20bf5c816ed55d1a9243d30467aba66505fa07c3ebb65df8
BLAKE2b-256 checksum
How to use checksums
55c534425cf9e39c97bcf5e3feb03f83e7d4da0258eb391cd4dc34d3aa670ca5
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 Sep 6, 2026.

Transparency log

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

Download URL rslab-0.32.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.3 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2c0b8de3e4b3e4f8a78167a2a3647bdf0cc38c8688f8c9c1bca053b49ccfa560
BLAKE2b-256 checksum
How to use checksums
9bdd58486398342fbe6eb77dc2c1f2064f88076fbc88a9f8bf6e1ac79216672b
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 Sep 6, 2026.

Transparency log

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

Download URL rslab-0.32.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5eef2b700fcced3f7579a39b6b1af11e83e41f920e8882e8beb1d571532e6bad
BLAKE2b-256 checksum
How to use checksums
a1e208f5383663966b469077c372649d431314d2713d47208c88552ebdcd8978
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 Sep 6, 2026.

Transparency log

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

Download URL rslab-0.32.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1ee0a8220fc1589605fa2bc0e89eb9b340787c1b819da3d515b9f0b0757660f3
BLAKE2b-256 checksum
How to use checksums
01861d3bf679c66771c52809d449c86c9dd5bd6d4d97b5bcbcdc7d4535fbec08
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 Sep 6, 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