Skip to main content

Thermodynamic HypergRaphical Model Library (THRML)

Project description

THRML

THRML is a JAX library for building and sampling probabilistic graphical models, with a focus on efficient block Gibbs sampling and energy-based models. Extropic is developing hardware to make sampling from certain classes of discrete PGMs massively more energy‑efficient; THRML provides GPU‑accelerated tools for block sampling on sparse, heterogeneous graphs, making it a natural place to prototype today and experiment with future Extropic hardware.

Features include:

  • Blocked Gibbs sampling for PGMs
  • Arbitrary PyTree node states
  • Support for heterogeneous graphical models
  • Discrete EBM utilities
  • Enables early experimentation with future Extropic hardware

From a technical point of view, the internal structure compiles factor-based interactions to a compact "global" state representation, minimising Python loops and maximising array-level parallelism in JAX.

Installation

Requires Python 3.10+.

pip install thrml

Documentation

Available at docs.thrml.ai.

Quick example

Sampling a small Ising chain with two-color block Gibbs:

import jax
import jax.numpy as jnp
from thrml import SpinNode, Block, SamplingSchedule, sample_states
from thrml.models import IsingEBM, IsingSamplingProgram, hinton_init

nodes = [SpinNode() for _ in range(5)]
edges = [(nodes[i], nodes[i+1]) for i in range(4)]
biases = jnp.zeros((5,))
weights = jnp.ones((4,)) * 0.5
beta = jnp.array(1.0)
model = IsingEBM(nodes, edges, biases, weights, beta)

free_blocks = [Block(nodes[::2]), Block(nodes[1::2])]
program = IsingSamplingProgram(model, free_blocks, clamped_blocks=[])

key = jax.random.key(0)
k_init, k_samp = jax.random.split(key, 2)
init_state = hinton_init(k_init, model, free_blocks, ())
schedule = SamplingSchedule(n_warmup=100, n_samples=1000, steps_per_sample=2)

samples = sample_states(k_samp, program, schedule, init_state, [], [Block(nodes)])

Developing

To get started, you'll need to create a virtual environment and install the requirements:

# Create a virtual environment
python -m venv venv

# Activate the virtual environment
source venv/bin/activate

# Install the package with development dependencies
pip install -e ".[development,testing,examples]"

# Install pre-commit hooks
pre-commit install

The pre-commit hooks will automatically run code formatting and linting tools (ruff, black, isort, pyright) on every commit to ensure consistent style.

If you want to skip pre-commit (for a WIP commit), you can use the --no-verify flag:

git commit --no-verify -m "Your commit message"

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-0.1.3.tar.gz (48.1 kB view details)

Uploaded Source

Built Distribution

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

thrml-0.1.3-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file thrml-0.1.3.tar.gz.

File metadata

  • Download URL: thrml-0.1.3.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for thrml-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8f8d3a931fadc64dfcff41ac3c07519b626ca45be2e724de6fedcb752bf86f42
MD5 931839d04ebcede836c48016160af5fc
BLAKE2b-256 b96e036d8f3b6edd3a9ad532254185f270d64947c96e3a5b7af60349f9f680f0

See more details on using hashes here.

File details

Details for the file thrml-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: thrml-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for thrml-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 21447a9b755061982226fab8b32089cd61f04baec147bd998297ea1d96fbbeb5
MD5 672f457bfcc5c4909c23658f05dca4ae
BLAKE2b-256 978f4d0e08d64d6217426f527a64d8d20ced4bb5bbe09f30091729bc26570abe

See more details on using hashes here.

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