squarem-JAXopt
JAX implementation of the SQUAREM accelerator for solving fixed-point equations, originally proposed by Du and Varadhan (2020).
The SQUAREM accelerator is implemented using JAXopt, enabling efficient automatic differentiation of the fixed-point equations via the implicit function theorem (see Blondel et al., 2022 for details).
Installation
pip install squarem-jaxopt
Usage
import jax
import jax.numpy as jnp
from jax import random
from jaxopt import FixedPointIteration, AndersonAcceleration
from squarem_jaxopt import SquaremAcceleration
# Increase precision to 64 bit
jax.config.update("jax_enable_x64", True)
N = 100_000
a = random.uniform(random.PRNGKey(111), (N, 1))
def fun(x: jax.Array) -> jax.Array:
y = (1 - a) + a * jnp.cos(x)
return y
initial_guess = jnp.zeros_like(a)
fxp_none = FixedPointIteration(fixed_point_fun=fun, verbose=False)
result_none = fxp_none.run(initial_guess)
fxp_anderson = AndersonAcceleration(fixed_point_fun=fun, verbose=False)
result_anderson = fxp_anderson.run(initial_guess)
fxp_squarem = SquaremAcceleration(fixed_point_fun=fun, verbose=False)
result_squarem = fxp_squarem.run(initial_guess)
print("\n" + "="*60)
print("ALGORITHM COMPARISON TABLE")
print("="*60)
print(f"{'Algorithm':<25} {'Iterations':<12} {'Func Evals':<12} {'Error':<12}")
print("-"*60)
print(f"{'FixedPointIteration':<25} {result_none.state.iter_num:<12} {result_none.state.num_fun_eval:<12} {result_none.state.error:<12.2e}")
print(f"{'AndersonAcceleration':<25} {result_anderson.state.iter_num:<12} {result_anderson.state.num_fun_eval:<12} {result_anderson.state.error:<12.2e}")
print(f"{'SquaremAcceleration':<25} {result_squarem.state.iter_num:<12} {result_squarem.state.num_fun_eval:<12} {result_squarem.state.error:<12.2e}")
print("="*60)
Metadata
Release files for squarem-jaxopt 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| squarem_jaxopt-0.1.4.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| squarem_jaxopt-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / squarem_jaxopt-0.1.4.tar.gz
| Download URL | squarem_jaxopt-0.1.4.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75f86e608d1f10e5e44c8852d78b4828ae7aacc946176c0157bfefda4c33ce11
|
|
BLAKE2b-256 checksum How to use checksums |
803456f439ff25c8ec319062e9f6622d8eabe76de70bdfd3e04cb88478e95033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.7
|
Release files / squarem_jaxopt-0.1.4-py3-none-any.whl
| Download URL | squarem_jaxopt-0.1.4-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3dfc1aa35f895fb8faf987ab3e0477bbf5fda782873de9eff0159d2873cde4f
|
|
BLAKE2b-256 checksum How to use checksums |
07d295cb53cf066c290663803dea384efb6bc34679a384f720f492b44716c094
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.7
|