Skip to main content

jaxctx

JAX Context for memoizationg collections of parameters, and handling sequences of random keys. Based loosely on things like haiku, and flax, but not deep learning specific. No support for lifting things like scan, etc. You must build these things on top of this if you want them.

Additional support added for probabilistic parameterisations based on priors.

Packed constrained parameters

New models can combine all prior-constrained optimisation variables into one unconstrained parameter leaf. The pack uses one base dtype and applies the real-to-unit transform once to the complete vector before passing static slices to the individual priors.

import jax.numpy as jnp
import tensorflow_probability.substrates.jax as tfp

from jaxctx import transform
from jaxctx.priors import ParameterPack, Prior

tfpd = tfp.distributions

parameters = ParameterPack(
    [
        Prior(tfpd.Normal(0., 1.), name="location"),
        Prior(tfpd.Uniform(jnp.zeros(2), jnp.ones(2)), name="weights"),
    ],
    name="model",
)


def model():
    location, weights = parameters.parameter()
    return location, weights


transformed_model = transform(model, base_dtype=jnp.float32)

The trainable collection contains only params["model"], with shape (3,). The derived unit collection contains U["model"], while physical values and log probabilities remain available under their prior names. The pack is the unit of optimisation and freezing; use separate packs when separate optimiser treatment is required.

base_dtype is configured once on transform and is shared by every unconstrained N value and unit-hypercube U value in that transformed model, whether packed or created through Prior.parameter(). Priors remain responsible for their physical X dtype, so a forward transform may produce floating, integer, boolean, or complex values independently of the N/U dtype. Prior constructors therefore do not take base_dtype.

Packed parameterisation is intended for new models. Its checkpoint layout follows the declared prior order, so keep the order and base dimensions stable when restoring a packed model. Existing models using Prior.parameter() remain supported.

Physical initial values can be supplied in prior order. Entries may use the same constant or callable forms supported by Prior.parameter(); callables receive the physical X shape and dtype of their prior:

location, weights = parameters.parameter(
    init=(0., lambda key, shape, dtype: 0.5 * jnp.ones(shape, dtype))
)

Change Log

25 Feb, 2026 -- 1.1.0 released with scoped dicts structure changes. Breaks backward compatibility with 1.0.x, but adds support for nested contexts and more flexible scoping.

21 July, 2025 -- 1.0.3 released with support for jaxctx.prior and jaxctx.prior.Prior.

3 June, 2025 -- 1.0.2 prior constrained parameters released.

2 June, 2025 -- 1.0.1 released with context API.

Metadata

Release files for jaxctx 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jaxctx 1.1.5
File Size Uploaded
jaxctx-1.1.5.tar.gz 42.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jaxctx 1.1.5
File Interpreter ABI Platform
jaxctx-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 76.2 kB

Release files / jaxctx-1.1.5.tar.gz

Download URL jaxctx-1.1.5.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6a7e2327e5830111f8301ddcbc6d7df04b9cc415e53423e9083e55d36729d7f5
BLAKE2b-256 checksum
How to use checksums
caf5eaf90607aa3061476cb7628bcf1453b6f40505395e1cd0515b4187c97709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / jaxctx-1.1.5-py3-none-any.whl

Download URL jaxctx-1.1.5-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a938dbdee6d32320f27cfffc97c8d1bcb6c4071d7a763219aeb08a31af9c53e7
BLAKE2b-256 checksum
How to use checksums
52dd42f86b8d1a0cb18dae46d96a2f07b9f8adc25b72d5cb0943be8774efc315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.6

2 release files

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page