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 dynamically linked to the SuiteSparse C++ library. The easiest way to install is as follows:

conda install pybind11 suitesparse
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, having gcc and g++ available in your path should be sufficient to be able to build the library from source.

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, after activating your conda environment:

set DISTUTILS_USE_SDK=1
conda install pybind11 suitesparse
pip install klujax

License & Credits

© Floris Laporte 2022, LGPL-2.1

This library was partly based on:

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.1.4.tar.gz (16.4 kB view details)

Uploaded Source

Built Distributions

klujax-0.1.4-cp311-cp311-win_amd64.whl (64.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

klujax-0.1.4-cp311-cp311-manylinux2014_x86_64.whl (574.0 kB view details)

Uploaded CPython 3.11

klujax-0.1.4-cp310-cp310-win_amd64.whl (64.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

klujax-0.1.4-cp310-cp310-manylinux2014_x86_64.whl (574.0 kB view details)

Uploaded CPython 3.10

klujax-0.1.4-cp39-cp39-win_amd64.whl (65.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

klujax-0.1.4-cp39-cp39-manylinux2014_x86_64.whl (574.5 kB view details)

Uploaded CPython 3.9

klujax-0.1.4-cp38-cp38-win_amd64.whl (64.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

klujax-0.1.4-cp38-cp38-manylinux2014_x86_64.whl (574.0 kB view details)

Uploaded CPython 3.8

File details

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

File metadata

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

File hashes

Hashes for klujax-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2f1fa1df162febdca5d44b857e37e1fbf5cf8f154c45cae2d3080d9dc200228e
MD5 bef8eff89ed32cdbc1749364df24522a
BLAKE2b-256 d7708324e793a848563ba8c52874b0295537ef2941e5f4f5bbc0571bde6288d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.1.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 64.8 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.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 abab04797b79e3f1e3c5ebfdb188963048bebb9c8b442a7271e92adec4770e87
MD5 da5d9fe3986762b5411da6add93ed7a7
BLAKE2b-256 62069698c8b840fe68d878c7e83e63e150acfceac0ece0be659b61396c48803d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klujax-0.1.4-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9eb1c5e2ce2cef0abb796247eeadabe0875f8c2a0a76d1cd496468d87d17e990
MD5 7b0fc5e5bdc7ad2cb79a448f10593a4f
BLAKE2b-256 fe5774aa152e0002a3b4ae42b335ffaba5be5e23c846822de3378843257058e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 64.8 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.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3e19bdc45a39ca6e0cc0ec6113e39509a31b2ec40c3543b33f9ed645ad2448d1
MD5 367e8936dbf58de4cf931d51c0de4ac3
BLAKE2b-256 45b1bec331c830d91cd13a52aae3cb1da1e92d38936ef423b563f4e5fe47736b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klujax-0.1.4-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 407924b1c7bc39bd0e13778f77ce7555519cdb8443856bbd13ff5e38144e6ed2
MD5 fd236ae8de63f5304d4ec8925cb8a686
BLAKE2b-256 3cfae85a5ab203967dd87fcbbc152e61f2b2c99974ce3df290e914af3efd6684

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 65.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.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c1ffaa22623a540c16ef8441e30719005678de80ee212b729fceec04757aad70
MD5 9359732a369f5d92c9cbd8528ab7863d
BLAKE2b-256 3fa2a5cc37f27af9306474c92bb6d5f9701564a9127312e7bbef7b3212a182d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klujax-0.1.4-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ca0b74a258e6a7a367cfb54a9d5654930cef96a6e0013d606738e948b12ba1b
MD5 a36761d016671fceb6c8e664330dd31d
BLAKE2b-256 007fc45fd7f14b973908f8dd5ee729e9d156439a8e3695428c9815d79f29c905

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klujax-0.1.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 64.6 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.1.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cb8cca4e17fc2c2c7438acc89a888bf564192a1b35b486abf42e793154fe08ea
MD5 3621ef65c4b5cd80bb614a4ec00a118a
BLAKE2b-256 acc19a423c6b873c5c0b476421ef102fda34b43897423c9dd19757fc5772f28b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klujax-0.1.4-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ef5da1131a95d8d8c4561143d7a7a746a1f221e7cea4917c1bced7478c232d5
MD5 f21ca56cbd19eb64fdcf7c0a0f2ba17e
BLAKE2b-256 e02c424e760e7882dbf250b8ee662a07ab5c2b7b97bf870056bc8964d70147ad

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