Chainable optics for JAX PyTrees
Project description
Refrax
Refrax is a tiny library implementing the optics functional pattern for JAX PyTrees.
Installation
Refrax can be installed using pip:
pip install refrax
Quick example
This example demonstrates the Mixin approach on an Equinox module, which adds .at to your class and simply returns refrax.Lens(self).
We define a dummy model with the mixin:
from refrax import OpticsMixin
import equinox as eqx
import jax
class Model(eqx.Module, OpticsMixin):
core: eqx.nn.Linear
head: eqx.nn.Linear
dropout: float
key1, key2 = jax.random.split(jax.random.key(0))
model = Model(
core=eqx.nn.Linear(in_features=5, out_features=5, key=key1),
head=eqx.nn.Linear(in_features=5, out_features=2, key=key2),
dropout=0.5
)
Then we can do updates using .at:
new_model = model.at.dropout.set(0.1)
new_model = model.at.select("core", "head").bias.apply(lambda b: b + 1.0)
new_model.core.bias
# [1. 1. 1. 1. 1.]
new_model.head.bias
# [1. 1.]
Documentation
Documentation is available here.
Related
The library uses Equinox (specifically eqx.tree_at) under the hood.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file refrax-0.0.1.tar.gz.
File metadata
- Download URL: refrax-0.0.1.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d66dc0c5a9f7b6614a610f3756ce39106c3018bbc9b981dc1c5314a26246cd
|
|
| MD5 |
9a6073dd90e78e61c6c3c86ff2994e2f
|
|
| BLAKE2b-256 |
452566a2c15646ffb300c610872111f5d637a6266a710a4b6dcc6e4a1b7fde93
|
Provenance
The following attestation bundles were made for refrax-0.0.1.tar.gz:
Publisher:
publish.yml on gvcallen/refrax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
refrax-0.0.1.tar.gz -
Subject digest:
f4d66dc0c5a9f7b6614a610f3756ce39106c3018bbc9b981dc1c5314a26246cd - Sigstore transparency entry: 1523496786
- Sigstore integration time:
-
Permalink:
gvcallen/refrax@19f47847abf828eaca157d5daed118b167bf94ef -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/gvcallen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19f47847abf828eaca157d5daed118b167bf94ef -
Trigger Event:
push
-
Statement type:
File details
Details for the file refrax-0.0.1-py3-none-any.whl.
File metadata
- Download URL: refrax-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80bcd3afe550526db997d4af6d2e6033cdcb8d827d8e3a2164cb0c41c514d7f2
|
|
| MD5 |
dd82b698bd890abe276dcf96270fd3ab
|
|
| BLAKE2b-256 |
ca99a48fae0dd075c34686a5a4ceec7d5b95c39dab88896373ed1bfbd33056dd
|
Provenance
The following attestation bundles were made for refrax-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on gvcallen/refrax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
refrax-0.0.1-py3-none-any.whl -
Subject digest:
80bcd3afe550526db997d4af6d2e6033cdcb8d827d8e3a2164cb0c41c514d7f2 - Sigstore transparency entry: 1523496795
- Sigstore integration time:
-
Permalink:
gvcallen/refrax@19f47847abf828eaca157d5daed118b167bf94ef -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/gvcallen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19f47847abf828eaca157d5daed118b167bf94ef -
Trigger Event:
push
-
Statement type: