TFIMSimulation class
- class TFIMSimulation(size=10, beta=0.4, h=0.05, steps=100)
A class to simulate the Transverse Field Ising Model (TFIM) on a two-dimensional lattice. The TFIM is a model of magnetism in statistical mechanics.
- Parameters:
size (int, optional) – The width and height of the square lattice. Defaults to 10.
beta (float, optional) – The inverse temperature parameter for the simulation. Defaults to 0.4.
h (float, optional) – The transverse field strength applied to the system. Defaults to 0.05.
steps (int, optional) – The number of Monte Carlo steps to perform in the simulation. Defaults to 100.
- size
The size of the lattice (size x size).
- beta
The inverse temperature parameter for the simulation.
- h
The transverse field strength.
- steps
The number of simulation steps to run.
- lattice
The lattice representing the spins, initialized randomly.
- initialize_lattice()
Initializes the lattice to a random state where each spin is either up or down with equal probability.
- Returns:
A square lattice of spins.
- Return type:
torch.Tensor
- tfim_step()
Performs a single Monte Carlo step in the TFIM simulation, potentially flipping each spin based on the Metropolis-Hastings algorithm.
- run_simulation()
Runs the TFIM simulation for the number of steps specified in the constructor.
- plot_lattice()
Plots the current state of the lattice using matplotlib, showing the spins as a heatmap.
Example Usage
The following example sets up a TFIM simulation with a lattice of size 10x10, runs it for 100 steps, and then plots the final configuration of spins:
# Initialize the TFIM simulation
sim = TFIMSimulation(size=10, beta=0.4, h=0.05, steps=100)
# Run the simulation
sim.run_simulation()
# Plot the final lattice configuration
sim.plot_lattice()
This will produce a plot showing the spin configuration of the lattice after running the specified number of Monte Carlo steps.