Skip to main content

Chainable optics for JAX PyTrees

Project description

Refrax

Refrax is a small library implementing the optics functional pattern for JAX PyTrees.

It focuses on elegant syntax and deep conditional chains as opposed to strict static typing.

Installation

Refrax can be installed using pip:

pip install refrax

Quick example

import equinox as eqx
import jax

class Model(eqx.Module):
    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 focus:

from refrax import focus

model = focus(model).dropout.set(0.1)
model = focus(model).select("core", "head").bias.apply(lambda b: b + 1.0)

model.dropout
# 0.1

model.core.bias
# [0.646, 0.860, 0.670 , 1.277 , 0.727]

model.head.bias
# [1.634, 1.877]

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

refrax-0.0.5.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refrax-0.0.5-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file refrax-0.0.5.tar.gz.

File metadata

  • Download URL: refrax-0.0.5.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for refrax-0.0.5.tar.gz
Algorithm Hash digest
SHA256 c833215045e4c950f050d263416385e7f21e6c8bf830281d8ccf4962acf3d1f1
MD5 9df9e822679f17b01ae2036ec7f5774b
BLAKE2b-256 8450234585452d79595f781a0f0a3fe160b30845f4521613a1ffbd129a667e99

See more details on using hashes here.

Provenance

The following attestation bundles were made for refrax-0.0.5.tar.gz:

Publisher: publish.yml on gvcallen/refrax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file refrax-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: refrax-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for refrax-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3ae81dbea8c10d66ab456ec705fa0c6f30728578fb1542efb5e6190b59845542
MD5 8e8b4359d35facc30bfcfbf2233a5739
BLAKE2b-256 6a54de909d5e10ce3ca0344e031d000901c2f3765993f54e651350499904ea3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for refrax-0.0.5-py3-none-any.whl:

Publisher: publish.yml on gvcallen/refrax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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