circuits
qemcmc.circuits ¶
BaseCircuitMaker ¶
Constructs and simulates quantum circuits used to generate QeMCMC proposals.
This class builds the Hamiltonian corresponding to a given energy model and simulates its time evolution using PennyLane. Starting from a classical bitstring configuration, the circuit performs Trotterised quantum evolution and samples a new configuration from the resulting quantum state.
The generated sample serves as the proposal state in the quantum-enhanced MCMC algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
EnergyModel
|
Energy model defining the problem Hamiltonian. |
required |
Source code in src/qemcmc/circuits/basecircuitmaker.py
get_problem_hamiltonian ¶
Construct the problem Hamiltonian from symmetric coupling tensors.
This method supports both 'ising' (-1/+1) and 'binary' (0/1) models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
couplings
|
List[BinaryPolynomial]
|
A list of coupling polynomials. |
required |
sign
|
int
|
A sign to apply to the Hamiltonian. Default is |
1
|
Returns:
| Type | Description |
|---|---|
Hamiltonian
|
The problem Hamiltonian. |
Source code in src/qemcmc/circuits/basecircuitmaker.py
get_mixer_hamiltonian ¶
Constructs the Mixer Hamiltonian: Σ X_i.
This can be for the full system or a subgroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_wires
|
int
|
The number of wires (qubits) for the mixer. If None, uses the total number of qubits. |
None
|
Returns:
| Type | Description |
|---|---|
Hamiltonian
|
The mixer Hamiltonian. |
Source code in src/qemcmc/circuits/basecircuitmaker.py
check_Hamiltonian ¶
Utility function to print the Energy of the Hamiltonian to be simulated. Naturally, for a classical problem, the energy of the Hamiltonian wrt to some basis state b H|b> = E|b> should equal the energy of the corresponding state in the classical model. This is a useful sanity check to ensure that the Hamiltonian is being constructed correctly from the coupling tensors.
Source code in src/qemcmc/circuits/basecircuitmaker.py
QuenchCircuitMaker ¶
Bases: BaseCircuitMaker
The total Hamiltonian simulated by the circuit is
``H = γ H_mixer + (1 - γ) α H_problem``
where H_problem encodes the classical energy model and H_mixer
corresponds to a transverse-field term. The evolution time t and
number of Trotter steps r are passed per call, giving an effective
Trotter step size of δt = t / r. The evolution is approximated
using Trotterisation via qml.ApproxTimeEvolution.
Source code in src/qemcmc/circuits/quenchcircuitmaker.py
get_state_vector ¶
Evolve the initial state and return the final state vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
Input bitstring representing the initial state. |
required |
weights
|
list of float
|
Coefficients for the problem Hamiltonian terms. |
required |
time
|
float
|
Total evolution time. |
required |
r
|
int
|
Number of Trotter steps for the approximate time evolution. |
required |
mix_weight
|
float
|
Coefficient for the mixer Hamiltonian. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The final state vector. |
Notes
The total Hamiltonian simulated by the circuit is a weighted sum of the problem Hamiltonian terms and the mixer Hamiltonian:
In Ferguson et al. (2025) [arXiv:2506.19538], we use gammas to weight the entire problem Hamiltonian vs the mixer vs the constraint Hamiltonian, such that the total Hamiltonian is:
H = g_p * H_p + g_m * H_m + g_c * H_c
but here we allow for separate weights for each coupling tensor term, as well as a separate gamma for the mixer. The total Hamiltonian is then:
H = (w_b1*H_b1 + w_b2*H_b2 + ... + w_b2*H_bm) + g_m * H_m
In other words, the constraint hamiltonian is absorbed in the coupling list, and weighted by the corresponding gamma in the gammas list. This allows for more flexible weighting of different terms, and also allows us to use the same code for both constrained and unconstrained problems (by simply including or excluding the constraint Hamiltonian in the coupling list and adjusting the gammas accordingly).
Note that it is assumed that each term is already normalised appropriately, so the gammas can be interpreted as the relative weights of each term in the total Hamiltonian.
Source code in src/qemcmc/circuits/quenchcircuitmaker.py
get_sample ¶
Generate a single sample by evolving the system and measuring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s_cg
|
str
|
Input bitstring for the subgroup. |
required |
time
|
float
|
Total evolution time. |
required |
r
|
int
|
Number of Trotter steps for the approximate time evolution. |
required |
mix_weight
|
float
|
Coefficient for the mixer Hamiltonian. |
required |
local_couplings
|
list
|
Coupling tensors for the subgroup. |
required |
weights
|
list of float
|
Coefficients for the problem Hamiltonian terms. Defaults to ones. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A single bitstring sample. |
Source code in src/qemcmc/circuits/quenchcircuitmaker.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
update ¶
Update a bitstring by evolving a subgroup.
This performs a time evolution on a coarse-grained Hamiltonian to get s' from s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The initial bitstring. |
required |
subgroup_choice
|
list of int
|
Indices of the subgroup to evolve. |
required |
local_couplings
|
list
|
Coupling tensors for the subgroup. |
required |
gamma
|
float
|
Mixing parameter. |
required |
time
|
float
|
Evolution time. |
required |
r
|
int
|
Number of Trotter steps for the approximate time evolution. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The updated bitstring s'. |
Source code in src/qemcmc/circuits/quenchcircuitmaker.py
AdiabaticCircuitMaker ¶
Bases: BaseCircuitMaker
Constructs and simulates adiabatic quantum circuits for QeMCMC proposals.
The total time-dependent Hamiltonian simulated by the circuit is:
``H(t) = h(t) * mix_weight * H_mixer + H_problem``
where H_problem encodes the classical energy model and H_mixer
corresponds to a transverse-field term. The dimensionless schedule function
h(t) ramps linearly from 0 to 1 over ramp duration alpha, remains at 1
for plateau duration kappa, and ramps down from 1 to 0 over duration alpha
(total duration 2 * alpha + kappa).
The time-dependent evolution is approximated using second-order Trotterisation
via qml.ApproxTimeEvolution over r = max(1, round((2 * alpha + kappa) / dt)) steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
EnergyModel
|
Energy model defining the target Boltzmann distribution. |
required |
Source code in src/qemcmc/circuits/adiabaticcircuitmaker.py
get_sample ¶
Generate a single sample by evolving the system under a time-dependent Hamiltonian and measuring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s_cg
|
str
|
Input bitstring for the subgroup. |
required |
alpha
|
float
|
Duration of the adiabatic ramp. |
required |
kappa
|
float
|
Duration of the plateau. |
required |
mix_weight
|
float
|
Coefficient for the mixer Hamiltonian. |
required |
local_couplings
|
list
|
Coupling tensors for the subgroup. |
required |
weights
|
list of float
|
Coefficients for the problem Hamiltonian terms. Defaults to ones. |
None
|
dt
|
float
|
Timestep size for second order Trotter evolution. Defaults to 0.3. |
0.3
|
Returns:
| Type | Description |
|---|---|
str
|
A single bitstring sample. |
Source code in src/qemcmc/circuits/adiabaticcircuitmaker.py
linear_schedule ¶
Calculates the linear ramp factor h(t) with a plateau of duration kappa and ramp duration alpha.
The schedule satisfies h(t): 0 -> 1 -> 1 -> 0 as t: 0 -> alpha -> alpha + kappa -> 2 * alpha + kappa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Current time during the evolution. |
required |
alpha
|
float
|
Duration of the linear ramp. |
required |
kappa
|
float
|
Duration of the constant plateau. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The instantaneous mixer weight factor in [0, 1]. |
Source code in src/qemcmc/circuits/adiabaticcircuitmaker.py
get_state_vector ¶
Evolve the initial state under the adiabatic Hamiltonian and return the final state vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s_cg
|
str
|
Input bitstring for the subgroup. |
required |
alpha
|
float
|
Duration of the adiabatic ramp. |
required |
kappa
|
float
|
Duration of the plateau. |
required |
mix_weight
|
float
|
Coefficient for the mixer Hamiltonian. |
required |
weights
|
list of float
|
Coefficients for the problem Hamiltonian terms. Defaults to ones. |
None
|
dt
|
float
|
Timestep size for second order Trotter evolution. Defaults to 0.3. |
0.3
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The final quantum state vector. |
Source code in src/qemcmc/circuits/adiabaticcircuitmaker.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
update ¶
Update a bitstring by evolving a subgroup.
This performs a time evolution on a coarse-grained Hamiltonian to get s' from s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The initial bitstring. |
required |
subgroup_choice
|
list of int
|
Indices of the subgroup to evolve. |
required |
local_couplings
|
list
|
Coupling tensors for the subgroup. |
required |
gamma
|
float
|
Mixing parameter. |
required |
alpha
|
float
|
Adiabatic ramp time. |
required |
kappa
|
float
|
Plateau time. |
required |
dt
|
float
|
Trotter step size for the approximate time evolution. Defaults to 0.3. |
0.3
|
Returns:
| Type | Description |
|---|---|
str
|
The updated bitstring s'. |