thrml.th
thrml.th exposes THRML’s JAX-based samplers through a PyTorch-friendly API. The module supplies:
enable()– registers thejaxdevice type in PyTorch throughtorchax.compile(program, schedule, …)– turns a THRML sampling program into atorch.nn.Module.torch_view/jax_view– zero-copy conversions between JAX arrays and Torch tensors.- RNG helpers (
make_key,KeyStream) so repeated sampler calls stay deterministic when needed.
Everything necessary to use the package lives in this README and the example scripts.
Install
pip install thrml-th
Usage
import jax
import thrml
import thrml.th as thrml_th
from thrml.models import IsingEBM, IsingSamplingProgram, hinton_init
thrml_th.enable()
nodes = [thrml.SpinNode() for _ in range(4)]
program = IsingSamplingProgram(...)
schedule = thrml.SamplingSchedule(n_warmup=10, n_samples=16, steps_per_sample=2)
sampler = thrml_th.compile(program, schedule)
init_state = thrml_th.torch_view(tuple(hinton_init(
jax.random.key(0), program.model, program.gibbs_spec.free_blocks, ()
)))
samples = sampler(init_state)
Examples
examples/ising_sampler.py– builds an Ising chain, compiles it withthrml.th, prints magnetization stats.examples/pytorch_training_loop.py– drops a compiled sampler into a regular PyTorch training loop.examples/blockwise_sampler.py– compares contiguous vs. checkerboardnodes_to_samplepartitions.
Run any script with python examples/<name>.py after installing the package and torchax dependency.
Metadata
Release files for thrml-th 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| thrml_th-0.1.1.tar.gz | 16.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| thrml_th-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / thrml_th-0.1.1.tar.gz
| Download URL | thrml_th-0.1.1.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4b0fb46a8c64333ba419d63d81a34ca8e993ae7ae6ce09c12f4ca827fa2ca3f
|
|
BLAKE2b-256 checksum How to use checksums |
b55185218ebb162aac1e7a432d85d7d4053d8a01168473f3c0537f8f60be622e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Nov 18, 2025.
Transparency logRelease files / thrml_th-0.1.1-py3-none-any.whl
| Download URL | thrml_th-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0416a453d61d4179ba110f0d1326ae5d1b0739a52102304e86df37d606c99b09
|
|
BLAKE2b-256 checksum How to use checksums |
ce1f14786a5fb38cffbaa57144d6677d9236d6835f604f23868471351709170c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Nov 18, 2025.
Transparency log