TORX

Examples

The gallery holds 16 notebooks. They start with a one-gate circuit and work up to trained networks and directed factor graphs. Each page is a full run of its notebook, with the outputs it produced.

Foundations

The primitives, the core gates, and the circuit-to-simulator pipeline.

01 Introduction to parametrised stochastic circuitsBuild and sample your first stochastic circuits: pbits, pdits, and pmodes, each driven by its core gate, from constructor to simulator. 02 Random walks on graphsSimulate a continuous-time random walk on a graph with one PSWAP gate per edge, then refine the Trotter step until the flow matches the exact kernel. 03 Bunny graph diffusionRun Stanford bunny connectivity diffusion through 1,352 PSWAP gates per step, compare a 32,000-sample Torx mean with the exact graph kernel, and expose ordered-sweep bias. 04 The execution interface: sampling and readoutsTurn Torx samples into histograms, expectations, and error bars, then verify the expected 1/sqrt(N) Monte Carlo concentration rate.

Discrete models

Boltzmann machines, diffusion, and trained circuits on pbits.

05 Chemical reaction networksApproximate finite mass-action reaction networks with Torx PJUMP split steps, then compare count means with exact CTMC and host Gillespie references. 06 Ising sampling and contrastive divergenceCompare Torx chromatic Gibbs with a host sampler built from Torx PISING matrices, then fit the 8-site ring with host-only persistent contrastive divergence. 07 Posterior per-pixel denoising on MNISTUse an offline UNet to predict clean-pixel probabilities, sample all 784 Bernoulli outputs through Torx PNOT gates, and separate one draw from a 64-draw ensemble estimate. 08 Stochastic convolutional networksTrain a circuit by gradients taken through the sampler itself: parameter-shift updates teach a weight-tied stochastic kernel to classify images. 09 Training a stochastic graph network for MaxCutTrain 12-edge PISING sweeps for MaxCut: Torx supplies exact probability vectors, while notebook JAX and Optax perform corrected REINFORCE updates against exact enumeration.

Continuous and hybrid

Gaussian gates, state-space models, and mixed discrete and continuous processes.

10 Pmode Gaussian gatesCarry continuous state through circuits with affine Gaussian gates and exact moment propagation, plus mixture gates for non-Gaussian density. 11 Building a Gaussian hierarchical state-space modelInfer an offline smoothed latent trajectory from synthetic Gaussian observation channels with a time-homogeneous linear-Gaussian state-space model. 12 Sampling Langevin dynamics on a graph Ising modelWrite your own gate: a custom overdamped-Langevin sampler (ULA and MALA) over a soft-spin Ising energy, validated against exact quadrature. 13 Simulating a regime-switching diffusion processCompose discrete and continuous primitives into a regime-switching diffusion, checked against analytic mixture and occupancy laws. 14 Gaussian-categorical clustering as a Boltzmann machineDerive Gaussian-categorical conditionals, draw Gaussian samples with Torx, compute responsibilities in JAX, and keep the handwritten block-Gibbs loop explicitly host-side.

Directed factor graphs

The layer beneath the circuits: custom factors wired into a directed graph and sampled, with a PSC as one shape it takes.

15 Introduction to Torx factors and directed factor graphsWire samplers into directed factor graphs: factors, ports, composite tiles, and the parametrised stochastic circuit as one shape they take. 16 Gibbs sampling on a directed factor graphBuild a 4x4 Ising sampler from hand-written factors and check block Gibbs against exact enumeration, from temperature sweeps to pattern completion.