a KLU solver for JAX
Project description
KLUJAX
version: 0.3.1
A sparse linear solver for JAX based on the efficient KLU algorithm.
CPU & float64
This library is a wrapper around the SuiteSparse KLU algorithms. This means the algorithm is only implemented for C-arrays and hence is only available for CPU arrays with double precision, i.e. float64 or complex128.
Note that float32
/complex64
arrays will be cast to float64
/complex128
!
Usage
The klujax
library provides a single function solve(Ai, Aj, Ax, b)
, which solves for x
in
the sparse linear system Ax=b
, where A
is explicitly given in COO-format (Ai
, Aj
, Ax
).
Supported shapes (?
suffix means optional):
Ai
:(n_nz,)
Aj
:(n_nz,)
Ax
:(n_lhs?, n_nz)
b
:(n_lhs?, n_col, n_rhs?)
A
(represented by (Ai
,Aj
,Ax
)): (n_lhs?
,n_col
,n_col
)
Additional dimensions can be added with jax.vmap
(alternatively any higher dimensional
problem can be reduced to the one above by properly transposing and reshaping Ax
and b
).
NOTE: JAX now has an experimental sparse library (
jax.experimental.sparse
). Using this natively in KLUJAX is not yet supported (but converting fromBCOO
orCOO
toAi
,Aj
,Ax
is trivial).
Basic Example
Script:
import klujax
import jax.numpy as jnp
b = jnp.array([8, 45, -3, 3, 19])
A_dense = jnp.array(
[
[2, 3, 0, 0, 0],
[3, 0, 4, 0, 6],
[0, -1, -3, 2, 0],
[0, 0, 1, 0, 0],
[0, 4, 2, 0, 1],
]
)
Ai, Aj = jnp.where(jnp.abs(A_dense) > 0)
Ax = A_dense[Ai, Aj]
result_ref = jnp.linalg.inv(A_dense) @ b
result = klujax.solve(Ai, Aj, Ax, b)
print(jnp.abs(result - result_ref) < 1e-12)
print(result)
Output:
[ True True True True True]
[1. 2. 3. 4. 5.]
Installation
The library is statically linked to the SuiteSparse C++ library. It can be installed on most platforms as follows:
pip install klujax
There exist pre-built wheels for Linux and Windows (python 3.8+). If no compatible wheel is found, however, pip will attempt to install the library from source... make sure you have the necessary build dependencies installed (see Installing from Source)
Installing from Source
NOTE: Installing from source should only be necessary when developing the library. If you as the user experience an install from source please create an issue.
Before installing, clone the build dependencies:
git clone --depth 1 --branch v7.2.0 https://github.com/DrTimothyAldenDavis/SuiteSparse suitesparse
git clone --depth 1 --branch main https://github.com/openxla/xla xla
git clone --depth 1 --branch stable https://github.com/pybind/pybind11 pybind11
Linux
On linux, you'll need gcc
and g++
, then inside the repo:
pip install .
MacOs
On MacOS, you'll need clang
, then inside the repo:
pip install .
Windows
On Windows, installing from source is a bit more involved as typically the build dependencies are not installed. To install those, download Visual Studio Community 2017 from here. During installation, go to Workloads and select the following workloads:
- Desktop development with C++
- Python development
Then go to Individual Components and select the following additional items:
- C++/CLI support
- VC++ 2015.3 v14.00 (v140) toolset for desktop
Then, download and install Microsoft Visual C++ Redistributable from here.
After these installation steps, run the following commands inside a x64 Native Tools Command Prompt for VS 2017:
set DISTUTILS_USE_SDK=1
pip install .
License & Credits
© Floris Laporte 2022, LGPL-2.1
This library was partly based on:
- torch_sparse_solve, LGPL-2.1
- SuiteSparse, LGPL-2.1
- kagami-c/PyKLU, LGPL-2.1
- scipy.sparse, BSD-3
This library vendors an unmodified version of the SuiteSparse libraries in its source (.tar.gz) distribution to allow for static linking. This is in accordance with their LGPL licence.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file klujax-0.3.1-cp313-cp313-win_amd64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 136.7 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 600ff885a4518c34b6a180679a1713cfc3228c0c76b9f4be2b9317b7349c884d |
|
MD5 | 72df0152c80a6cbbcf392450e0e6b3ec |
|
BLAKE2b-256 | a845bc011099a47bc6b68869e13dec63173dd752fcdb4547d978f9528a066ab1 |
File details
Details for the file klujax-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c47c7fd919e4b39f9dd4ef4e7ead9db0bcc0096174364869218004be2f1cba |
|
MD5 | d30da002d31b25979f197475662cded4 |
|
BLAKE2b-256 | c01a25ecea5b2d906212ec9da5af793c767d11b41fb204d73dbd2ff150493246 |
File details
Details for the file klujax-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 198.0 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66b00bce789c7ccbf26f9d40c0ca0c395af073dc204e84b76331cdcb120a6c5e |
|
MD5 | 739a4bf1133ee77b298c97a42e6575fb |
|
BLAKE2b-256 | 2110931419abf96c4b4bc6d39e7fb9f3baa50116bfdb0bae743f2cfb4c0f59f1 |
File details
Details for the file klujax-0.3.1-cp313-cp313-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp313-cp313-macosx_10_13_x86_64.whl
- Upload date:
- Size: 249.8 kB
- Tags: CPython 3.13, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ddaf44725d4a987ae0542ce02249b19ef509192513045e1b1fe8410c6a2257c |
|
MD5 | 3c5c7d35029b93d0b0f1a7c9101c4597 |
|
BLAKE2b-256 | 4378d05910dfaff9f1ed55ac74405ed6cb637d73d884fef5b3fc2624f6d5b17a |
File details
Details for the file klujax-0.3.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 136.7 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e73982999b51e889bf85cf8fb83621b304c5d90ee6b688f306f45e441dc11e |
|
MD5 | 29bc60240be785d101ef4e6337940fa8 |
|
BLAKE2b-256 | feb7e954c1d41dd6cceb2698721b8e8c1bd943db49b93545ec0ab343ad68bc68 |
File details
Details for the file klujax-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ce7278e8532dee03cf4aedb4bb56b5115c4d3fb68b80cadcdfba65efeb6fcf9 |
|
MD5 | 43a73aeedcc480ef0e11050c28d9f83a |
|
BLAKE2b-256 | b7d88a57b64675042d5f381faf08e9ea67bde5ba0a290ca6e70320294d493c57 |
File details
Details for the file klujax-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 197.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37d8cf9fe5a039a8488daed2a4d2defc0cb0fda4efba1756644018cdcc612c5e |
|
MD5 | 6e54af88e33db91b60b8c88225dd3b83 |
|
BLAKE2b-256 | f26c540badf058e3e6da21329061c3e64d05d205989fa8d4920cd691da93ca53 |
File details
Details for the file klujax-0.3.1-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 249.7 kB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca69310649582dfe50c7fb5c0b05aba309b69a7a9e1529e7ddb069817bd9e99 |
|
MD5 | e44a0a9cbfa1261ccfbf6601b44deea7 |
|
BLAKE2b-256 | 53baae6f8bb4d50c86252e0afcc75d22edd97641ce0364e43c8870a495b6a3b0 |
File details
Details for the file klujax-0.3.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 136.5 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a6f7bf325f013bbd27ff942e5dfeca2a0114d8f8a17f67279bd360b0e18d0f |
|
MD5 | 3878abce2bd5144c08c0493779ea9d45 |
|
BLAKE2b-256 | 986f66e960c64f052c8340a9008ae4c1ea287bf840fef10759a6f1d11a8d1a8e |
File details
Details for the file klujax-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d5bd1c877eed99c03115d766e94aa1691a020f5aa49c181d2493a76dceb3fca |
|
MD5 | 9a6a0a90181ffaa8b39750f039b66f19 |
|
BLAKE2b-256 | 6595f3350268b7e302ff67e2ecb50a7d43b0113f453c096facce74d87451f588 |
File details
Details for the file klujax-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 199.2 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8629a7f0b84a25519a71d9e92c937afd4db99d6947a69f3ad1810408f87474e |
|
MD5 | ba47133ceee7bc445551fdbbcd1c1e25 |
|
BLAKE2b-256 | 6c39efa1e4944d1d1e6d07eb48b94aa9640232ca263b7c7e1306ffb868fa4e5c |
File details
Details for the file klujax-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 248.8 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aba8375f837b7b33db894908100aa78c31bb6e988de7bc821908bd9c2f532143 |
|
MD5 | 90fb97b781d3b7958921576aaf75fcd7 |
|
BLAKE2b-256 | 33c683d2d80aee796a1d2a5d5517a7342378a7a8371cd5054b2e5e826e7ecfeb |
File details
Details for the file klujax-0.3.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 135.1 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5860f715596548d582ea2ff2604ca264c8ac24427a07736d3f23c333e9884ae8 |
|
MD5 | 49b731fdd45582875435d755fbb2ced1 |
|
BLAKE2b-256 | bbdb2cbe8f008ed098282f5130f7157f8a80a178faa90f86e521c1a5cbbca4fe |
File details
Details for the file klujax-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a458a2e12075e6619a39d7ef6f8ac9cf40508d807e941492554f5faad86ff64e |
|
MD5 | 5b77a3faeccfc4117a354758a5017c13 |
|
BLAKE2b-256 | b49d288a40ce947c90307bd00819e20b769d092666f74e4d549cac25989cc27c |
File details
Details for the file klujax-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 197.8 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88fab1d61f5f00af2f2a11a42d042cd73c5b8adf974a3aa68dc9ed5355395860 |
|
MD5 | 00cd66212dbf4f4677674ed7fd82ec3e |
|
BLAKE2b-256 | f935dd2df0f3e4bf39f53ca048cbfaa29a8671a85bde32d6d5bfb82a170e8b3f |
File details
Details for the file klujax-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: klujax-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 247.4 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f68dc3cdf94e85b8cf0d7be2bf16bad2c5a0c7f0ffac14a662fc1ed3b594f6 |
|
MD5 | 08716e623b0b269354a3c06c44eb3971 |
|
BLAKE2b-256 | 8b31eb8c16f90e0b6fb9363489e4b9fd1923f6a80522848c1b5a24d0c3cb3876 |