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.1.tar.gz (207.1 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.1-py3-none-any.whl (171.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pbitlang-2.1.1.tar.gz
  • Upload date:
  • Size: 207.1 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.1.tar.gz
Algorithm Hash digest
SHA256 d0900969e2e29670d1d3ffede06bd150733db1b198876c078bce7f28b3266b31
MD5 27997f75e3b52779151a05c3b7ee8997
BLAKE2b-256 cfbd66af9aa5df41ed8815fd03c41e669fb0b5676a7f0e35a0a5f8ddd33f27e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pbitlang-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 171.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e36b4f689ff8f9c47ef11b9eb6c5ffb5495d182b23d894ebe1d5d6c6d9e4821
MD5 00aa2fdd5ab96568847bf337733e8d54
BLAKE2b-256 ba9057e55d11cd098382c72b0c46bba54cf6b2a6543961efc01894ae41ff3111

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