qemcmc.utils¶
Submodules¶
Classes¶
Functions¶
|
|
|
Generate a random state for a given number of spins. |
|
Returns all possible binary strings of length n=num_spins |
|
Validate coarse-graining subgroups. |
Package Contents¶
- class qemcmc.utils.MCMCState[source]¶
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.
- bitstring: str¶
- accepted: bool¶
- energy: float = None¶
- position: int = None¶
- class qemcmc.utils.MCMCChain(states: List[MCMCState] | None = None, name: str | None = 'MCMC')[source]¶
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.
- name = 'MCMC'¶
- property states¶
- property current_state¶
- property accepted_states: List[str]¶
- qemcmc.utils.plot_chains(chains: list[MCMCChain], color: str, label: str, plot_individual_chains: bool = True)[source]¶
- qemcmc.utils.get_random_state(num_spins: int) str[source]¶
Generate a random state for a given number of spins.
- Parameters:
num_spins (int) – The number of spins in the system.
- Returns:
A bitstring representing the random state.
- Return type:
str
- qemcmc.utils.get_all_possible_states(num_spins: int) list[source]¶
Returns all possible binary strings of length n=num_spins
- Paremeters:
num_spins: n length of the bitstring
- Returns:
A list of all possible binary strings of length num_spins.
- Return type:
list
- qemcmc.utils.validate_subgroups(subgroups, subgroup_probs, n_spins)[source]¶
Validate coarse-graining subgroups.
- Requirements:
subgroups is a non-empty list of non-empty sequences
each element is an int in [0, n-1]
each subgroup has no duplicate indices
every spin from 0 to n-1 appears in at least one subgroup
- Raises:
ValueError/TypeError –