Python library for the simulation of probabilistic circuits.
Probabilistic computers operate on probabilistic or p-bits that fluctuate between -1
and +1
randomly with probability given its neighbors:
By connection to the Boltzmann distribution, the binary vector
Probabilistic computers have been known to computer science literature as Boltzmann machines for a number of years but have recently re-emerged as an accelerator target for hardware engineers with the advent of Coherent Ising Machines, Digital Annealers, Oscillator Based Ising Machines, Dynamical Ising Machines and special purpose accelerators for Simulated Bifurcation.
Probabilistic Circuits or p-circuits are any realization of ordinary sequential computation (both classical and quantum!) using p-bits. To date, there are two design frameworks used to implement probabilistic spin logic:
This framework realises classical computation in an "invertible" format, that is, unlike ordinary classical logic - a digital circuit can be run both forwards and backwards by using Gibbs sampling. To instantiate a PSL circuit, we can use the one-to-one relationship between digital logic gates and probabilistic spin logic gates.
Drawing inspiration from Quantum Approximate Optimization algorithms, PAOA represents a subset of QAOA that can be simulated probabilistically - this class of algorithms includes Clifford group quantum emulation, smaller implementations of Shor's algorithm and unusual applications typically reserved for Quantum Computers.
Please check the wiki for more information on probabilistic computers.
There is no official release at the moment. Only dev version is available. Follow these steps:
- Clone the repo locally
- Set up a Python environment (we recommend Anaconda for example). We support python 3.9 and 3.10.
- Run
pip install .
andpip install .[tests]
(for visualization and testing).
Create a circuit using the new decorator-based API:
from p_kit import psl
from p_kit.psl import Port
@psl.pcircuit(n_pbits=3)
class MyCircuit:
# Define ports
p1 = Port("p1")
p2 = Port("p2")
p3 = Port("p3")
# Define matrices
J = np.array([[0, -2, -2],
[-2, 0, 1],
[-2, 1, 0]])
h = np.array([[2], [-1], [-1]])
Create a module to combine circuits:
@psl.module
class MyModule:
def __init__(self):
self.circuit = MyCircuit()
Create a solver and solve the circuit:
- Nt: number of runs
- Dt: time interval for constant inputs
- i0: correlation strength (closer to 1 = closer to boolean logic)
from p_kit.solver.csd_solver import CaSuDaSolver
solver = CaSuDaSolver(Nt=10000, dt=0.1667, i0=0.8)
_, output = solver.solve(c)
Visualize the results:
from p_kit.visualization import histplot
histplot(output)
The histogram shows the non-random distribution of states, indicating successful probabilistic computation.
The library supports multiple types of connections between ports:
from p_kit.psl import ConnectionType
# No copy connection (shared global index)
circuit1.p3.connect(circuit2.p1, ConnectionType.NO_COPY)
# Vanilla copy with weight 1.0
circuit1.p3.connect(circuit2.p1, ConnectionType.VANILLA_COPY)
# Weighted copy with custom weight
circuit1.p3.connect(circuit2.p1, ConnectionType.WEIGHTED_COPY, weight=0.5)
The library provides common gates:
from p_kit.psl.gates import ANDGate, ORGate
@psl.module
class LogicCircuit:
def __init__(self):
self.and_gate = ANDGate()
self.or_gate = ORGate()
# Connect gates
self.and_gate.output.connect(self.or_gate.input1)
For more information, visit our documentation.