PyTorch + THRML interop shim (thrml-th).
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thrml_th-0.1.1.tar.gz.
File metadata
- Download URL: thrml_th-0.1.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4b0fb46a8c64333ba419d63d81a34ca8e993ae7ae6ce09c12f4ca827fa2ca3f
|
|
| MD5 |
65b34bc21d40741b7eb90dbdcea7bc41
|
|
| BLAKE2b-256 |
b55185218ebb162aac1e7a432d85d7d4053d8a01168473f3c0537f8f60be622e
|
Provenance
The following attestation bundles were made for thrml_th-0.1.1.tar.gz:
Publisher:
release.yaml on ClashLuke/thrml_th
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thrml_th-0.1.1.tar.gz -
Subject digest:
a4b0fb46a8c64333ba419d63d81a34ca8e993ae7ae6ce09c12f4ca827fa2ca3f - Sigstore transparency entry: 707106853
- Sigstore integration time:
-
Permalink:
ClashLuke/thrml_th@a89cb8c1a9dcd8643e01c45c42e974e3ffba08b9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ClashLuke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@a89cb8c1a9dcd8643e01c45c42e974e3ffba08b9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file thrml_th-0.1.1-py3-none-any.whl.
File metadata
- Download URL: thrml_th-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0416a453d61d4179ba110f0d1326ae5d1b0739a52102304e86df37d606c99b09
|
|
| MD5 |
edd8f25ce1fc3624305b3a5ae03cb30b
|
|
| BLAKE2b-256 |
ce1f14786a5fb38cffbaa57144d6677d9236d6835f604f23868471351709170c
|
Provenance
The following attestation bundles were made for thrml_th-0.1.1-py3-none-any.whl:
Publisher:
release.yaml on ClashLuke/thrml_th
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thrml_th-0.1.1-py3-none-any.whl -
Subject digest:
0416a453d61d4179ba110f0d1326ae5d1b0739a52102304e86df37d606c99b09 - Sigstore transparency entry: 707106854
- Sigstore integration time:
-
Permalink:
ClashLuke/thrml_th@a89cb8c1a9dcd8643e01c45c42e974e3ffba08b9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ClashLuke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@a89cb8c1a9dcd8643e01c45c42e974e3ffba08b9 -
Trigger Event:
release
-
Statement type: