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 Bridge — run(..., 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.

Metadata

Release files for pbitlang 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pbitlang 2.1.1
File Size Uploaded Provenance Actions
pbitlang-2.1.1.tar.gz 207.1 kB Without provenance Details for pbitlang-2.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pbitlang 2.1.1
File Interpreter ABI Platform Actions
pbitlang-2.1.1-py3-none-any.whl Python 3 none any Details for pbitlang-2.1.1-py3-none-any.whl

Total release size: 378.7 kB

Release files / pbitlang-2.1.1.tar.gz

Download URL pbitlang-2.1.1.tar.gz
Size 207.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d0900969e2e29670d1d3ffede06bd150733db1b198876c078bce7f28b3266b31
BLAKE2b-256 checksum
How to use checksums
cfbd66af9aa5df41ed8815fd03c41e669fb0b5676a7f0e35a0a5f8ddd33f27e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / pbitlang-2.1.1-py3-none-any.whl

Download URL pbitlang-2.1.1-py3-none-any.whl
Size 171.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e36b4f689ff8f9c47ef11b9eb6c5ffb5495d182b23d894ebe1d5d6c6d9e4821
BLAKE2b-256 checksum
How to use checksums
ba9057e55d11cd098382c72b0c46bba54cf6b2a6543961efc01894ae41ff3111
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for pbitlang 2.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page