Skip to main content

a KLU solver for JAX

Project description

KLUJAX

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 this will be enforced at import of klujax!

Usage

The klujax library provides a single function solve(A, b), which solves for x in the linear system Ax=b A is a sparse tensor in COO-format with shape mxm and x and b have shape mxn. Note that JAX does not have a native sparse matrix representation and hence A should be represented as a tuple of two index arrays and a value array: (Ai, Aj, Ax).

import jax.numpy as jnp
from klujax import solve

b = jnp.array([8, 45, -3, 3, 19], dtype=jnp.float64)
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]], dtype=jnp.float64)
Ai, Aj = jnp.where(jnp.abs(A_dense) > 0)
Ax = A_dense[Ai, Aj]

result_ref = jnp.linalg.inv(A_dense)@b
result = solve(Ai, Aj, Ax, b)

print(jnp.abs(result - result_ref) < 1e-12)
print(result)
[ 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.

Linux

On linux, you'll need gcc and g++. Then just do a normal pip install:

pip install klujax

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 klujax

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 Distribution

klujax-0.2.0.tar.gz (155.9 kB view details)

Uploaded Source

Built Distributions

klujax-0.2.0-cp311-cp311-win_amd64.whl (104.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

klujax-0.2.0-cp311-cp311-manylinux2014_x86_64.whl (695.2 kB view details)

Uploaded CPython 3.11

klujax-0.2.0-cp310-cp310-win_amd64.whl (104.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

klujax-0.2.0-cp310-cp310-manylinux2014_x86_64.whl (695.2 kB view details)

Uploaded CPython 3.10

klujax-0.2.0-cp39-cp39-win_amd64.whl (104.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

klujax-0.2.0-cp39-cp39-manylinux2014_x86_64.whl (695.5 kB view details)

Uploaded CPython 3.9

klujax-0.2.0-cp38-cp38-win_amd64.whl (104.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

klujax-0.2.0-cp38-cp38-manylinux2014_x86_64.whl (695.0 kB view details)

Uploaded CPython 3.8

File details

Details for the file klujax-0.2.0.tar.gz.

File metadata

  • Download URL: klujax-0.2.0.tar.gz
  • Upload date:
  • Size: 155.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klujax-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0faa4b343756d3be2eeffd19d9ff6b25788ef8646fd1938422cc948291de1aae
MD5 bc5ce9f2c23ab0fff11f9099269fece0
BLAKE2b-256 a55010d36cb6e80b9dd392492af925d56b8fc14fe9c02b3cb5975845e96708c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 104.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klujax-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c7f2552c9a38219f0beb2c8abe38fa68bf2c8c4db88d4d8026b651f3a78f18e1
MD5 2e4288e80f1f396157a590bb9b08aefe
BLAKE2b-256 754cbeb99da27a62dd1c57311ecde313cb16ab112dd966daa3d138da723214f8

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.2.0-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d74338e11109d290ce1332b0148e657b7b2f84ea7f10749991663b0ae990ce40
MD5 65f4c561cd78608b3d41a8dcc782b29f
BLAKE2b-256 f78c4e24faadede57f3a33519b5bb631bfe0354d4fe7ee50f36df20d415462c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 104.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klujax-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 db0242e933bb0508d38bc8f77e27521d199148a0e99aadc526bb1bf1c1ba2b6a
MD5 e4d26c7ee4bff3c747631a512b78ce83
BLAKE2b-256 795780d8ce411c82771014bd8b1cfd38d5f3f34d44a2e320911c1343db92efef

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.2.0-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7ea156f5f1bab0885a437b156d0b7b23e972f534772a17bc90950b9638b6b73
MD5 aefc2610f04a582048022968b65e01b2
BLAKE2b-256 761f5d2af86a1cb282d424199ae005d2d9f0378ef6384850463f1bc5b96c7038

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: klujax-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 104.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klujax-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1557d544d18b6a6abe8d3ec642f6dd7a1250cc837e70011ea841fd02c706f52a
MD5 48fa45b23f67d8d6c8730335b6b96dc1
BLAKE2b-256 3071b24b1495484dc398baef7d88b8c7ce5464251b92e3bc47197815675bf4c7

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.2.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9612e7c19d59c9e7ec339e64e4f074194a3eecb95e51f37fa412832d91774b6c
MD5 f8eb596d5b67c8c5b0d903471c923477
BLAKE2b-256 af2b2018a3dcf17108db6fe01bea6670477d47c3fd1f04bc2b92cb1d1315d542

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: klujax-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 104.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klujax-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 360c0567d1d67723bfecfd33fec5b5ee68e9f904168bff1653932b19f3a0a760
MD5 cc753e90603fdf4cbe940b9511894186
BLAKE2b-256 193a7a805167a91278ef4436317c3caef6b9b6cef8fcd1048e0019018ec373a4

See more details on using hashes here.

File details

Details for the file klujax-0.2.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for klujax-0.2.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa24cc9aa44dff9785b710e10ad3f39f46ab7c1e48d222383e108afb53e019dd
MD5 3f221d8b623efbb73222a93cbbaf76fa
BLAKE2b-256 a8909a917f6b7ad87b49f373c4bf8b84df0acfc9d6b27743c37d19a0f8852a3a

See more details on using hashes here.

Supported by

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