qemcmc
qemcmc ¶
Proposal ¶
Bases: ABC
Abstract base class for producing proposals for Markov Chain Monte Carlo algorithms.
Subclasses implement the proposal mechanism by defining an
update(state) method that generates a candidate state from the current one
(e.g. single-spin flips, block updates, or quantum proposals).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
EnergyModel
|
Energy model defining the target distribution over spin configurations. |
required |
Source code in src/qemcmc/sampler/proposal.py
update
abstractmethod
¶
Generate a candidate state from the current state using the proposal mechanism.
This method should be implemented by subclasses to define the specific proposal strategy (e.g., single-spin flips, block updates, or quantum proposals).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MCMCState
|
The current state of the Markov chain. |
required |
Returns:
| Type | Description |
|---|---|
MCMCState
|
A new candidate state. |
Source code in src/qemcmc/sampler/proposal.py
ClassicalProposal ¶
Bases: Proposal
Classical Markov Chain Monte Carlo proposer.
This class implements purely classical proposal mechanisms for MCMC. New candidate states are generated either by sampling a completely random (uniform) configuration, or by performing a local single-spin or two-spin flip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
EnergyModel
|
Energy model defining the target Boltzmann distribution. |
required |
method
|
str
|
Proposal mechanism used to generate candidate states.
Default is |
'uniform'
|
Source code in src/qemcmc/sampler/classical_proposal.py
update_uniform ¶
Proposes a new state by generating a random bitstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_state_bitstring
|
str
|
The current state represented as a bitstring (not used, but required by the API). |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new random state bitstring of the same length. |
Source code in src/qemcmc/sampler/classical_proposal.py
update_local ¶
Proposes a new state by flipping a single randomly chosen spin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_state_bitstring
|
str
|
The current state represented as a bitstring. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The new state bitstring after flipping one spin. |
Source code in src/qemcmc/sampler/classical_proposal.py
update_2local ¶
Proposes a new state by flipping two randomly chosen spins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_state_bitstring
|
str
|
The current state represented as a bitstring. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The new state bitstring after flipping two spins. |
Source code in src/qemcmc/sampler/classical_proposal.py
QeProposal ¶
QeProposal(
model,
gamma,
time,
r=None,
delta_t=None,
coarse_graining=None,
coupling_weights=None,
m=1,
)
Bases: Proposal
Quantum-enhanced Markov Chain Monte Carlo sampler.
This class implements the proposal mechanism of the quantum-enhanced MCMC algorithm. Candidate states are generated by simulating the quantum time evolution of a transverse-field Hamiltonian.
The quantum proposal circuit is constructed using :class:CircuitMaker
and can optionally operate on coarse-grained subgroups of spins to
improve scalability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
EnergyModel
|
Energy model defining the target Boltzmann distribution. |
required |
gamma
|
float | tuple[float, float]
|
Transverse field strength (Γ). If a tuple is provided, a value is sampled uniformly from the range [min, max] at each step. |
required |
time
|
float | tuple[float, float]
|
Total evolution time. If a tuple is provided, a value is sampled uniformly from the range [min, max] at each step. |
required |
r
|
int | None
|
Number of Trotter steps. Mutually exclusive with |
None
|
delta_t
|
float | None
|
Trotter step size. Mutually exclusive with |
None
|
coarse_graining
|
CoarseGraining | None
|
A coarse-graining scheme to define spin subgroups. If None, no coarse-graining
is used. By default |
None
|
coupling_weights
|
list[float | tuple[float, float]] | None
|
Weights for the coupling tensors. If a tuple is provided, a weight is
sampled uniformly from the range. This allows for dynamic adjustment
of the influence of different terms in the Hamiltonian during the proposal
step. By default |
None
|
m
|
int
|
Number of subgroups to partition the spins into for sequential updates.
By default |
1
|
Notes
The proposal step simulates the time evolution under a transverse-field Hamiltonian defined by the energy model and measures the resulting state to produce a candidate configuration. This proposal is then accepted or rejected using the Metropolis criterion to ensure convergence to the target Boltzmann distribution.
Exactly one of r or delta_t should be passed in as an argument. If neither is
given, a default Δt of 0.8 is used.
Source code in src/qemcmc/sampler/qe_proposal.py
update ¶
Perform 'm' sequential quantum updates across non-overlapping subgroups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_state
|
str
|
Current state of the system as a bitstring. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Updated state of the system as a bitstring. |
Source code in src/qemcmc/sampler/qe_proposal.py
sample_hyperparams ¶
Sample hyperparameters (coupling weights, gamma, time, r) for the current proposal step.
Returns:
| Type | Description |
|---|---|
tuple[list[float], float, float, int]
|
(final_coupling_weights, gamma, time, r) for this proposal step. |
Source code in src/qemcmc/sampler/qe_proposal.py
EnergyModel ¶
A base class for energy models for a classical energy function over n spins, defined by arbitrary-order coupling tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of spins |
required |
couplings
|
List[ndarray]
|
List of numpy arrays representing interaction tensors. A 1D array encodes linear terms, a 2D array encodes pairwise terms (expected symmetric), and higher-rank tensors encode higher-order interactions. |
[]
|
name
|
str
|
Optional label for the model (used in plotting / logging). |
None
|
cost_function_signs
|
list
|
Sign convention(s) used by downstream components (e.g. proposal/acceptance conventions).
For example, |
[-1, -1]
|
model_type
|
str
|
Type of model, either 'ising' or 'binary'. This determines how the binary states are interpreted and how the energy is calculated. 'ising' models use spin values {-1, +1}, while 'binary' models use binary values {0, 1}. |
'ising'
|
Notes
- Energies are computed by mapping binary states
{0,1}to spin values{-1,+1}internally. - Brute-force methods such as
get_all_energiesscale as O(2^n) and are intended only for small systems.
Source code in src/qemcmc/model/energy_model.py
get_initial_states ¶
Generates a list of random initial states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_initial_states
|
int
|
The number of initial states to generate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of random initial states. |
Source code in src/qemcmc/model/energy_model.py
get_ground_state ¶
Finds an approximate ground state using Simulated Annealing.
Source code in src/qemcmc/model/energy_model.py
calculate_energy ¶
Calculate the energy of a given state for an arbitrary-order Ising/binary model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
array - like(str, list, tuple, array)
|
State configuration. Can be: - Binary: "011", [0,1,1], (0,1,1), etc. - Spin: [-1,1,1], (-1,1,1), etc. |
required |
couplings
|
list of numpy arrays
|
List of coupling tensors where: - 1D arrays represent linear terms (h_i) - 2D arrays represent quadratic terms (J_ij) - 3D arrays represent cubic terms, etc. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Total energy of the state
|
|
Source code in src/qemcmc/model/energy_model.py
get_subgroup_couplings ¶
Calculates local couplings for a subgroup of spins.
Spins outside the specified subgroup are treated as frozen constants, and their values are absorbed into the couplings of the subgroup. This is useful for calculating local effective Hamiltonians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subgroup
|
List[int]
|
A list of indices of the spins in the subgroup. |
required |
current_state
|
str
|
The current state of the full system, as a binary string. |
required |
coupling_weights
|
List[float]
|
Optional weights for the couplings. This can be used to effectively remove certain couplings from the proposal (e.g., constraints) by setting their weight to 0. It is important not to normalize the couplings after applying these weights. |
None
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
A new list of coupling tensors for the subgroup. |
Notes
It might seem off to do the reweighting at this point, but here are reasons why I [SF] did it!
Basically, when you get the subgroup couplings, the terms jumble up, so the returned local
coupling list necessarily does not respect the order etc. of the different terms in the original.
Source code in src/qemcmc/model/energy_model.py
calculate_alpha ¶
Compute alpha = sqrt(n) / sqrt(sum of squares of UNIQUE coupling coefficients), assuming coupling tensors are symmetric representations.
Any non-symmetric 2-body input raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of spins. |
required |
couplings
|
list[ndarray]
|
Couplings to use. Defaults to self.couplings if not provided. |
None
|
eps
|
float
|
Small threshold to avoid division by zero. |
1e-15
|
Returns:
| Type | Description |
|---|---|
np.ndarray :
|
An array of normalising factors for each term in the couplings list. |
Source code in src/qemcmc/model/energy_model.py
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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
get_energy ¶
Returns the energy of a given state
Source code in src/qemcmc/model/energy_model.py
get_all_energies ¶
Calculate the energies for all possible spin states. This method generates all possible spin states for the system and calculates the energy for each state.
Returns:
| Type | Description |
|---|---|
np.ndarray :
|
An array containing the energies of all possible spin states. |
Source code in src/qemcmc/model/energy_model.py
get_lowest_energies ¶
Retrieve the lowest energy states and their degeneracies. This method computes all possible energies and then finds the specified number of lowest energy states along with their degeneracies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_states
|
int
|
|
required |
return_configurations
|
bool
|
|
False
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
|
Notes
This method is intended for small instances due to its brute-force nature, which is extremely memory intensive and slow.
Source code in src/qemcmc/model/energy_model.py
find_lowest_values ¶
Find the lowest unique values in an array and their degeneracies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
|
required |
num_values
|
int
|
|
5
|
Returns:
| Type | Description |
|---|---|
Tuple[lowest_values(ndarray), degeneracy(ndarray)]
|
|
Source code in src/qemcmc/model/energy_model.py
get_lowest_energy ¶
Calculate and return the lowest energy from all possible energies. This method uses a brute force approach to find the lowest energy, making it extremely memory intensive and slow. It is recommended to use this method only for small instances.
Returns:
| Name | Type | Description |
|---|---|---|
float |
The lowest energy value.
|
|
Notes
If the lowest energy has already been calculated and stored
in self.lowest_energy, it will return that value directly
to save computation time.
Source code in src/qemcmc/model/energy_model.py
get_boltzmann_factor ¶
Get un-normalised boltzmann probability of a given state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
configuration of spins for which probability is to be calculated |
required |
beta
|
float
|
inverse temperature (1/T) at which the probability is to be calculated. |
1.0
|
Returns:
| Type | Description |
|---|---|
float corresponding to the un-normalised boltzmann probability of the given state.
|
|
Source code in src/qemcmc/model/energy_model.py
get_boltzmann_factor_from_energy ¶
Get un-normalized Boltzmann probability for a given energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
E
|
float
|
Energy for which the Boltzmann factor is to be calculated. |
required |
beta
|
float
|
Inverse temperature (1/T) at which the probability is to be calculated. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The un-normalized Boltzmann probability for the given energy. |
Source code in src/qemcmc/model/energy_model.py
ConstraintModel ¶
Bases: EnergyModel
A subclass of EnergyModel that incorporates a constraint function to define valid configurations.
The constraint function takes a state as input and returns True if the state is valid (satisfies the constraint) and False otherwise. The energy of invalid states is set to infinity, effectively excluding them from the Boltzmann distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of spins in the model. |
required |
constraint_couplings
|
list[ndarray]
|
List of coupling tensors (numpy arrays) defining the constraint. |
required |
constraint_signs
|
list[float]
|
Sign convention(s) for the constraint couplings. |
required |
couplings
|
list[ndarray]
|
List of coupling tensors (numpy arrays) defining the energy function. |
required |
constraint_func
|
Callable[[str], bool]
|
A function that takes a state (string representation of spin configuration) and returns True if the state satisfies the constraint, and False otherwise. |
required |
name
|
str
|
Optional label for the model (used in plotting / logging). |
required |
cost_function_signs
|
list[float]
|
Sign convention(s) used by downstream components (e.g. proposal/acceptance conventions). |
required |
model_type
|
str
|
Type of model, either 'ising' or 'binary'. This determines how the binary states are interpreted and how the energy is calculated. 'ising' models use spin values {-1, +1}, while 'binary' models use binary values {0, 1}. |
required |
Notes
- The energy of any state that does not satisfy the constraint is set to infinity, which means such states will have zero probability in the Boltzmann distribution.
- This class can be used to model systems with hard constraints on the configurations, such as certain combinatorial optimization problems or physical systems with forbidden states.
Source code in src/qemcmc/model/constraint_model.py
get_initial_states_constraint ¶
Generates a list of random initial states that satisfy the constraint function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_initial_states
|
int
|
The number of initial states to generate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of random initial states that are valid according to the constraint. |
Source code in src/qemcmc/model/constraint_model.py
get_constraint_energy ¶
Calculate the energy contribution from the constraint couplings for a given state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
The state for which to calculate the constraint energy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The energy contribution from the constraint couplings for the given state. |
Source code in src/qemcmc/model/constraint_model.py
get_total_energy ¶
Calculate the total energy of a given state, including both the regular energy and the constraint energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
The state for which to calculate the total energy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The total energy of the given state, including contributions from both the regular couplings and the constraint couplings. |
Source code in src/qemcmc/model/constraint_model.py
ModelMaker ¶
Utility class for constructing standard Ising energy models used in simulations and experiments.
This class constructs predefined random energy models used for testing
and experimentation. Depending on the chosen model_type, it generates
coupling tensors and initialises an :class:EnergyModel instance.
Source code in src/qemcmc/model/model_maker.py
make_fully_connected_binary ¶
Transforms the existing Ising couplings into an mathematically equivalent QUBO model via s = 2x - 1.
Source code in src/qemcmc/model/model_maker.py
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.
Source code in src/qemcmc/circuits.py
MCMCState
dataclass
¶
Represents a single step in an MCMC trajectory.
Stores the proposed configuration, whether it was accepted by the Metropolis rule, its energy, and the position of the step in the chain.
MCMCChain
dataclass
¶
Container for the sequence of states produced during an MCMC run.
This class records all proposed states, tracks accepted configurations, and provides helper methods for extracting trajectories, energies, and empirical distributions from the Markov chain.
Source code in src/qemcmc/utils/helpers.py
SpectralGap ¶
Bases: Runner
Class that finds the spectral gap, and the acceptance and proposal matrices for a given mcmc.
Source code in src/qemcmc/spectralgap.py
find_acceptance_matrix ¶
Function to find the acceptance matrix for a given model instance.
Returns: A (np.ndarray): The acceptance matrix for the mcmc
Source code in src/qemcmc/spectralgap.py
find_proposal_matrix_local ¶
Function to find the proposal matrix for a given local chain.
Returns: Q (np.ndarray): The Q matrix for local proposal
Source code in src/qemcmc/spectralgap.py
find_proposal_matrix_uniform ¶
Function to find the proposal matrix for a given uniform chain.
Returns: Q (np.ndarray): The Q matrix for uniform proposal
Source code in src/qemcmc/spectralgap.py
find_proposal_matrix_quantum ¶
Function to find the proposal matrix for a given QeMCMCChain object.
Returns: Q (np.ndarray): The Q matrix for quantum proposal
Source code in src/qemcmc/spectralgap.py
find_proposal_matrix ¶
Function to find the proposal matrix for a given mcmc. This is not done by brute force
Source code in src/qemcmc/spectralgap.py
find_spectral_gap ¶
Function to find the spectral gap of a given mcmc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
The acceptance matrix for the mcmc (optional, if not given, will be calculated) |
None
|
|
Q
|
The proposal matrix for the mcmc (optional, if not given, will be calculated) |
None
|
Source code in src/qemcmc/spectralgap.py
CoarseGraining ¶
CoarseGraining class to generate partitions of spins for quantum proposals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of spins in the system. |
required |
subgroups
|
list[list[int]]
|
A list of subgroups, where each subgroup is a list of spin indices. If None, the entire set of spins is treated as one subgroup. |
None
|
subgroup_probs
|
list[float]
|
A list of probabilities corresponding to each subgroup, used for weighted random selection. Must sum to 1. If None, subgroups are selected uniformly at random. |
None
|
repeated
|
bool
|
If True, then multiple subgroups are run on the quantum computer in serial, if not then only one subgroup is selected at random and run on the quantum computer. Default is |
True
|
Source code in src/qemcmc/coarse_grain.py
sample ¶
Randomly samples a subgroup according to the specified probability distribution.
get_partitions ¶
Returns partitions of spins for sequential quantum updates.
If the user provided explicit subgroups at initialisation, those are sampled accordingly.
returned directly (all if repeated=True, otherwise just the first).
If no subgroups were specified, random disjoint partitions of
approximate size n/m are generated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
int
|
The number of partitions to generate. Ignored if user-specified subgroups are provided. |
required |
Source code in src/qemcmc/coarse_grain.py
get_random_state ¶
Generate a random state for a given number of spins.
Parameters: num_spins (int): The number of spins in the system. Returns: str: A bitstring representing the random state.
Source code in src/qemcmc/utils/helpers.py
get_all_possible_states ¶
Returns all possible binary strings of length n=num_spins
Paremeters: num_spins: n length of the bitstring Returns: list: A list of all possible binary strings of length num_spins.