circuits
qemcmc.circuits ¶
CircuitMaker ¶
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 |
Notes
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.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[ndarray]
|
A list of coupling tensors. |
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.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.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.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.py
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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
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.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.