API Docs

MCMC : Markov Chain Monte Carlo Routines

mcmc provides routines for performin Markov Chain Monte Carlo

MCFF.mcmc.mcmc_generator(initial_state, steps, T, stepsize=1000, energy_difference=energy_difference)

Yields the state after each MCMC step. Performs steps monte carlo steps each of size stepsize starting from initial_state at temperature T.

Parameters:
  • initial_state (array_like) – Numpy array of shape (N,N) with values +1,-1

  • steps (int) – The number of steps to take.

  • T (float) – The temperature at which to perform the simulation.

  • stepsize (int, default = 1000) – How many times to try to flip a pixel between for each step.

  • energy_difference (function(state, site), default = ising_model.energy_difference) – A function that gives the energy change from flippings site = (i, j)`of `state.

Yields:

np.array – The final state.

MCFF.mcmc.mcmc_original(initial_state, steps, T, rng=np.random.default_rng())

Return the state after performing steps monte carlo steps starting from initial_state at temperature T.

This is the original version of the algorithm, written in notebook 03.

Parameters:
  • initial_state (array_like) – Numpy array of shape (N,N) with values +1,-1

  • steps (int) – The number of steps to take.

  • T (float) – The temperature at which to perform the simulation.

  • rng (numpy.random._generator.Generator, default = np.random.default_rng()) – Optionally pass in the rng to be used, useful to get reproducable answers.

Returns:

The final state.

Return type:

np.array

Ising_Model : Ising Model Routines

ising_model provides functions specific to the 2D ising model such as computing its energy and generating special states.

States are represented by NxM numpy arrays with values +/-1. These functions are intended to be used with a markov chain monte carlo routine to sample from the thermal ensemble of the 2d Ising model.

MCFF.ising_model.all_down_state(N)

The NxN all down state of the Ising model.

MCFF.ising_model.all_up_state(N)

The NxN all up state of the Ising model.

MCFF.ising_model.energy(state)

Compute the energy of a state of the Ising Model with open boundary conditions.

Parameters:

state (array_like) – A NxM array containing only the values +1 and -1

Returns:

The interaction energy per site.

Return type:

float64

MCFF.ising_model.energy_difference(state, site)

The change in energy if we flipped site of state

MCFF.ising_model.energy_numpy(state)

Compute the energy of a state of the Ising Model with open boundary conditions.

An alternate implementation of energy using Numpy array operations, used for comparison and correctness checks.

Parameters:

state (array_like ()) – A 2D array containing only the values +1 and -1

Returns:

The interaction energy per site.

Return type:

float64

MCFF.ising_model.random_state(N, magnetisation=0.5, rng=np.random.default_rng())

Return the a random NxN state of the Ising model.

Parameters:
  • N (int) – The returned state will have shape (N,N)

  • magnetisation (int, default = 0.5) – What proportion of the values will be +1

  • rng (numpy.random._generator.Generator, default = np.random.default_rng()) – Optionally pass in the rng to be used, useful to get reproducable answers.

Returns:

A random NxN state.

Return type:

np.array

MCFF.ising_model.show_state(state, ax=None)

Plot an Ising state to axis or make a new figure to plot to