Skip to main content

rslab (Python bindings)

NumPy/SciPy bindings for RSLAB, a pure-Rust sparse direct solver and preconditioner: complex/real symmetric LDLᵀ (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ᵀ or LU path
ldlt(A, **kw) -> Ldlt factor a real/complex symmetric matrix (Bunch-Kaufman LDLᵀ)
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) solve one RHS, optional iterative-refinement steps against the original A
solve_many(B) solve n × nrhs RHS in one batched pass
solve_transpose(b) solve Aᵀ y = b on the same factors (plain transpose, not conjugate)
refactor(data) 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) GMRES with this factor as preconditioner
gmres_block(B, tol=1e-8, maxit=400, restart=None, x0=None) block GMRES for multiple RHS
recycle(k) a Recycle workspace holding up to k deflation vectors across gmres calls
n, factor_nnz, n_perturbed, dtype dimension, stored factor entries, perturbed pivots (always 0 for Klu), NumPy dtype name
inertia (n_pos, n_neg, n_zero) eigenvalue counts from LDLᵀ
n_blocks number of BTF diagonal blocks

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

License

MIT.

Download files

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

Source Distribution

rslab-0.27.0.tar.gz (4.8 MB view details)

Uploaded Source

Built Distributions

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

rslab-0.27.0-cp39-abi3-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

rslab-0.27.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

rslab-0.27.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

rslab-0.27.0-cp39-abi3-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

rslab-0.27.0-cp39-abi3-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file rslab-0.27.0.tar.gz.

File metadata

  • Download URL: rslab-0.27.0.tar.gz
  • Upload date:
  • Size: 4.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rslab-0.27.0.tar.gz
Algorithm Hash digest
SHA256 aac7032c1c8d196ce4ec12506a8940d8e935d0eb8ec2da24f21276b631a5432e
MD5 22bdd9642633c10b4a57f361644b8deb
BLAKE2b-256 d683cb1db24d8aa51d9594f83cd8824bf746b1ebfaf6672d8446eb37031c49ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0.tar.gz:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rslab-0.27.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rslab-0.27.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rslab-0.27.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c24ab8187f8163748f735365ffa95ece8547daaf96b8381d9405ac32732d5df4
MD5 ae18581e2442f075e4c50b78aab67929
BLAKE2b-256 10c56af7fe120565ad7b5c47b040199813f0656a98a44651c6c634e65aa8cc2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0-cp39-abi3-win_amd64.whl:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rslab-0.27.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rslab-0.27.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 620510fe865f9ccbe3b7c039ada0e44b300554aa71107688b06b7aa557b8e9fc
MD5 136003fa5c45900cc1c07ed9e9d78db1
BLAKE2b-256 02a6e633110303343917a0b7cdc85ae9f0eb083099224d567bdbe6a0869417e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rslab-0.27.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rslab-0.27.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eaabfb3b15bbb3823e84e133c86722b07de8a2d287b2d65c5b94aafe62230a1c
MD5 81f14f5cdf99364993de11b7c8b08511
BLAKE2b-256 536be9d759612b27ee4fba13e3d0d872153a049b0dfbdd5e5172b05f54d813c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rslab-0.27.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rslab-0.27.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd0bc9069ac99901731d8e611292a9f90feaa81dc7b14a74e820a0ee4086c45a
MD5 db25b17991fd516f52225b0d87b28f19
BLAKE2b-256 750e45ed29094f5da80d5992fadbc7f5f36c856815aa1dea01999ba66c106d94

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rslab-0.27.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rslab-0.27.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5abb21a0c9e9f18a98da0f5808512c37fba822f610034d8019af9e87d1abdec1
MD5 23689aad66435c2d5e36b25958f63212
BLAKE2b-256 93b767e8f85e946300ebd0f54660cefef77366e4feca93f544c94b0b90fcc898

See more details on using hashes here.

Provenance

The following attestation bundles were made for rslab-0.27.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on milanofthe/rslab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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