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.0.0.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

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

pbitlang-2.0.0-py3-none-any.whl (117.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pbitlang-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d73f1c3629c01e6709c6b7881f7235fb4a2ac5394b92aaeb5ff7793126e33e10
MD5 057e930a3bcf4c442667f843238dc194
BLAKE2b-256 59a2b933834abd3127b3395eeec08f7d3b1b650262cd30391ded5f19163641da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pbitlang-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 117.1 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62cceb0c7b41261ff0a65032bf4d9961c82e3edf05cb2680c4adcfa343089f6f
MD5 48cb2db548031cd65221c7d2bfd67b37
BLAKE2b-256 dade2e2a6b10e1d3e68adba9873ab3282eba087c7b2e99e7ff81206707b53f25

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