{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMWdpe4GJ0m/pneJIfCBsn/"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"HwvaNgJ578Ua"},"source":["# MCMC simulation of the Ising model\n","\n","The goal of the tutorial is to implement the Metropolis algorithm to sample configurations from the Ising model on the discrete torus in dimension $d=2$."]},{"cell_type":"code","metadata":{"id":"1SICXgNjpQYO","executionInfo":{"status":"ok","timestamp":1700426991810,"user_tz":-60,"elapsed":6,"user":{"displayName":"Julien Reygner","userId":"06465841509771183939"}}},"source":["import numpy as np\n","import matplotlib.pyplot as plt"],"execution_count":1,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"az9yXzVw9mhh"},"source":["# 1. The case $\\beta=0$\n","\n","A configuration is represented by an array of size $N \\times N$. Write a function ising_0(N) which returns such an array with cells containing spins independently uniformly distributed in $\\{-1,1\\}$."]},{"cell_type":"code","metadata":{"id":"13vhUcUm8qUe","executionInfo":{"status":"ok","timestamp":1700426996768,"user_tz":-60,"elapsed":244,"user":{"displayName":"Julien Reygner","userId":"06465841509771183939"}}},"source":["def ising_0(N):\n"," return np.sign(np.random.randn(N,N))\n"," # many other solutions are possible!"],"execution_count":2,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"69xFZVXe_Kt2"},"source":["The function plot_configuration(conf) takes in argument a configuration and plots a figure in which spins $+$ are represented by a black pixel and spins $-$ are represented by a white pixel."]},{"cell_type":"code","metadata":{"id":"tmJ_1I7l-hps","colab":{"base_uri":"https://localhost:8080/","height":406},"executionInfo":{"status":"ok","timestamp":1700427009604,"user_tz":-60,"elapsed":1043,"user":{"displayName":"Julien Reygner","userId":"06465841509771183939"}},"outputId":"8d97f7a8-b2c2-41b2-b728-9bca68c48ce1"},"source":["def plot_configuration(conf):\n"," fig, ax = plt.subplots()\n"," ax.matshow(conf,cmap=\"Greys\",vmin=-1,vmax=1)\n"," ax.set_axis_off()\n","\n","plot_configuration(ising_0(1000))"],"execution_count":3,"outputs":[{"output_type":"display_data","data":{"text/plain":["