sampler
qemcmc.sampler ¶
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. |