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.6

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.6
File Size Uploaded
jaxctx-1.1.6.tar.gz 42.3 kB Details

Built distribution (wheel)

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

Total release size: 76.2 kB

Release files / jaxctx-1.1.6.tar.gz

Download URL jaxctx-1.1.6.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
020d42fb11f27220bec82d36d9b8073cf5a56faa85757f83fadf7dd29587d4db
BLAKE2b-256 checksum
How to use checksums
e2f1be2aa6ba2f7edd9f4db38acdb33e34aee776cdd7b5f3fcce22a13a7851f9
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.6-py3-none-any.whl

Download URL jaxctx-1.1.6-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed43f2c7b5dc302bf85229470020435136cd7bf8ab3306053f7758254a8738bd
BLAKE2b-256 checksum
How to use checksums
efbc2951e794ca4308e6b34c4a76278837224de91275aef5e57498e257d5bc0b
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

This release

1.1.6 This release

2 release files

1.1.5

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