Quantum enhanced Markov Chain Monte Carlo sampler simulated using PennyLane
Project description
Quantum-enhanced Markov Chain Monte Carlo Simulator
This is a lightweight research package for Quantum-enhanced Markov Chain Monte Carlo (QeMCMC) sampling over discrete spin/bitstring configurations.
The implementation is inspired by the numerics in Layden's work on QeMCMC and builds upon the foundations of the pafloxy/quMCMC repository.
Features
- Arbitrary Energy Models: Define any classical Ising or QUBO-like model using a simple list of coupling tensors (example: 2D Ising
h,Jetc). A universal energy calculator handles arbitrary-order interactions - Automatic Hamiltonian Construction: Build the corresponding quantum Hamiltonian based on the given couplings and run Trotterised time evolution with PennyLane's lightining qubit simulator
- Coarse Graining: Optionally use local updates on chosen subgroups of spins to scale proposals
Installation
This project uses uv, an extremely fast Python package installer written in Rust, intended as a drop-in replacement for pip and pip-tools. Official installation instructions available at astral.sh/uv
-
Install
uv: For macOS and Linux run:curl -LsSf https://astral.sh/uv/install.sh | sh
-
Create a virtual environment: From the project's root directory, run:
uv syncThis will create a local
.venvfolder and install all required dependencies frompyproject.tomlanduv.lock.
Quick Start - Example 2D Ising Model
1. Initialise an energy model
In this step, we define a classical energy function over binary spin configurations. This energy model is the target distribution that the QeMCMC sampler will explore.
import numpy as np
from qemcmc.model import EnergyModel
n = 4
h = np.array([-1.0, 0.5, 0.0, 2.0])
# Symmetric J
J = np.array([
[0.0, 1.2, 0.0, 0.0],
[1.2, 0.0, -0.7, 0.0],
[0.0, -0.7, 0.0, 0.4],
[0.0, 0.0, 0.4, 0.0],
])
couplings = [h, J]
model = EnergyModel(n=n, couplings=couplings, name="my_ising")
Here, h represents local fields and J encodes pairwise interactions in a standard Ising formulation. Higher-order coupling tensors can also be supplied.
2. (Optional) Define coarse graining
Coarse graining allows the sampler to propose local multi-spin updates on predefined subgroups, rather than updating all spins at once.
from qemcmc.coarse_grain import CoarseGraining
cg = CoarseGraining(
n=n,
subgroups=[[0,1], [2,3,4], [1,3]],
subgroup_probs=[0.3, 0.5, 0.2],
)
Each subgroup specifies a set of spin indices that may be updated together. At each MCMC step, a subgroup is sampled according to subgroup_probs.
3. Create and run QeMCMC
Finally, we initialise the quantum-enhanced Markov chain and generate a single proposal using simulated quantum time evolution.
from qemcmc.qemcmc import QeMCMC
sampler = QeMCMC(
model=model,
gamma=(0.3, 0.6),
time=(1, 5),
temp=1.0,
delta_time=0.8,
coarse_graining=cg,
)
s = "01010"
s_prime = sampler.get_s_prime(s)
print("proposal:", s, "->", s_prime)
Here, each call to get_s_prime runs a quantum circuit to generate a proposal state conditioned on the current configuration.
Coarse Graining
To do coarse graining, a list of subgroups and it's corresponding probabilities along with the couplings list should be passed in as parameters when initializing a coarse graining object. The subgroup list should contain lists of spin indices that belong to each subgroup. For example, for a system with 6 spins divided into 2 subgroups of 3 spins each, the subgroup list would be [[0, 1, 2], [3, 4, 5]].
NOTE: All spins must belong to at least one subgroup and subgroups may overlap (i.e., a spin may belong to multiple subgroups).
The CircuitMaker will then automatically build the evolution circuit to perform coarse graining based on these subgroups.
Documentation
QeMCMC's documentation is available at docs.
License
Distributed under the MIT License. See LICENSE for more information.
Authors
This project was created by Stuart Ferguson and maintained by Feroz Hassan.
For questions, suggestions, or collaboration, please feel free to contact the authors:
Acknowledgements
- pafloxy/quMCMC for the foundational code.
- Quantum-enhanced Markov Chain Monte Carlo by David Layden et al.
- Quantum-enhanced MCMC for systems larger than your Quantum Computer by S. Ferguson and P. Wallden.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qemcmc-0.1.1.tar.gz.
File metadata
- Download URL: qemcmc-0.1.1.tar.gz
- Upload date:
- Size: 305.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83fd5d80fdeb73da13036d03577239e19371da2de61357e375255b4f7d84208a
|
|
| MD5 |
c2e9ab4e8a6351b579b323e2572db205
|
|
| BLAKE2b-256 |
dc1142d92775d2b0f144ebaf734633f16d26fa98fbe1ea372a7f95dfca429508
|
Provenance
The following attestation bundles were made for qemcmc-0.1.1.tar.gz:
Publisher:
publish.yaml on Stuartferguson00/QeMCMC
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qemcmc-0.1.1.tar.gz -
Subject digest:
83fd5d80fdeb73da13036d03577239e19371da2de61357e375255b4f7d84208a - Sigstore transparency entry: 1147510034
- Sigstore integration time:
-
Permalink:
Stuartferguson00/QeMCMC@4d4ed1a597dddc6682cbd0e69ebdb2b3cc64500a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Stuartferguson00
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@4d4ed1a597dddc6682cbd0e69ebdb2b3cc64500a -
Trigger Event:
push
-
Statement type:
File details
Details for the file qemcmc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: qemcmc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1e53967f74f0035cd88a3bd6afb8fe47adb9c0a93539cbf2b45e54a585c5bd
|
|
| MD5 |
262535b5614c8d9bffaeaec1d846af70
|
|
| BLAKE2b-256 |
0b709193f7e2c8e13247213923fb78bc7ced105b886dcb5296b6b1e4db97c573
|
Provenance
The following attestation bundles were made for qemcmc-0.1.1-py3-none-any.whl:
Publisher:
publish.yaml on Stuartferguson00/QeMCMC
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qemcmc-0.1.1-py3-none-any.whl -
Subject digest:
1d1e53967f74f0035cd88a3bd6afb8fe47adb9c0a93539cbf2b45e54a585c5bd - Sigstore transparency entry: 1147510098
- Sigstore integration time:
-
Permalink:
Stuartferguson00/QeMCMC@4d4ed1a597dddc6682cbd0e69ebdb2b3cc64500a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Stuartferguson00
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@4d4ed1a597dddc6682cbd0e69ebdb2b3cc64500a -
Trigger Event:
push
-
Statement type: