Skip to main content

PbitLang

The p-bit / thermodynamic-computing language.

Python

PbitLang lets you write a Hamiltonian (energy function) once and run it on thermodynamic hardware — P-bits, Ising machines, annealers, and continuous thermodynamic samplers. v2.0 makes PbitLang the authoring front-end for the whole EnergyIR stack: a program compiles to device-independent ThermoIR and runs on the local simulator, a real sampler, or the hosted Thermo Bridge, where every run comes back with a signed certificate you verify offline.

Train energy-based models (new)

Where PyTorch trains by backprop, energy-based models train by sampling — the gradient of the log-likelihood is ⟨·⟩data − ⟨·⟩model, and the model term is the negative phase a thermodynamic device is built to compute. pbitlang.learn is that engine:

from pbitlang.learn import RBM, learn_ising

rbm = RBM(n_visible=9, n_hidden=16).fit(data)   # contrastive divergence
gen = rbm.sample(100)                            # generate

J, h = learn_ising(spin_samples)                 # recover couplings from data (inverse Ising)

What's new in 2.0

  • Compiles to ThermoIR — not just PHAL. One program, any backend.
  • Runs on the Thermo Bridgerun(..., backend="bridge") → result + certificate, verified offline.
  • All four primitive families (the p-bit hardware vocabulary):
    Primitive What it is PbitLang
    p-bit Bernoulli / binary spin ising / binary on a lattice → ThermoIR Ising
    p-mode Gaussian thermo.gaussian_program(A, b) → ThermoIR Quadratic
    p-MoG Mixture of Gaussians (multimodal) thermo.mixture_program(...)EnergyGraph + Langevin
    p-dit Categorical Potts / one-hot lowering (DSL surface lands in 2.x)
  • A training engine for energy-based models (pbitlang.learn) — RBMs (CD / persistent CD / parallel tempering), classification RBMs, deep belief nets, Gaussian–Bernoulli RBMs, and inverse Ising — with the negative phase runnable on the Thermo Bridge (negative="thermo").
  • Certified inference — provable lower/upper bounds on log Z yield a certified log-likelihood interval, wrapped in an ed25519-signed, offline-verifiable certificate. The number PyTorch can't give you: a bound you can prove, not a loss you take on faith.
  • PyTorch interop (pbitlang.torch) — write the energy as a torch.nn.Module, train with torch.optim + autograd, and let the thermodynamic sampler supply the partition-function gradient. DeepThermoEBM extends this to deep (conditional) energy landscapes.
  • CLI run — compile and execute from the shell, local or hosted.
  • Repaired core — the v1.x parser/checker rejected its own documented examples (coupling: / field: labels, neighbors domains, J * s[i] arithmetic). Those now compile.

Install

pip install pbitlang                    # the language + compiler (zero core deps)
pip install 'pbitlang[learn]'           # + the EBM training engine + certified inference (NumPy only)
pip install 'pbitlang[certify]'         # + ed25519-signed certificates (adds cryptography)
pip install 'pbitlang[thermo]'          # + the ThermoIR / Thermo Bridge backend (needs energyir >= 1.1.0)
pip install 'pbitlang[torch]'           # + PyTorch interop: DeepThermoEBM, autograd training
pip install 'pbitlang[torch-thermo]'    # + ThermoEBM samplers on the thermo runtime (torch + energyir)

The [thermo] / [torch-thermo] extras require energyir ≥ 1.1.0, the first release that ships the energyir.thermo runtime (compiler, backends, the gibbs Boltzmann sampler). The training engine and certified inference ([learn] / [certify]) are pure-NumPy and need none of that.

Quick start

import pbitlang
from pbitlang import thermo

src = """
hamiltonian Ising(n: int, J: real = 1.0, h: real = 0.0)
    -> ising on chain(n) {
    coupling: sum((i, j) in neighbors) { -J * s[i] * s[j] }
    field:    sum(i in sites)          { -h * s[i] }
}
"""

# Compile → a ThermoIR Program; run locally:
res = thermo.run(src, n=16, J=1.0, h=0.1, backend="simulator", shots=1000)
print(res.value)

# ...or run on the hosted Thermo Bridge and verify the certificate offline:
res = thermo.run(src, n=16, backend="bridge",
                 api_key="eir-thermo-...", certificate="statistical")
print(res.verified)   # True — the worker signed it, you checked it

Continuous pole (p-mode / p-MoG):

import numpy as np
from pbitlang import thermo

# p-mode: solve A x = b as a Gaussian readout
A = np.array([[4., 1.], [1., 3.]]); b = np.array([1., 2.])
print(thermo.run(None, program=thermo.gaussian_program(A, b, readout="mean")).value)  # = A^-1 b

# p-MoG: a bimodal landscape; both basins are visited
prog = thermo.mixture_program(dim=1, wells=1.0, well_scale=2.0, shots=4000)
print(thermo.run(None, program=prog).value)

CLI

pbitlang run model.pbit -p n=16 -p J=1.0 --backend simulator
pbitlang run model.pbit -p n=16 --backend bridge --certificate statistical   # $THERMO_API_KEY
pbitlang compile model.pbit -t info
pbitlang stdlib list

Language

  • Spin types: ising, binary, potts(q), clock(q), continuous
  • Lattices: chain, square, triangular, honeycomb, kagome, cubic, custom (adjacency / edges)
  • Energy: coupling: / field: / energy: terms with sum / product comprehensions, patterns, where
  • Domains: neighbors, next_neighbors, all_pairs, sites
  • Physics validation: frustration, critical temperature, symmetry checks at compile time

Part of the EnergyIR thermodynamic stack

PbitLang authors the Hamiltonian; ThermoIR is the device-independent IR; the Thermo Bridge runs it hosted with certificates. See the Thermo Bridge docs on energyir.io.

License

Proprietary Software — Copyright © 2024–2026 David Johnson. All Rights Reserved.

Download files

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

Source Distribution

pbitlang-2.1.0.tar.gz (201.4 kB view details)

Uploaded Source

Built Distribution

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

pbitlang-2.1.0-py3-none-any.whl (165.2 kB view details)

Uploaded Python 3

File details

Details for the file pbitlang-2.1.0.tar.gz.

File metadata

  • Download URL: pbitlang-2.1.0.tar.gz
  • Upload date:
  • Size: 201.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pbitlang-2.1.0.tar.gz
Algorithm Hash digest
SHA256 9586b964c9ad7209c9ab21b9153659eae8fa7dfed4d0b39104cd9c7f70ca71bd
MD5 40e29b33555a6fa579b42f05cafffa7c
BLAKE2b-256 951fdfcf4b55e429f992791d0d4573146f2ac27d00c49ec97a28c9d7beb01048

See more details on using hashes here.

File details

Details for the file pbitlang-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: pbitlang-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 165.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pbitlang-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad2f110d941a0482e0dd2bd1abdcc4289df686b61b75e70de4c7c9a048e41e5e
MD5 025a2faea1b3be911d0e9c17bb4bf004
BLAKE2b-256 8d2f60fb4de3174cd675c8fe82a3e5f7d5ba2c898278ee1cd40769ef6d3ae856

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 Sentry Error logging StatusPage Status page