Skip to main content

a KLU solver for JAX

Project description

KLUJAX

version: 0.3.0

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 from BCOO or COO to Ai, 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:

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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

klujax-0.3.0-cp313-cp313-win_amd64.whl (136.7 kB view details)

Uploaded CPython 3.13 Windows x86-64

klujax-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

klujax-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (198.0 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

klujax-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl (249.7 kB view details)

Uploaded CPython 3.13 macOS 10.13+ x86-64

klujax-0.3.0-cp312-cp312-win_amd64.whl (136.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

klujax-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

klujax-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (197.8 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

klujax-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl (249.7 kB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

klujax-0.3.0-cp311-cp311-win_amd64.whl (136.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

klujax-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

klujax-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (199.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

klujax-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (248.8 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

klujax-0.3.0-cp310-cp310-win_amd64.whl (135.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

klujax-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

klujax-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (197.7 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

klujax-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (247.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

Details for the file klujax-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: klujax-0.3.0-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

Hashes for klujax-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ccbf4a672d2335dff931398b8b7b0fd42b6ac0de49b7a69b63e7972d0547583d
MD5 628092e769c392c824a0f38e41066e4d
BLAKE2b-256 ca572483825a26e6f4ea3ce5392f93549fbcea8b696018b2707c5b77ff23d46f

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ad9692b827d57b1c48d71054e7c8e1727681e5b2dd6d96717314ba49ca9b5d5
MD5 dc9e754241ed8e5c2900fda831a3b5f0
BLAKE2b-256 ba817ed91321ef5811235e3ee334ecb02b84a177dcbbf7b622e13b6cae532e92

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb2ce5cd683db2cd319232f19f6066553b0b4226e3cdfdcb8d6c651289e691ae
MD5 c8840491be777fc0d3e0efa65970a394
BLAKE2b-256 9964420782e037476149c8e889611b281e913382fe086e31f7c8fc5847bb15cb

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3fe115cc952b9a615a477cbc9e24c2ec55523bfe7dcc64d8d595473c300a24cf
MD5 78623913a67773e6eb0768c977b835d3
BLAKE2b-256 a3ca181adaf08efc1b8d6f17a8b51e85db1d129b108f9edd8ea0b6d0cb2e31bb

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: klujax-0.3.0-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

Hashes for klujax-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 858e2776d00090286123b0f4d0cd054ce9f17fca6166896c5b5c1629e9e6b82b
MD5 b5ec92cbb38f3660c421e126c4ddfe74
BLAKE2b-256 b9ab248b2746db7be23688b284c91cc1bb59b515f3c5bd516dd6c088a0ce4d6e

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82e85cb677e275fae7b789b5c134dacbf30aa5171f2c6e028ba07140621011e3
MD5 e58a4e5c81994b7df4639b33ed68e51d
BLAKE2b-256 4718ec0e5e896be65fd5a216af023a7177d6e1854d99fdaf179f7b7c96a016fd

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 697dbc4d9e7d640b8c58392cdd9ced20238914ee4ad4fc12eb4edb31751bdf65
MD5 c1be0c13b8062722a30e146f2b62ce1f
BLAKE2b-256 0916f31e68bd142f5148d32adea8b21ec5745d445d05e8cbf573bacff48882d8

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f1c4bf0e9521cf880f82ecba6a90301b07b0d3f299fc59f582a03853324a4f86
MD5 fe651ef3af3f35908b6606762b366ce6
BLAKE2b-256 fb133c0866a174f5bd68cf2f5e9af81fc5ba26865b917c72acc24b5483f0165c

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: klujax-0.3.0-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

Hashes for klujax-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0af62ed90fa639c12823bffcb6cfa9d21754f53f1d1784740250190aa8286b32
MD5 a1d60de776b9f9374ffd528b8d3455b2
BLAKE2b-256 f1e81232d7a36b2a9c728412ca97c538b722d3467182ac5dbf85418c411a9ac7

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c64af22347feb0708f14d90b72826740b4563659a432399da949dae1ac76a411
MD5 88946f8b2f2defb7dd39b27c7b34404e
BLAKE2b-256 a2c48b842cbdd65b004aebdbffd1b1eac37e022564150c2ae83fd8b9823546ca

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 366d2c0605ff932b27dc6897fbe15872d846325933af22d451055e76eafafe8a
MD5 2e319dbb0192de56686ea38b1657654d
BLAKE2b-256 3abdc3187de1da8a22100a095962d83a1343a040565b94fd2362752054dd59b4

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0cdedc4e292c6af3b532282b6ef4dc44c3bf65e0ab034d5d184615893a80c419
MD5 b6ebb990eae2b68949d956f1a46ffbd5
BLAKE2b-256 0056554f78ff5cd57815141ad4da9342b8bfba1ae38a845a2285636c7fe62d36

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: klujax-0.3.0-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

Hashes for klujax-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9a984bece73666dcb8a3e4e0ebd2e06cfefff6e1d9969609974041eed3ef0d8f
MD5 46d7eea9d0056dc8931643694c52a0c7
BLAKE2b-256 749e3490a04127cd85c35a050ae1d8a1b491340f0a9d238f40ea114c3d62cada

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c31cbfd911775cfc45de4683795671f034c33183f8d6c90b40bda707c689bd6b
MD5 e9cc02ca1a888555c418e82f9c28b8f8
BLAKE2b-256 3600cfc96ed0cd521998aac85e07feb19997a70f3ff1fdece5b88347c50d4711

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2595a8266ee1cb9516b7e86baf188042cbd5153748c5c8edbdf02c91648d84e1
MD5 673a3629f4b96a7c4f7d2fd51be45ce7
BLAKE2b-256 6dbe9cf0f94972f2a19c548c3e837e10cd025c30a2e6a4601eacc23773088860

See more details on using hashes here.

File details

Details for the file klujax-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c7b7d57310cf49623c9d35e8aa8e415a924f9d858a969b33d057b571d8ecd3ce
MD5 628909b855121ac658ca9027c977640b
BLAKE2b-256 d1f9f4c36ee6f4e48f25639433cc0708dd8a6fdd5f9940af87a8dd5f1c117fc2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page