Skip to content

This package provides an implementation of the Metropolis algorithm for simulating spin configurations.

License

Notifications You must be signed in to change notification settings

San-WierPa/2d_Ising_incl_Binder

Repository files navigation

2d_Ising_incl_Binder

Python package

This package provides an implementation of the Metropolis algorithm for simulating spin configurations.

Installation

You can install the package using pip:

pip install .

Usage

Here’s an example of how to use the package to perform Monte Carlo simulations:

import numpy as np
from src.py_ising_2d import Config, mc_metro_random, initial_lattice, calc_magnetisation

# Define lattice size and configuration
n = 4
config = Config(n=n)

# Initialize spin configuration
spin_config = initial_lattice(n)

# Perform Monte Carlo simulation
for t_index, temp in enumerate(config.T):
    beta = 1.0 / temp

    # Equilibrate the system
    for _ in range(config.eq_steps):
        mc_metro_random(spin_config, n, beta)

    # Perform Monte Carlo steps
    for _ in range(config.mc_steps):
        mc_metro_random(spin_config, n, beta)
        mag = calc_magnetisation(spin_config)

        config.M[t_index] += mag
        config.Chi[t_index] += mag * mag

    # Normalize results
    config.M[t_index] *= config.norm_1
    config.Chi[t_index] = (config.Chi[t_index] * config.norm_1 - (config.M[t_index] ** 2)) * beta

print(f"Magnetizations: {config.M}")
print(f"Susceptibilities: {config.Chi}")

Plotting results

from src.py_ising_2d.visualisation import plot_results

# Plot results
plot_results(config.T, config.M, config.Chi, n)

Running tests

python -m unittest discover tests

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

About

This package provides an implementation of the Metropolis algorithm for simulating spin configurations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages