Skip to main content

Sparse symmetric indefinite direct solver with certified inertia, in pure Rust.

Project description

feral-solver

Python bindings for feral, a pure-Rust sparse symmetric indefinite direct solver with certified inertia counts. Aimed at interior-point methods (the IPM in discopt is the primary consumer), but usable for any application that factors symmetric KKT-shaped systems.

Install

pip install feral-solver           # plain
pip install 'feral-solver[scipy]'  # with scipy.sparse adapters
uv add feral-solver                # via uv

Wheels are published for CPython 3.10+ on Linux x86_64/aarch64, macOS universal2, and Windows x86_64. abi3 means one wheel per platform/arch covers all supported Python minor versions.

Quickstart

import numpy as np
import feral

A = feral.CscMatrix.from_dense(np.array([
    [4.0, 1.0, 0.0],
    [1.0, 3.0, 2.0],
    [0.0, 2.0, 5.0],
]))

solver = feral.Solver()
status, inertia = solver.factor(A)
assert status == feral.FactorStatus.SUCCESS
print(inertia)                       # Inertia(n_pos=3, n_neg=0, n_zero=0)

b = np.array([1.0, 2.0, 3.0])
x = solver.solve(b)
print(np.allclose(A.symv(x), b))     # True

IPM use

The feral.ipm.KktSolver class wraps Solver with the Wächter–Biegler 2006 §3.1 perturbation-escalation loop. Symbolic analysis is cached; across an entire Newton run solver.symbolic_call_count stays at 1.

import feral
import feral.ipm

kkt_pattern = feral.CscMatrix.from_scipy(my_kkt)   # see scipy adapter
kkt = feral.ipm.KktSolver(
    kkt_pattern,
    expected_inertia=feral.Inertia(n_vars, n_equality_constraints),
)
for newton_iter in range(max_iter):
    report = kkt.factor(values_this_iter)          # auto-perturbs if needed
    if report.status != feral.FactorStatus.SUCCESS:
        break
    dx_aff, dx_corr = kkt.solve_pair(b_aff, b_corr)
    ...

See examples/discopt_ipm_kkt.py for an end-to-end Newton step against a small NLP.

Example notebooks

Runnable notebooks live in examples/notebooks/ (regenerate the .ipynb from _build_notebooks.py; execute with jupyter nbconvert --execute or open in Jupyter):

  • 01_basic_factor_solve — factor, certified inertia, solve, refine, reuse.
  • 02_multi_rhs_batchedbatched multi-RHS solve, motivated by a steady-state heat-conduction sweep, with a correctness check and a looped-vs-batched timing showing the per-RHS speedup (issue #57).
  • 03_kkt_saddle_inertia — indefinite KKT system with certified inertia.
  • 04_scipy_numpy_interopscipy.sparse round-trip vs spsolve.

scipy.sparse interop

import scipy.sparse as sp
import feral

A_scipy = sp.csc_matrix(...)
A = feral.from_scipy(A_scipy, symmetric="full")    # reads lower triangle
# ... factor, solve ...
A_back = feral.to_scipy(A)                          # round-trips to scipy

Building from source

Requires a stable Rust toolchain (1.75+) and Python 3.10+.

git clone https://github.com/jkitchin/feral.git
cd feral/python
pip install maturin
maturin develop --release    # builds and installs into current venv
pytest tests/

License

MIT, same as the underlying Rust crate.

Project details


Download files

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

Source Distribution

feral_solver-0.10.0.tar.gz (646.8 kB view details)

Uploaded Source

Built Distributions

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

feral_solver-0.10.0-cp310-abi3-win_amd64.whl (633.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

feral_solver-0.10.0-cp310-abi3-manylinux_2_28_aarch64.whl (666.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

feral_solver-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (743.8 kB view details)

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

feral_solver-0.10.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file feral_solver-0.10.0.tar.gz.

File metadata

  • Download URL: feral_solver-0.10.0.tar.gz
  • Upload date:
  • Size: 646.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for feral_solver-0.10.0.tar.gz
Algorithm Hash digest
SHA256 14de31ad6084ebc38e5c8427439e5d99fd582ea9e8fb81636b9607a9d9d881be
MD5 392fc93d49ec7e63d4807dbf124a5adb
BLAKE2b-256 4e7cf54ee4dd55be7be83e5455bd27637809e980e3ddaecd303c3462dce9a29f

See more details on using hashes here.

Provenance

The following attestation bundles were made for feral_solver-0.10.0.tar.gz:

Publisher: python-wheels.yml on jkitchin/feral

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

File details

Details for the file feral_solver-0.10.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for feral_solver-0.10.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0da6a23f9e228a59f7c6906f207d6518aae8b69ffa7bd6af5833d58fdbfe49ba
MD5 d1842404c0866e32f9b69fb7401b5881
BLAKE2b-256 3ff8c2d3f1e726e7d030c3e8a448aced83ffdeab6a8cd1499846989fe8149c4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for feral_solver-0.10.0-cp310-abi3-win_amd64.whl:

Publisher: python-wheels.yml on jkitchin/feral

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

File details

Details for the file feral_solver-0.10.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for feral_solver-0.10.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9505a7a5ee154a09c192ac56bb74449ea258bef57f626c26c22d99c02800456d
MD5 de3c29c62e523076572a76efa0085f34
BLAKE2b-256 12747927e64c1b4ee15a7b59b06800e76fb843b0f3206bc4edf521322fdeaf92

See more details on using hashes here.

Provenance

The following attestation bundles were made for feral_solver-0.10.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: python-wheels.yml on jkitchin/feral

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

File details

Details for the file feral_solver-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for feral_solver-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b5e908d6abd9e3053c782ad7684f6ec7692fe804ebbb46d98420689e515f9a0
MD5 2e00a79350e3334bf3c90bc1048fb5cc
BLAKE2b-256 59ef83bc64a9ce6b846f821c205f3306ef4f521a53e9e384850ad5e98fcb1583

See more details on using hashes here.

Provenance

The following attestation bundles were made for feral_solver-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-wheels.yml on jkitchin/feral

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

File details

Details for the file feral_solver-0.10.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for feral_solver-0.10.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6b6bee8c19687f73fe008d6070efb2f1d7e8764bb98637df49834929f080c342
MD5 b7c813de8427e4cc1418138cf8b63bdd
BLAKE2b-256 381b096e6a4988640f7ee8054bf7e46cf44a68ade48d7068a79ee264e712b6b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for feral_solver-0.10.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: python-wheels.yml on jkitchin/feral

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 Pingdom Monitoring Sentry Error logging StatusPage Status page