qemcmc.utils.helpers

Classes

MCMCState

Represents a single step in an MCMC trajectory.

MCMCChain

Container for the sequence of states produced during an MCMC run.

CoarseGrainingConfig

Functions

plot_chains(chains, color, label[, plot_individual_chains])

get_random_state(→ str)

Generate a random state for a given number of spins.

get_all_possible_states(→ list)

Returns all possible binary strings of length n=num_spins

magnetization_of_state(→ float)

Parmeters:

dict_magnetization_of_all_states(→ dict)

Returns magnetization for all unique states

hamming_dist(str1, str2)

hamming_dist_related_counts(num_spins, ...)

energy_difference_related_counts(num_spins, ...)

validate_subgroups(subgroups, subgroup_probs, n_spins)

Validate coarse-graining subgroups.

Module Contents

class qemcmc.utils.helpers.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[source]
accepted: bool[source]
energy: float = None[source]
position: int = None[source]
class qemcmc.utils.helpers.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'[source]
add_state(state: MCMCState)[source]
property states[source]
get_accepted_energies()[source]
get_current_energy_array()[source]
get_pos_array()[source]
get_current_state_array()[source]
get_all_energies()[source]
property current_state[source]
property accepted_states: List[str][source]
get_list_markov_chain() List[str][source]
get_accepted_dict(normalize: bool = False, until_index: int = -1)[source]
qemcmc.utils.helpers.plot_chains(chains: list[MCMCChain], color: str, label: str, plot_individual_chains: bool = True)[source]
qemcmc.utils.helpers.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.helpers.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.helpers.magnetization_of_state(bitstring: str) float[source]
Parmeters:

bitstring: for eg: ‘010’

Returns:

Magnetization for the given bitstring

Return type:

float

qemcmc.utils.helpers.dict_magnetization_of_all_states(list_all_possible_states: list) dict[source]

Returns magnetization for all unique states

Parameters:

list_all_possible_states

Returns:

A dictionary mapping each state to its magnetization value.

Return type:

dict

qemcmc.utils.helpers.hamming_dist(str1, str2)[source]
class qemcmc.utils.helpers.CoarseGrainingConfig[source]
subgroups: list[list[int]][source]
subgroup_probs: list[float][source]
qemcmc.utils.helpers.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