StringJAX Tools
stringjax_tools is a small utility package for reusable JAX transform
patterns used across StringJAX projects. Use
it when a package needs the same JAX mechanics in several places, but should
not carry domain-specific names or conventions into a shared helper layer.
It currently focuses on:
- conservative rank-checked automatic vectorisation;
- manual cached
jax.jit(jax.vmap(...))wrappers; - small helpers for explicit static-argument JIT compilation;
- explicit JAX persistent-compilation-cache setup;
- configurable pytree registration for stateful model classes;
- running a call in a child process with an enforced timeout
(
run_in_subprocess); - recording which code produced a result (
provenance).
The package keeps reusable transformation and pytree machinery separate from domain-specific StringJAX model code.
Installation
From this directory:
pip install -e ".[dev,docs]"
From PyPI:
pip install stringjax-tools
The Python import name is:
import stringjax_tools
Documentation
The Sphinx documentation lives in documentation/:
make -C documentation html
For strict local validation:
make -C documentation html SPHINXOPTS="-W -q"
The feature notebooks are included under documentation/source/notebooks/ and
are linked from the Sphinx tutorials page.
Start with the compact feature tour:
documentation/source/notebooks/00_crucial_features.ipynb
It shows the pieces most StringJAX packages usually need first:
auto_vmapfor scalar-or-leading-batch public methods;- exact shape validation for package-local model conventions;
vmapping_func_cachedfor explicitin_axeskernels;- static-argument JIT helpers;
PytreePolicyfor stateful model classes;- explicit persistent compilation-cache setup.
Package Boundary
stringjax_tools is intentionally application-agnostic. Consuming packages
should define their own shape names, static keys, ignored cache attributes and
state policies locally. For example, a downstream package can wrap
stringjax_tools.auto_vmap with package-specific defaults, while
stringjax_tools itself remains free of domain language.
Automatic Vectorisation
Keep the single-sample function explicit, then wrap it at the boundary where callers may pass either one sample or a paired leading-axis batch.
import jax.numpy as jnp
from stringjax_tools.auto_vectorise import auto_vmap
def observable_single(moduli, tau, fluxes, scale=1.0):
return scale * (jnp.sum(jnp.abs(moduli) ** 2) + tau + jnp.sum(fluxes**2))
observable = auto_vmap(moduli=1, tau=0, fluxes=1)(observable_single)
With these declarations:
modulihas sample rank1, so(h,)is one sample and(N, h)is a batch.tauhas sample rank0, so()is one sample and(N,)is a batch.fluxeshas sample rank1, so(n,)is one sample and(N, n)is a batch.
If several checked arguments are batched, all leading batch sizes must agree.
Checked arguments without a batch axis are broadcast with in_axes=None.
Exact Shape Validation
Ranks decide batching. Exact trailing dimensions are optional:
class Model:
def __init__(self, h12, n_fluxes):
self.h12 = h12
self.n_fluxes = n_fluxes
@auto_vmap(
sample_ranks={"moduli": 1, "fluxes": 1},
sample_shapes={
"moduli": "h12",
"fluxes": lambda bound: (2 * bound["self"].n_fluxes,),
},
validate_shapes=True,
)
def diagnostic(self, moduli, fluxes):
return jnp.sum(jnp.abs(moduli) ** 2) + 0.01 * jnp.sum(fluxes**2)
String dimensions are resolved from a bound object, usually self. Derived
dimensions should be callables rather than expression strings.
The same public API can be imported from the package root when convenient:
from stringjax_tools import auto_vmap
Manual Transform Helpers
When a function already has a deliberate in_axes structure, use:
from stringjax_tools.vmap import vmapping_func_cached
batched = vmapping_func_cached(single_sample_function, in_axes=(0, None, 0))
Static keyword configuration is snapshotted when the cached wrapper is built. Prefer immutable configuration objects, such as tuples, for values that should participate in wrapper caching.
For explicit static positional arguments:
from stringjax_tools.jit import jit_with_static_args
jit_f = jit_with_static_args(f, static_argnums=(2,))
Pytree Policies
Each StringJAX package should define its own static and ignored attribute policy locally. The tool package supplies only generic registration machinery.
from stringjax_tools.pytrees import PytreePolicy
PACKAGE_PYTREE_POLICY = PytreePolicy(
static_keys=("h11", "h12", "model_ID", "_user_Q"),
ignore_defaults={"_sampler": None, "_cache": dict},
)
PACKAGE_PYTREE_POLICY.register(MyModelClass)
Semantic model state belongs in static_keys when it is hashable and immutable,
or in traced children when it is array-like. Ignored attributes should be
limited to recomputable caches, scratch state, and eager-only helpers. Since
JAX reconstruction bypasses __init__, ignored caches that may be read after a
round trip should be declared through ignore_defaults; callable defaults such
as dict are called for each reconstructed object. Do not ignore user-supplied
configuration such as physical bounds or tadpole values.
Static and ignored attribute names must be disjoint. Static values are
validated by default: they must be hashable and have scalar, self-equal
comparison semantics, so array-like and NaN-like values are rejected unless a
package deliberately opts out with validate_static=False.
Leave validate_static=True unless the consuming package deliberately stores
non-hashable metadata in JAX pytree auxiliary data.
Compilation Cache
configure_compilation_cache(...) is opt-in and has no import-time side
effects. Call it before the first JAX compilation in a process:
from stringjax_tools.cache import configure_compilation_cache
configure_compilation_cache(
cache_dir=".jax-cache",
max_size_bytes=10_000_000_000,
)
License
StringJAX Tools is distributed under the GNU General Public License v3.0 or later.
Metadata
Release files for stringjax-tools 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stringjax_tools-0.2.0.tar.gz | 50.7 kB | With provenance | Details for stringjax_tools-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stringjax_tools-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for stringjax_tools-0.2.0-py3-none-any.whl |
Total release size: 96.3 kB
Release files / stringjax_tools-0.2.0.tar.gz
| Download URL | stringjax_tools-0.2.0.tar.gz |
|---|---|
| Size | 50.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4d0e20217f708044636db348802169c84b281d876a0c72c8b5bc3610b5194ab
|
|
BLAKE2b-256 checksum How to use checksums |
5c9e130e6b783fb34755ff97575d1a5750ccd83819738a0c30347eae2330bd18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / stringjax_tools-0.2.0-py3-none-any.whl
| Download URL | stringjax_tools-0.2.0-py3-none-any.whl |
|---|---|
| Size | 45.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
339eed20138eb8adb588308e6ae8399cb682852ee7dd482f37a00d6d5d0a7ee3
|
|
BLAKE2b-256 checksum How to use checksums |
dcf83bde525f4401368952caed7010dbc2355bce5a9a3296556c67870c415714
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for stringjax-tools 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for stringjax_tools-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.