Skip to main content

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 the jax device type in PyTorch through torchax.
  • compile(program, schedule, …) – turns a THRML sampling program into a torch.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 with thrml.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. checkerboard nodes_to_sample partitions.

Run any script with python examples/<name>.py after installing the package and torchax dependency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thrml_th-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thrml_th-0.1.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

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

Hashes for thrml_th-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a4b0fb46a8c64333ba419d63d81a34ca8e993ae7ae6ce09c12f4ca827fa2ca3f
MD5 65b34bc21d40741b7eb90dbdcea7bc41
BLAKE2b-256 b55185218ebb162aac1e7a432d85d7d4053d8a01168473f3c0537f8f60be622e

See more details on using hashes here.

Provenance

The following attestation bundles were made for thrml_th-0.1.1.tar.gz:

Publisher: release.yaml on ClashLuke/thrml_th

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for thrml_th-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0416a453d61d4179ba110f0d1326ae5d1b0739a52102304e86df37d606c99b09
MD5 edd8f25ce1fc3624305b3a5ae03cb30b
BLAKE2b-256 ce1f14786a5fb38cffbaa57144d6677d9236d6835f604f23868471351709170c

See more details on using hashes here.

Provenance

The following attestation bundles were made for thrml_th-0.1.1-py3-none-any.whl:

Publisher: release.yaml on ClashLuke/thrml_th

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page