Skip to main content

Linear solvers in JAX and Equinox.

Project description

Lineax

Lineax is a JAX library for linear solves and linear least squares. That is, Lineax provides routines that solve for $x$ in $Ax = b$. (Even when $A$ may be ill-posed or rectangular.)

Features include:

  • PyTree-valued matrices and vectors;
  • General linear operators for Jacobians, transposes, etc.;
  • Efficient linear least squares (e.g. QR solvers);
  • Numerically stable gradients through linear least squares;
  • Support for structured (e.g. symmetric) matrices;
  • Improved compilation times;
  • Improved runtime of some algorithms;
  • All the benefits of working with JAX: autodiff, autoparallism, GPU/TPU support etc.

Installation

pip install lineax

Requires Python 3.9+, JAX 0.4.11+, and Equinox 0.10.5+.

Documentation

Available at https://docs.kidger.site/lineax.

Quick examples

Lineax can solve a least squares problem with an explicit matrix operator:

import jax.random as jr
import lineax as lx

matrix_key, vector_key = jr.split(jr.PRNGKey(0))
matrix = jr.normal(matrix_key, (10, 8))
vector = jr.normal(vector_key, (10,))
operator = lx.MatrixLinearOperator(matrix)
solution = lx.linear_solve(operator, vector, solver=lx.QR())

or Lineax can solve a problem without ever materializing a matrix, as done in this quadratic solve:

import jax
import lineax as lx

key = jax.random.PRNGKey(0)
y = jax.random.normal(key, (10,))

def quadratic_fn(y, args):
  return jax.numpy.sum((y - 1)**2)

gradient_fn = jax.grad(quadratic_fn)
hessian = lx.JacobianLinearOperator(gradient_fn, y, tags=lx.positive_semidefinite_tag)
solver = lx.CG(rtol=1e-6, atol=1e-6)
out = lx.linear_solve(hessian, gradient_fn(y, args=None), solver)
minimum = y - out.value

Finally

See also: other libraries in the JAX ecosystem

Equinox: neural networks.

Optax: first-order gradient (SGD, Adam, ...) optimisers.

Diffrax: numerical differential equation solvers.

jaxtyping: type annotations for shape/dtype of arrays.

Eqxvision: computer vision models.

sympy2jax: SymPy<->JAX conversion; train symbolic expressions via gradient descent.

Disclaimer

This is not an official Google product.

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

lineax-0.0.1.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

lineax-0.0.1-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file lineax-0.0.1.tar.gz.

File metadata

  • Download URL: lineax-0.0.1.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for lineax-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4b73f0ccb3fffe67e73813b4b9324c3c302d381e3bbfa6e4e82864eb11516e47
MD5 2cbf8a5dea99f571b585db0e36628399
BLAKE2b-256 129a2d2f3163c5be401efc40cf2946a347c157962ea58b020dc4e20377fa5d9e

See more details on using hashes here.

File details

Details for the file lineax-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lineax-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 61.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for lineax-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5aef28e69bff50e42a28ba97f6e533f226b61357ab528e23b69eeaa27ce47100
MD5 f912d1813e82bba4419e9043d73fa497
BLAKE2b-256 4b8257f4c077314c745b040b585b108e68055b34ef5fc1460eb3d6662b1a8917

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