Package: ising-animate
ising_animateA Python Package to easily generate animations of theIsing Modelusing theMetropolis Algorithm, the most
commonly used Markov Chain Monte Carlo method to calculate estimations for this system.InstallationBe sure to have Python 3.6 or newer installed on your machine. Then you can simply use pip to install the package and its dependencies.pip install ising_animateUsageCommand Line ToolThis package can be used as a command line tool to generate the desired animations. For instance, the animation above was created using the commandpython -m ising_animateYou can specify the desired size, initial state, temperature or field using some command line options. For example, the commandpython -m ising_animate --size 256 --temp 1.5 --field 1.0 --init-state "down" --time-seriesyieldsFor a full description of all the available options, type inpython -m ising_animate --help.ImportWhen imported, there are four classes of objects that can be used to create custom animations:Ising: just the core implementation of the Ising Model, no animation;AnimatedIsing: an animation of the Ising Model with both temperature and external magnetic field held at fixed values;CoolingAnimatedIsing: an animation of the Ising Model with the temperature droping (or raising) exponentially to a target value, at a given rate;DynamicAnimatedIsing: an animation of the Ising Model with temperature and external magnetic field both described by given functions of time.The usage of all of them are very similar. You just have to create an instance with the desired arguments...fromising_animateimportDynamicAnimatedIsingfrommathimportsinframes=100dynamic=DynamicAnimatedIsing(shape=(256,256),# the shape of the latticetemp=lambdat:1.0+0.3*t,# temperature as a function of timefield=lambdat:sin(t),# external magnetic field as a function of timetime_series=True,# plot evolution of physical quantities over timeinterval=100,# interval of each frameframes=frames,# amount of frames in the animation)and the animation itself is now given by a matplotlibFuncAnimationobject stored atdynamic.animation. This object has asavemethod of which the most important arguments is the output filename and the fps of the animation. The fps can be chosen as you wish,
but the natural value is 1000 (the amount of milliseconds in one second) divided by the interval of each frame. So, in that case, fps is 10.dynamic.animation.save("outfile.gif",fps=10)Another useful feature of the save method is the possibility to pass a progress callback function that
will be called after drawing each frame, with the count of already drawn frames and the total number of frames on
the animation. This makes easy to use a package like progressbar2 to show the progress in a progress bar.importprogressbarwithprogressbar.ProgressBar(max_value=frames)asbar:dynamic.animation.save("outfile.gif",fps=10,progress_callback=lambdai,n:bar.update(i),)To install progressbar2, use the following command in a terminal.pip install progressbar2To view a full description of each class, take a look at thefull documentation.ExamplesThere is a subpackageising_animate.exampleswith some usage examples of usage of this library. The example
above is one of them, and can be run usingpython -m ising_animate.examples.dynamicAnother interesting one can be run withpython -m ising_animate.examples.heatingwhich yields two plots with the dependency of the mean energy and the specific heat density with the temperature.
This example is a good illustration of the phase thansition that occurs at the temperature of 2.27, in energy units.