Jekyll2023-09-16T07:59:53-07:00https://shiling42.github.io/feed.xmlShiling Liang PhD student in Physics@LBS, EPFLShiling Liang 梁师翎shiling.liang@epfl.chCoding with GPT-4: Simulating Emergent Phenomena in Complex Systems2023-03-21T00:00:00-07:002023-03-21T00:00:00-07:00https://shiling42.github.io/posts/2023/03/GPT-simulator<blockquote>
<p>This article was generated by ChatGPT-4.</p>
</blockquote>
<h2 id="introduction">Introduction</h2>
<p>Today we bring you a unique online interactive physics system simulation project, which uses HTML and JavaScript code generated by GPT-4 to implement a series of visual simulations that allow us to better understand physics, complex systems, and emergent phenomena.</p>
<p>In this project, we will show you some exciting simulations, including the XY model, the Vicsek bird flocking model, phase separation, and particle repulsion. These simulations all use code generated by GPT-4, allowing us to explore the physical world intuitively and understand various physical processes and emergent phenomena.</p>
<p>In addition, with the help of GPT-4, the natural language processing tool, programming becomes simpler, allowing more people to participate in project development. Even people without interface development experience can quickly develop such projects by commanding GPT-4 in ordinary language.</p>
<p>In this project, we will guide you through how to use GPT-4 technology to generate code for interactive physics system simulations, allowing you to experience the charm of physics and complex systems. Let’s start this exploration journey together!</p>
<h2 id="vicsek-model-of-flocking"><a href="https://shilingliang.com/web-simulator-by-GPT4/interactive_vicsek.html">Vicsek Model of Flocking</a></h2>
<p>Today, we are excited to introduce a cutting-edge, online interactive physics system simulation project that leverages the power of GPT-4-generated HTML and JavaScript code to create a suite of visually engaging simulations, aimed at enhancing our understanding of physics, complex systems, and emergent phenomena.</p>
<p>In this project, we showcase captivating simulations such as the XY model, the Vicsek bird flocking model, phase separation, and particle repulsion. Each of these simulations is powered by code generated by GPT-4, enabling us to explore the physical world in an intuitive manner and gain insights into various physical processes and emergent phenomena.</p>
<p>Furthermore, GPT-4’s natural language processing capabilities simplify the programming process, making it more accessible for a wider audience to contribute to the project’s development. Individuals without prior experience in interface development can swiftly create projects by providing GPT-4 with plain-language instructions.</p>
<p>Throughout this project, we will walk you through the process of utilizing GPT-4 technology to generate code for interactive physics system simulations, offering you the opportunity to delve into the fascinating world of physics and complex systems. Let’s embark on this thrilling journey of exploration together!</p>
<iframe src="https://shilingliang.com/web-simulator-by-GPT4/interactive_vicsek.html" width="780" height="500" allowfullscreen=""></iframe>
<h2 id="xy-model"><a href="https://shilingliang.com/web-simulator-by-GPT4/XY_model.html">XY Model</a></h2>
<p>The XY model originates from condensed matter physics and mainly studies a particle system on a two-dimensional plane. These particles can be imagined as compasses, distributed on the plane, and each particle has a direction. The core of this model lies in the interaction between particles: each particle tends to maintain the same direction as neighboring particles. This interaction forms an interesting balance, where particles strive to maintain consistency while responding to the influence of other particles.</p>
<p>In the XY model, we can observe a fascinating emergent phenomenon: when the interaction between particles reaches a certain degree, the entire system will spontaneously form an ordered state, and the particles will point in roughly the same direction. This ordered state reflects the self-organizing behavior inside the system and is a typical phenomenon in complex systems.</p>
<p>The XY model also contains a very interesting and important physical phenomenon - the Berezinskii–Kosterlitz–Thouless (BKT) phase transition. The discovery of the KT phase transition brought revolutionary breakthroughs to the theory of phase transitions, and even led to the Nobel Prize in Physics being awarded to physicists Kosterlitz and Thouless in 2016.</p>
<p>Unlike the first- and second-order phase transitions we are familiar with, such as water turning into ice or water vapor, the KT phase transition is a topological phase transition. This means that it does not involve a sudden change in the density, magnetism, or other physical properties of matter, but rather involves a change in the internal topological structure of the system. In the XY model, this topological structure is manifested as vortices and antivortices, which can be understood as local rotational structures with different rotation directions.</p>
<p>When the temperature is low, vortices and antivortices form a stable paired state, and their mutual attraction makes the system present an ordered state. However, when the temperature rises to a critical point, vortices and antivortices begin to dissociate, and the degree of order in the system gradually decreases. This is the process described by the KT phase transition.</p>
<p>Through the XY model in the online interactive physics system simulation project, we can intuitively observe the process of the KT phase transition and understand how this unique topological phase transition occurs in complex systems. This is undoubtedly an attractive learning path for science enthusiasts who want to deepen their understanding of phase transitions, topological structures, and emergent phenomena.</p>
<centre>
<iframe src="https://shilingliang.com/web-simulator-by-GPT4/XY_model.html" width="780" height="650" allowfullscreen=""></iframe>
</centre>
<h2 id="phase-separation"><a href="https://shilingliang.com/web-simulator-by-GPT4/phase_separation.html">Phase Separation</a></h2>
<p>Phase separation is a widely existing phenomenon in nature, which refers to the spontaneous separation of different types of components into regions of a single component in a mixed system under certain conditions. This process is involved in many chemical, physical, and biological systems, such as oil-water mixtures, cooling and separation of alloys, and distribution of lipid molecules on cell membranes.</p>
<p>The concept closely related to phase separation is pattern formation, which describes the self-organizing phenomenon of spatial structure under certain conditions. This phenomenon is often accompanied by the appearance of local structure and order. In the process of phase separation, we can observe a series of complex pattern formation phenomena, such as bubble-like structures, stripe-like structures, etc. These patterns can be understood as stable structures formed by the system in the process of trying to reduce energy.</p>
<p>In the online interactive physics system simulation project, the phase separation model uses a simplified two-dimensional particle system to simulate the phase separation phenomenon. Although this model is simplified, it can intuitively demonstrate the basic mechanisms of phase separation, such as like attraction, unlike repulsion, and random motion between particles.</p>
<iframe src="https://shilingliang.com/web-simulator-by-GPT4/phase_separation.html#container" width="780" height="550"></iframe>
<h2 id="physics-visualization-platform"><a href="https://shilingliang.com/web-simulator-by-GPT4">Physics Visualization Platform</a></h2>
<p>In this ChatGPT-assisted project website, we strive to present an engaging and educational online physics visualization platform. Through this platform, users can personally interact with a variety of physical phenomena and complex systems, gaining a more intuitive and vivid understanding of the principles underlying these phenomena.</p>
<p>Our project website features multiple physics simulation examples generated by GPT-4, such as the Vicsek model, the XY model, and the phase separation model. These models are designed to help users comprehend the operational principles and emergent phenomena of complex systems. Additionally, the website offers a series of mouse-interactive models, enabling users to experience the allure of physical phenomena through real-time interaction.</p>
<h2 id="coding-with-gpt-4">Coding with GPT-4</h2>
<p>To conclude this article, let’s discuss how this project was brought to life through ChatGPT. In implementing the phase separation project, I didn’t specify any particular model. Instead, I provided the following requirements:</p>
<ul>
<li>Implement a visual phase separation model using HTML.</li>
<li>Add repulsion to the model to prevent particle aggregation.</li>
<li>Handle boundary conditions.</li>
<li>Introduce temperature as a parameter.</li>
<li>Add sliders to control all parameters.</li>
</ul>
<p>Based on these requirements, ChatGPT generated the corresponding HTML and JavaScript code, creating an interactive physics simulation project (there were five or six conversations from the initial command to the generation of a functional model that could display phenomena, followed by more detailed discussions with ChatGPT to refine the page’s appearance). Throughout this process, GPT-4 exhibited an incredible ability to understand my project’s core objectives based on my requirements and generate the appropriate code to fulfill them. It is worth noting, however, that there is a limit to the length of code output by ChatGPT. If the output is interrupted, you can copy and paste the end of the output code and ask GPT to continue writing, ensuring a seamless code-writing process.</p>
<p>Although I’m not well-versed in JavaScript syntax details, I was able to understand how specific calculations were implemented in the physics portion by examining the code (as a pseudo-code reader), which allowed me to verify its accuracy. Overall, correctness checks still require some coding experience, but developers don’t need to know every syntax detail.</p>
<p>For the interface layer, the logic is visually apparent, so it can also be checked. If errors are detected, feedback can be given directly, and GPT-4 possesses a robust self-checking capability.</p>
<p>In collaboration with ChatGPT, we have successfully developed a fun and practical online interactive physics system simulation project. This project not only enables us to grasp complex physical phenomena intuitively but also showcases GPT-4’s enormous potential in code generation and project implementation. Furthermore, GPT-4’s powerful features have saved significant time and effort during the development process, making it possible for physicists and novices alike to swiftly create high-quality visualization and interactive projects.</p>
<p>In conclusion, while GPT-4 cannot currently replace all human work, it can significantly streamline the development process and empower beginners to accomplish tasks that were previously unattainable. In the future, we eagerly anticipate deeper collaboration with artificial intelligence technologies like GPT-4 to explore more innovative applications and solutions.</p>Shiling Liang 梁师翎shiling.liang@epfl.chThis article was generated by ChatGPT-4.Thermophroesis as an emergent phenomenon: the role of internal states2023-01-02T00:00:00-08:002023-01-02T00:00:00-08:00https://shiling42.github.io/posts/2023/01/Thermophoresis<blockquote>
<ul>
<li>In our recent paper, we showed that thermophoresis can be an emergent phenomenon from chemical reaction systems. This blog is a <strong>lay summary</strong> of our work.</li>
</ul>
</blockquote>
<h2 id="what-is-thermophoresis">What is thermophoresis?</h2>
<p><strong>After establishing a temperature gradient in a solution system, we may observe the accumulation of solute particles on the cold or warm side</strong>. This phenomenon is known as thermophoresis. Its exact microscopic origin is still under debate. In our work<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>, we propose a simple and intuitive mechanism to explain this phenomenon, which relies on the correlation of the energy-diffusion properties of the different states of the particles. It is based on a simple idea: <strong>particles stay longer where diffusion is slower, and temperature can modulate the transport property of particles.</strong></p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="/files/thermophoresis/热泳.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">The phenomenon of inhomogeneous concentration gradients driven by a temperature gradient.</td>
</tr>
</tbody>
</table>
<h2 id="from-einsteins-diffusion-relation-to-thermophoresis">From Einstein’s diffusion relation to thermophoresis</h2>
<p>For the understanding of thermophoresis we can go back to the basic Einstein relation of diffusion:</p>
\[D= \frac{T}{\gamma}\propto T R^{-1}\]
<p>The diffusion coefficient is proportional to the temperature divided by the damping constant, and the larger the particle the greater the damping (damping is proportional to particle size), which leads to an inverse relationship between diffusion coefficient and particle size as shown above.</p>
<p>Why do we mention the diffusion coefficient? Because the thermophoretic mechanism we propose here is rooted in nonhomogeneous diffusion and is simply based on a simple concept:</p>
<blockquote>
<p><strong>Particles tend to stay in the slow diffusion region for a longer time</strong></p>
</blockquote>
<p>This is quite intuitive idea. The diffusion process is essentially the random walk of microscopic particles, and where the random walk is slow, the particles will wander around for a longer time.</p>
<p>Then the emergence of thermophoresis is natural: the diffusion coefficient depends on temperature. Therefore, let’s look at the first term of Einstein’s relation, $\boxed{T}R^{-1}$. Isn’t it exactly the temperature? To put it more bluntly, this term tells us that <em>particles diffuse faster in hot places and slower in cold places.</em></p>
<p>The temperature term in Einstein’s relation gives us a direct Soret coefficient:</p>
\[S_T^0=\frac{1}{T}\]
<p>However, there are two issues with this simple result.</p>
<ol>
<li>
<p>This coefficient is always positive, which means that it can only indicate the tendency of accumulation in the cold region, namely the thermophoretic phenomenon. In contrast, it is observed experimentally that solute particles can move to the hot region.</p>
</li>
<li>
<p>This Soret coefficient is two orders of magnitude smaller than the experimentally measured values.</p>
</li>
</ol>
<p>So we need to extract additional information from the Einstein relation. If we look at the Einstein relation again, $D\propto T R^{-1}$, there is a term related to the size of the particle, so can we derive thermophoresis from this term? The answer is yes, and this is the focus of our paper: chemical thermophoresis.</p>
<h2 id="chemical-thermophoresis">Chemical thermophoresis</h2>
<p>To understand the thermophoresis from thermoresponsive particle size, we can start with a simple and intuitive example which is the foldable polymer</p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="/files/thermophoresis/聚合物反应.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">Folded and unfolded states of a polymer.</td>
</tr>
</tbody>
</table>
<p>A polymer can be in both folded and unfolded states. These two states have different free energies, taking into account the interactions between the various parts of the long chain and the interaction with the solvent molecules. Also, it is straightforward that <strong>the unfolded state of the polymer has a larger size</strong>. The Einstein relation tells us that particles of larger size encounter greater damping and diffuse more slowly. So, if temperature regulates the switching between these two states, we immediately have an <strong>average size</strong> that depends on temperature and thus a temperature-dependent effective diffusion coefficient.</p>
<p>And this temperature regulation is obvious, especially if we consider that the switching between unfolding and folding is reached fast enough in comparison to diffusion, the probability of being in each state is determined by the local temperature (local equilibrium approximation).</p>
\[p_i=\frac{1}{Z}e^{-G_i/k_BT(x)}\]
<p>From the above Boltzmann distribution, which is the most fundamental law in thermodynamics, we can see that the probability of being in each state depends on the free energy of the state and the temperature of the local environment. Then, if we calculate the average, the effective diffusion coefficient is</p>
\[\langle D\rangle = p_u D_u +p_fD_f\]
<p>which directly depends on the occupations in the two states, and the occupations are determined by the local temperature. Therefore, we have an <strong>effective diffusion coefficient that depends on the temperature.</strong></p>
<p>To gain a better understanding, let’s consider the following limit: in the cold region, the particle is almost completely in the folded state, while in the hot region it is almost completely unfolded. The unfolded state in the hot region diffuses more slowly and thus leads to a <strong>negative Soret coefficient</strong>, which means that such a polymer can show <strong>thermophilic</strong> behavior.</p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="/files/thermophoresis/聚合物热泳.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">Polymer can show thermophilic behavior.</td>
</tr>
</tbody>
</table>
<p>Of course, in the limit case shown above, the always positive term, $S_T^0=1/T$, is not included. Overall, the thermophoresis of the particle depends on $D\propto \boxed{T}\boxed{R^{-1}}$ these two individual contributions. In the case of the example polymer, these two terms are positive and negative, respectively, which leads to the fact that the particle can switch from <strong>thermophobic</strong> to <strong>thermophilic</strong> as the temperature changes, i.e. the sign of the Soret coefficient changes. This positive and negative thermophoresis of polymers has been widely observed in experiments<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">2</a></sup>.</p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="/files/thermophoresis/热泳_符号变化.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">The thermotropic and thermophilic behaviors of polymer be changed depending on the temperature.</td>
</tr>
</tbody>
</table>
<p>Here $S_T^0=1/T$ is the contribution of the direct temperature-dependent term. While $S_T^\mathrm{chem}$ is what we call chemical thermophoresis, which originates from the thermoresponsive particle size.</p>
<p>For a more general case, we can consider that the particles have many internal states, which have different energies and diffusion coefficients. This energy-diffusion correlation leads to chemical thermophoresis. We can derive a very simple expression for the chemical Soret coefficient as</p>
\[S_T^\mathrm{chem}=\frac{\mathrm{Cov}_\mathrm{eq}(E,D)}{\langle D\rangle k_BT^2}\]
<p>Here, the Soret coefficient is directly related to the covariance between the energies and the diffusion coefficients. If the energy and diffusion coefficients of the different states are positively correlated, we get a positive Soret coefficient, i.e. thermophobic, and vice versa, a more interesting thermophilic behavior.</p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="\../files/thermophoresis/正负热泳.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">Positive or negative chemical thermophoresis depends on the energy-diffusion correlation.</td>
</tr>
</tbody>
</table>
<h2 id="complex-chemical-reactions">Complex chemical reactions</h2>
<p>The chemical reactions covered in the previous section are the basic isomerization reactions, that is, no chemical complexes are formed. However, conceptually, it is straightforward to extend the chemical thermophoresis to more complex chemical reactions. For example, the following polymerization reaction</p>
<table>
<thead>
<tr>
<th style="text-align: center"><img src="/files/thermophoresis/聚合反应.png" alt="" /></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">Dimerization reaction can also exhibit thermophoresis.</td>
</tr>
</tbody>
</table>
<p>Two monomers can form a dimer. Although the Soret coefficient derived from the previous isomerization cannot be directly applied, we can still use the energy-diffusion coefficient correlation to understand this thermophoretic phenomenon. Here, the energy and diffusion coefficients of the monomer and dimer are different, and as long as they are not the same, the system can respond to the temperature gradient and exhibit thermophoresis (inhomogeneous distribution) of the total concentration.</p>
<h2 id="discussion">Discussion</h2>
<p>Our theory gives a microscopic mechanism for the emergence of thermophoresis, which can be decomposed into several terms: the contribution of the temperature term of the Einstein relation itself, and the chemical thermophoresis as a consequence of energy-diffusion correlation. The actual thermophoretic phenomenon might be influenced by other mechanisms, such as those originating from the direct interaction of the particles with the solvent molecules<sup id="fnref:3" role="doc-noteref"><a href="#fn:3" class="footnote" rel="footnote">3</a></sup><sup id="fnref:4" role="doc-noteref"><a href="#fn:4" class="footnote" rel="footnote">4</a></sup>. Therefore, the emergent chemical thermophoresis we discuss here may be the dominant term, but it may also be a small higher-order quantity that can be neglected. From our understanding, <strong>it is highly likely to observe chemical thermophoresis as the dominant mechanism when the structure of the particle is very sensitive to temperature change.</strong> For example, in PNIPAM systems, the folding and unfolding of the polymer exhibit phase transition with temperature, and “giant thermophoresis” can be measured at this phase transition point<sup id="fnref:5" role="doc-noteref"><a href="#fn:5" class="footnote" rel="footnote">5</a></sup><sup id="fnref:6" role="doc-noteref"><a href="#fn:6" class="footnote" rel="footnote">6</a></sup><sup id="fnref:7" role="doc-noteref"><a href="#fn:7" class="footnote" rel="footnote">7</a></sup>. We expect that some experiments will be inspired to explore this direction.</p>
<p><a href="/files/thermophoresis/emergent_thermophoresis.pdf">Download the PDF</a></p>
<h2 id="references">References</h2>
<div class="footnotes" role="doc-endnotes">
<ol>
<li id="fn:1" role="doc-endnote">
<p>Liang S, Busiello D M and De Los Rios P, 2022. Emergent thermophoretic behavior in chemical reaction systems. New Journal of Physics <a href="http://doi.org/10.1088/1367-2630/aca556"><strong>24</strong> 123006</a> <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:2" role="doc-endnote">
<p>Wang Z, Kriegs H and Wiegand S 2012 Thermal diffusion of nucleotides J. Phys. Chem. B <a href="https://doi.org/10.1021/jp3032644">116 7463–9</a> <a href="#fnref:2" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:3" role="doc-endnote">
<p>Burelbach Jerome, Frenkel D, Pagonabarraga I and Eiser E 2018 A unified description of colloidal thermophoresis Eur. Phys. J. E <a href="https://doi.org/10.1140/epje/i2018-11610-3"><strong>41</strong> 1–12</a> <a href="#fnref:3" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:4" role="doc-endnote">
<p>Piazza R 2008 Thermophoresis: moving particles with thermal gradients Soft Matter <a href="https://doi.org/10.1039/B805888C"><strong>4</strong> 1740–4</a> <a href="#fnref:4" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:5" role="doc-endnote">
<p>Kita R and Wiegand S 2005 Soret coefficient of poly (n-isopropylacrylamide)/water in the vicinity of coil- globule transition temperature Macromolecules <a href="https://doi.org/10.1021/ma050526+"><strong>38</strong> 4554–6</a> <a href="#fnref:5" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:6" role="doc-endnote">
<p>Wongsuwarn S, Vigolo D, Cerbino R, Howe A M, Vailati A, Piazza R and Cicuta P 2012 Giant thermophoresis of poly(n-isopropylacrylamide) microgel particles Soft Matter <a href="https://doi.org/10.1039/C2SM25061F"><strong>8</strong> 5857–63</a> <a href="#fnref:6" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:7" role="doc-endnote">
<p>Königer A, Plack N, Köhler W, Siebenbürger M and Ballauff M 2013 Thermophoresis of thermoresponsive polystyrene–poly (n-isopropylacrylamide) core–shell particles Soft Matter <a href="https://doi.org/10.1039/C2SM27417E"><strong>9</strong> 1418–21</a> <a href="#fnref:7" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
</ol>
</div>Shiling Liang 梁师翎shiling.liang@epfl.chIn our recent paper, we showed that thermophoresis can be an emergent phenomenon from chemical reaction systems. This blog is a lay summary of our work.Notes on Fluctuation Theorems2018-11-14T00:00:00-08:002018-11-14T00:00:00-08:00https://shiling42.github.io/posts/2018/11/Notes-on-Fluctuation-Theorems<p><a href="/files/Fluctuation_Theorems.pdf">Get the PDF</a></p>
<h2 id="abstract">Abstract</h2>
<p>These notes are based on the review article by E.M Sevick et al[1]. on the fluctuation theorem. I also refer to the original papers of Jarzynski[2-4] and adopt notation from a book written by Evans et al.[5]. I discuss the motivation for proposing the fluctuation theorem and provide a detailed derivation of the Evans-Searles Fluctuation Theorem, which shows how macroscopic irreversibility emerged from the time-symmetrical equation of motion and addresses the importance of the initial condition of the system. I also recap the derivation the Crooks Fluctuation Theorem to relate work and free energy of a non-quasistatic process between two states of equilibrium, and I then take the Jarzynski equality as a consequence of the Crooks Fluctuation Theorem. In the section of examples, it is shown that a simple physical example with an analytical solution can be used to verify these relations.</p>
<h2 id="introduction">Introduction</h2>
<p>Fluctuation theorems present an analytical description of violations of the second law of thermodynamics; however, they also provide rigorous proof to this law from a statistical perspective. Classical thermodynamics can only deal with equilibrium systems and quasistatic processes. The behaviours of non-equilibrium systems are unclear within this scheme. Moreover, reversible equations of motion conflict with the monotonically increasing entropy predicted by the second law. Boltzmann’s statistical thermodynamics provides the groundwork for solving this problem by using the second law as a statistical law. However, he was not able to determine a quantitative relation. The most recent progress toward this end was the development of the fluctuation theorem in the 1990s.</p>
<p>In 1994, Evans and Searles proposed the fluctuation theorem[6], which calculates the probability of negative and positive entropy production. It is valid for systems of any size and with arbitrary distances from equilibrium. It illustrates how irreversible macroscopic phenomena emerge from time-reversible equations of motion. In 1997, Jarzynski developed a more practical relation[2], the Jarzynski equality, which allows us to establish the relationships between work and free energy changes for a non-quasistatic process between two states of equilibrium. This relation reveals more information than do classical thermodynamics, which only reveals discrepancies between work and free energy differences.
The next year, Crooks developed a more general form of the Jarzynski equality: the Crooks Fluctuation Theorem[7]. This theorem calculates the relative probability of given forward and backward trajectories.</p>
<p>In this report, I recap the derivations of these relations based on a deterministic Hamiltonian system. I include a short introduction to phase spaces at the beginning and then follow the logical order rather than the chronological order of theorem development (which regards the Jarzynski equality as a consequence of the Crooks Fluctuation Theorem). It is also demonstrated how to view the second law of thermodynamics is a consequence of the fluctuation theorem.</p>
<h2 id="derivation-of-fluctuation-theorems">Derivation of Fluctuation Theorems</h2>
<h3 id="phase-space-and-liouvilles-equation">Phase space and Liouville’s Equation</h3>
<p>In Hamiltonian mechanics, all possible states of a system expanded a phase space. A typical system in our scale has more than $\sim 10^{23}$ particles. Thus, it is not possible to know their exact configurations, so we use a probability distribution function to characterise such systems. By denoting the probability distribution function as $f(\Gamma,t)$, the probability of finding the system in an infinitesimal phase space volume $\mathrm{d}\Gamma$ is</p>
\[P(\mathrm{d}\Gamma_t,t)\equiv
f(\Gamma_t,t)\mathrm{d}\Gamma_t.\]
<p>For a Hamiltonian system, the total time derivative of $f$ is</p>
\[\begin{equation}
\begin{aligned}
\frac{\mathrm{d}f}{\mathrm{d}t}
&=\frac{\partial f}{\partial t}+\frac{\partial f}{\partial p}\dot{p}+\frac{\partial f}{\partial q}\dot{q}\\
&=\frac{\partial f}{\partial t}+\frac{\partial f}{\partial \Gamma}\cdot \dot\Gamma.
\end{aligned}
\end{equation}\]
<p>The continuity equation must hold for the probability flow in the phase space</p>
\[\frac{\partial (f\dot{\Gamma})}{\partial \Gamma}+\frac{\partial f}{\partial t}=0.\]
<p>Using these two equations to eliminate the partial derivative of $t$, one obtains</p>
\[\frac{\mathrm{d} f}{\mathrm{d} t}=-f\frac{\partial \dot{\Gamma}}{\partial \Gamma}.\]
<p>We now denote $\Lambda \equiv\frac{\partial \dot\Gamma}{\partial \Gamma}$, and integrate from the initial time $t=0$ to $t=\tau$</p>
\[f(\Gamma_\tau,\tau)=f\left(\Gamma_0,0\right)\exp\left(-\int_0^\tau \Lambda\mathrm{d}t\right).\]
<p>As the probability of a specific phase space volume must be conserved, we can use the equation of probability evolution and Liouville equation to obtain the compression factor for the infinitesimal phase space volume:</p>
\[\frac{\mathrm{d}\Gamma_\tau}{\mathrm{d}\Gamma_0}=\exp\left(\int_0^\tau\Lambda\mathrm{d}s\right).\]
<h3 id="the-evans-searles-fluctuation-theorem-1994">The Evans-Searles Fluctuation Theorem (1994)</h3>
<p>The Evans-Searles fluctuation theorem is the most general one, and it can be applied to a system of any size and any distance from equilibrium.</p>
<p>Using time evolution operator $S^t$ to denote the evolution of a phase space point for a period $t$ and time-reversal mapping operator $M^T$ to reverse the trajectory. For a Hamiltonian system, the reverse mapping is noting but reversing the momentum $p\to -p$. Since the dynamics are deterministic, a trajectory can be determined by its initial state. For a trajectory origin at phase point $\Gamma_0$, the corresponding anti-trajectory can be easily represented by its initial phase point $\Gamma^*_0 \equiv M^T\Gamma_t=M^T S^\tau\Gamma_0$. Note that the time-reversal mapping does not change the size of phase space volume. With equation (6), we can obtain</p>
\[\mathrm{d}\Gamma_0^*=\mathrm{d}\Gamma_\tau=\mathrm{d}\Gamma_0\exp\left(\int_0^\tau \Lambda\mathrm{d}t\right).\]
<p>Alongside the trajectory of a single-phase space point, we also consider the evolution of an infinitesimal phase space volume $d\Gamma_0$; that is, a bundle of trajectories. The probability of observing this volume is</p>
\[P(\mathrm{d}\Gamma_0,0)\equiv \mathrm{d}\Gamma_0 f(\Gamma_0,0) .\]
<p>Macroscopic reversible systems indicate that the probability of observing the forward bundle of trajectories and the corresponding anti-trajectories should be the same:</p>
\[\mathrm{d}\Gamma_0 f(\Gamma_0,0) =\mathrm{d}\Gamma^*_0 f(\Gamma^*_0,0).\]
<p>For more general cases, we define a dissipation function to characterize the reversibility of the bundle of trajectories</p>
\[\begin{aligned}
\Omega_\tau(\Gamma_0)
&\equiv \ln\left(\frac{P(\mathrm{d}\Gamma_0,0)}{P(\mathrm{d}\Gamma_0^*,0)}\right)\\
&=\ln\left(\frac{f(\mathrm{d}\Gamma_0,0)}{f(\mathrm{d}\Gamma_0^*,0)}\right)-\int_0^\tau \Lambda\mathrm{d}t.
\end{aligned}\]
<p>The positive dissipation function means the anti-trajectories are less probable, and the negative dissipation function gives the opposite case. It takes the value $0$ only in the state of equilibrium, where no macroscopic time evolution can be observed. Moreover, the dissipation function has odd parity</p>
\[\Omega_\tau(\Gamma_0)=-\Omega_\tau(\Gamma_0^*).\]
<p>Now it is important to calculate the probability of an anti-trajectory occurring within the entire phase space. We can do the following integral to calculate the relative probability of the dissipation function taking the opposite value.</p>
\[\begin{aligned}
\frac{p(\Omega_\tau= A)}{p(\Omega_\tau= -A)}
&=\frac{\int\mathrm{d}\Gamma_0\delta(\Omega_\tau(\Gamma_0)-A)f(\Gamma_0,0)}{\int\mathrm{d}\Gamma_0^*\delta(\Omega_\tau(\Gamma_0^*)+A)f(\Gamma_0^*,0)}\\
&=\frac{\int\mathrm{d}\Gamma_0\delta(\Omega_\tau(\Gamma_0)-A)f(\Gamma_0,0)}{\int\mathrm{d}\Gamma_0^*\delta(-\Omega_\tau(\Gamma_0)+A)f(\Gamma_0^*
,0)}\\
&=\frac{\int\mathrm{d}\Gamma_0\delta(\Omega_\tau(\Gamma_0)-A)f(\Gamma_0,0)}{\int\mathrm{d}\Gamma_0\delta(-\Omega_\tau(\Gamma_0)+A)f(\Gamma_0,0)\exp(-{\Omega}_\tau(\Gamma_0))}\\
&=\exp(A),
\end{aligned}\]
<p>where we used the fact that $\Gamma_0$ is a dummy variable for the integral over the whole phase space. Then we used the fact that the dissipation function is odd. To calculate the third equality, we used the equation phase compression factor with the definition of the dissipation function. The result,</p>
\[\frac{p(\Omega_\tau=A)}{p(\Omega_\tau=-A)}=\exp(A),\]
<p>implies that for all trajectories in the phase space, irreversible cases are exponentially more probable than are reversible cases. We can further calculate the average of the dissipation function over the whole phase space:</p>
\[\begin{aligned}
\langle \exp(-{\Omega}_\tau) \rangle
&=\int_{-\infty}^\infty \mathrm{d}A\ \exp(-A)p({\Omega}_\tau=A)\\
&=\int_{-\infty}^\infty \mathrm{d}A\ \exp(A)p(-{\Omega}_\tau)\exp(A)\\
&=\int_{-\infty}^\infty \mathrm{d}A\ p({\Omega}_\tau=-A)\\
&=1.
\end{aligned}\]
<p>Note that $\exp(-\Omega_\tau)$ is a convex function, which leads to the Jensen’s inequality</p>
\[\langle \Omega_\tau\rangle \geq 0.\]
<p>This is exactly what we expect – the second law inequality.</p>
<h3 id="crooks-fluctuation-theorem-1998">Crooks Fluctuation Theorem (1998)</h3>
<p>Crooks Fluctuations Theorem and the Jarzynski equality address the non-equilibrium processes between two equilibriums (unlike classical thermodynamics, which can only describe quasistatic work relations). Jarzynski equality directly presents the work relation regarding actions performed at any rate. The Crooks Fluctuation Theorem even measures the probability distribution of trajectories. These relations allow us to describe certain microscopic operations, such as the stretching of a polymer.</p>
<p>The Crooks Fluctuation Theorem was developed later than the Jarzynski equality. However, as it is a more general formula, we view the Jarzynski equality as a direct consequence of the Crooks Fluctuation Theorem in the following discussion. The Crooks Fluctuation Theorem reads</p>
\[\frac{p_f(W=\mathcal{A})}{p_r(W=-\mathcal{A})}=\exp\left(\beta(\mathcal{A}-\Delta F)\right),\]
<p>where $p_f(W=\mathcal{A})$ is the probability of work done on the system $W=\mathcal{A}$ between the initial equilibrium state $A$ to the final equilibrium state $B$. Additionally, $p_B(W=\mathcal{A})$ is the probability distribution of the reverse trajectories. On the right-hand side, $\Delta F$ is the free energy difference between the two states and $\beta\equiv\frac{1}{k_BT} $ is the reverse temperature of the heat bath.</p>
<p>The external work is introduced by a control parameter $\lambda$. The Hamiltonian of the system can be written as</p>
\[H(\Gamma_t,t,\lambda_t)=T(\mathbf{p})+V(\mathbf{q},\lambda),\]
<p>where $T$ and $V$ are the kinetic energy and the potential, respectively. The potential can be adjusted by the external control parameter $\lambda$ and varies from the initial value $\lambda=A$ to the final value $\lambda=B$. If it varies slowly enough, it becomes a trivial quasistatic case. In more general cases, an external agent drives the system out of equilibrium before it relaxes into a state of equilibrium once again.</p>
<p>Initially, the system is in contact with a heat bath at a temperature of $T=\frac{1}{k_B\beta}$. Thus, it is a canonical ensemble characterised by the Boltzmann probability distribution:</p>
\[p(H(\Gamma_0,A))=\frac{1}{Z_A}e^{-\beta H(\Gamma_0,A)}.\]
<p>Then the $\lambda$ varies from an initial value of $A$ to final value of $B$ in a specific protocol. The final equilibrium state has the probability distribution</p>
\[p(H(\Gamma_\tau,B))=\frac{1}{Z_B}e^{-\beta H(\Gamma_\tau,B)},\]
<p>and the change of Hamiltonian can be written as</p>
\[H(\Gamma_\tau,B)-H(\Gamma_0, A)=\int_0^\tau \mathrm{d}t \ \frac{\partial H(\Gamma,\lambda)}{\partial\lambda}\dot\lambda +\frac{\partial H(\Gamma,\lambda)}{\partial{\Gamma}}\cdot\dot{\Gamma}\]
<p>The first term of the integral is the total work done on the system, and the second term is the heat absorbed from the environment[8].</p>
\[\begin{aligned}
Q(\Gamma_0,\tau)&\equiv\int_0^\tau\mathrm{d}t\ \frac{\partial H(\Gamma,\lambda)}{\partial{\Gamma}}\cdot\dot{\Gamma}=k_BT\int_0^\tau
\Lambda(\Gamma_t) \mathrm{d}t\\
W(\Gamma_0,\tau)&\equiv \int_0^\tau\mathrm{d}t\ \frac{\partial H(\Gamma,\lambda)}{\partial\lambda}\cdot\dot\lambda.
\end{aligned}\]
<p>Hence, we can express the work done as a function of the energy difference associated with the initial and the final states, and we can express the phase space compression factor as</p>
\[W(\Gamma_0,\tau)=H(\Gamma_\tau,B)-H(\Gamma_0, A)-k_BT\int_0^\tau\Lambda(\Gamma_t)\mathrm{d}t.\]
<p>As time evolution is deterministic for a Hamiltonian system, the probability distribution of trajectories with $W=\mathcal{A}$ is directly determined by the initial distribution function associated with the work parameter $\lambda=A$
\(p_f(W=\mathcal{A})
=\int d\Gamma_0\delta(W(\Gamma_0,\tau)-\mathcal{A}) p(H(\Gamma_0,A)).\)
In the same way, we can write the probability of the anti-trajectories during which the system does work $\mathcal{A}$ to the external agent:</p>
\[p_b(W=-\mathcal{A})=\int d\Gamma_0^*\delta(W(\Gamma_0^*,A)+\mathcal{A}) p(H(\Gamma_0^*,B)).\]
<p>Based on the results obtained, we can write the relative probability as</p>
\[\begin{aligned}
\frac{p_f(W=\mathcal{A})}{p_b(W=-\mathcal{A})}
&=\frac{\int d\Gamma_0\delta(W(\Gamma_0,\tau)-\mathcal{A}) p(H(\Gamma_0,A))}{\int d\Gamma_0^*\delta(W(\Gamma_0^*,\tau)+\mathcal{A}) p(H(\Gamma_0^*,B))}\\
&=\frac{Z_B}{Z_A}\frac{\int d\Gamma_0\delta(W(\Gamma_0,\tau)-\mathcal{A}) e^{-\beta H(\Gamma_0, A)}}{\int d\Gamma_0^*\delta(W(\Gamma_0^*,\tau)+\mathcal{A}) e^{-\beta H(\Gamma_0^*,B)}}\\
&=\frac{Z_B}{Z_A}\frac{\int d\Gamma_0\delta(W(\Gamma_0,\tau)-\mathcal{A}) e^{-\beta H(\Gamma_0, A)}}{\int d\Gamma_0\delta(W(\Gamma_0,\tau)-\mathcal{A}) e^{-\beta H(\Gamma_0,A)}e^{-\beta W(\Gamma_0,\tau)}}\\
&=\frac{Z_B}{Z_A}e^{\beta \mathcal{A}}\\
&=\exp\left({-\beta\Delta F+\beta \mathcal{A}}\right),
\end{aligned}\]
<p>where the first equality is a direct substitution of forward and backwards probability. Then writing explicitly the equilibrium distribution leads to the second equality. To get the third equality, we used the work related to rewrite the denominator. With some simplification, we reach the final expression which is so-called Crooks fluctuation relation</p>
\[\frac{p_f(W=\mathcal{A})}{p_b(W=-\mathcal{A})}=\exp\left({-\beta\Delta F+\beta \mathcal{A}}\right).\]
<h3 id="jarzynski-equality-1997">Jarzynski equality (1997)</h3>
<p>As we mentioned before, Jarzynski equality can be regarded as a direct consequence of Crooks fluctuation theorem. With this probability distribution of trajectories given by Crooks FT, we can calculate the Jarzynski average of the work done on the system between initial and final state associated with $\lambda = A$ and $\lambda = B$</p>
\[\begin{aligned}
\langle \exp(-\beta W)\rangle
&= \int \mathrm{d}\mathcal{A}\ p_f(W=\mathcal{A})\exp(-\beta\mathcal{A})\\
&=\int\mathrm{d}\mathcal{A}\ p_b(W=-\mathcal{A})\exp(-\beta\Delta F)\\
&=\exp(-\beta\Delta F).
\end{aligned}\]
<p>This equality is highly useful; it allows for the calculation of the free energy difference by conducting the experiment many times. Due to the convexity of the exponential function, the Jarzynski equality implies</p>
\[\Delta F \leq W.\]
<p>Therefore we can see it is consistent with the second law of thermodynamics.
##Example</p>
<h3 id="colloidal-in-an-optical-trap">Colloidal in an optical trap</h3>
<p>The simplest and most practical example of applying fluctuation theorems is through a single colloidal in an optical trap. This system has the smallest possible degrees of freedom, and the optic trap can be approximated as a harmonical potential, which is the simplest potential providing restoring force. For such a system, we can obtain an analytical solution to verify the fluctuation theorems.</p>
<p>We treat the optical trap as a harmonical potential with the spring constant $k$ and assume the particle confined in the trap is over-damped; in this way, we can neglect the kinetic energy. Thus, the Hamiltonian can be written as</p>
\[H(\Gamma_0,\lambda)=\phi_{ext}=\frac{1}{2}k^2 \mathbf{r}^2,\]
<p>where $\lambda$ is the control parameter. In the beginning, $k=k_0$ and the system is in a canonical distribution</p>
\[p_{k_0}(\mathbf{r})=\frac{2\pi}{\beta k_0}e^{-\beta \frac{1}{2}k_0 \mathbf{r}^2}.\]
<p>At the time $t=0$, we suddenly change the intensity of the laser so that the spring constant jumps to $k_1$. In this process, the work done on the system depends on the distance from the centre at that moment</p>
\[W=\int_0^\tau dt \dot{\lambda}\frac{d\phi_{ext}}{d\lambda}=\frac{1}{2}(k_1-k_0)\mathbf{r}_0^2.\]
<p>Now the system is in an non-equilibrium state and will relax to a state of equilibrium:</p>
\[p_{k_1}(\mathbf{r})=\frac{2\pi}{\beta k_1}e^{-\beta \frac{1}{2}k_1 \mathbf{r}^2}.\]
<p>Accordingly, the free energy difference can be directly obtained from the initial and final equilibrium distributions:</p>
\[\Delta F=-k_BT\ln{Z_{k_1}}+k_BT\ln{Z_{k_0}}=k_BT\ln{\frac{k_0}{k_1}}\]
<p>To calculate the Jarzynski average of the work, we can first find the probability distribution of the trajectories as a function of work by combining the initial probability distribution and equation of the work applied on the colloid:</p>
\[p_{k_0\to k_1}(W)=p_{k_0}(W)=\frac{k_1-k_0}{\beta k_0}e^{-\beta\frac{k_0W}{k_1-k_0}}.\]
<p>Then, we can easily calculate the Jarzynski average and confirm the Jarzynski equality:</p>
\[\begin{aligned}
\langle e^{-\beta W}\rangle
&=\int_0^\infty \mathrm{d}W\ e^{-\beta W}\frac{k_1-k_0}{\beta k_0}e^{-\beta\frac{k_0W}{k_1-k_0}W}\\
&=\frac{k_1}{k_0}\\
&=e^{-\beta \Delta F}.
\end{aligned}\]
<p>Following the same procedure, we can also calculate the probability of the reverse process $p_{k_0\to k_1}(W)$ and confirm the Crooks Fluctuation Theorem:</p>
\[\frac{p_{k_0\to k_1}(W)}{p_{k_1\to k_0}(-W)}=\frac{\frac{k_1-k_0}{\beta k_0}e^{-\beta\frac{k_0W}{k_1-k_0}}}{\frac{k_0-k_1}{\beta k_1}e^{\beta\frac{k_1W}{k_0-k_1}}}=e^{\beta(W-\Delta F)}.\]
<p>This example can also be used to verify the Evans-Searles Fluctuation Theorem. Since the Evans-Searles Fluctuation Theorem requires that all processes are time-reversible, we need to change the protocol to meet this condition, which involves changing $k_1$ back to $k_0$ at time $t=\tau$.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Fluctuation theorems bring us a deeper understanding of the irreversible process. Evans-Searles fluctuations resolved Loschmidt‘s objection on Boltzmann’s statistical thermodynamics. The Crooks Fluctuation Theorem and Jarzynski equality are powerful tools for investigating small systems with non-negligible fluctuations. However, due to time restrictions, we can only discuss the deterministic dynamics described by Hamiltonian mechanics. The quantum version of the fluctuation theorem and stochastic dynamics are also worth discussing.</p>
<h2 id="appendix">Appendix</h2>
<h3 id="a-hamiltonian-mechanics-with-dissipative-force">a. Hamiltonian mechanics with dissipative force</h3>
<p>See in section 2, <em>Fluctuation Theorem</em>, E.M Sevick et al.[1].</p>
<h3 id="b-heat-absorbed-and-the-phase-space-compression-factor">b. Heat absorbed and the phase space compression factor</h3>
<p>In the derivation of the Crooks Fluctuation Theorem, we used the relation</p>
\[Q(\Gamma_0,\tau)\equiv\int_0^\tau\mathrm{d}t\ \frac{\partial H(\Gamma,\lambda)}{\partial{\Gamma}}\cdot\dot{\Gamma}=k_BT\int_0^\tau
\Lambda(\Gamma_t) \mathrm{d}t\]
<p>without proof. For an intuitive understanding, we can consider a specific case in which heat slowly enters in a microcanonical ensemble. We begin by writing the above relation in the instantaneous form:</p>
\[\dot{Q}(\Gamma_t)\equiv\frac{\partial H(\Gamma,\lambda)}{\partial \Gamma}\cdot\dot\Gamma = k_BT\Lambda(\Gamma_t)\]
<p>To understand this, let us consider the case for states of equilibrium with quasistatic processes, in which Boltzmann’s entropy is defined as</p>
\[S=k_B\log \Omega,\]
<p>where $\Omega$ is the number of states. In a quasi-static process, we have</p>
\[\mathrm{d}S=\frac{\mathrm{d}Q}{T}.\]
<p>Thus,</p>
\[\dot{Q}\equiv\frac{\mathrm{d}Q}{\mathrm{d}t}=T\frac{\mathrm{d}S}{\mathrm{d}t}=k_BT\frac{\mathrm{d}}{\mathrm{d}t}\log{\Omega}=k_BT\Lambda(\Gamma).\]
<h2 id="reference">Reference</h2>
<p>[1] Edith M Sevick, R Prabhakar, Stephen R Williams, and Debra J Searles. Fluctuation theorems.Annu. Rev. Phys.Chem., 59:603–633, 2008.</p>
<p>[2] C. Jarzynski. Nonequilibrium equality for free energy differences.Physical Review Letters, 78(14):2690–2693, 1997.</p>
<p>[3] Denis J. Evans and Debra J. Searles. The fluctuation theorem.Advances in Physics, 51(7):1529–1585, 2002.</p>
<p>[4] Chris Jarzynski. Nonequilibrium work theorem for a system strongly coupled to a thermal environment. Journal of Statistical Mechanics: Theory and Experiment,2004(09): P09005, 2004.</p>
<p>[5] Denis James Evans, Debra Joy Searles, and Stephen Rod-ney Williams.Fundamentals of classical statistical thermodynamics: dissipation, relaxation, and fluctuation theorems. John Wiley & Sons, 2016.</p>
<p>[6] Denis J Evans and Debra J Searles. Equilibrium microstates which generate second law violating steady states.Physical Review E, 50(2):1645, 1994.</p>
<p>[7] Gavin E Crooks. Nonequilibrium measurements of free energy differences for microscopically reversible Markovian systems.Journal of Statistical Physics, 90(5-6):1481–1487,1998.</p>
<p>[8] For an intuitive understanding of this relation, see theAppendix. More rigorous proof can be obtained with Nosé–Hoover thermostat</p>
<object data="/files/Fluctuation_Theorems.pdf" width="1000" height="2000" type="application/pdf" />Shiling Liang 梁师翎shiling.liang@epfl.chGet the PDFMonte Carlo Simulation of XY Model with Python2017-06-08T00:00:00-07:002017-06-08T00:00:00-07:00https://shiling42.github.io/posts/2017/06/XY-Model<blockquote>
<p>Python codes for XY model simulation.</p>
<ul>
<li><a href="https://shilingliang.com/XY-MODEL/">Project page</a></li>
<li><a href="https://github.com/Shiling42/XY-MODEL/blob/master/README.ipynb">Jupyter notebook</a></li>
</ul>
</blockquote>
<p><img src="/files/XY_model/XY_color.jpg" alt="drawing" style="width:300px;" /></p>
<h2 id="whats-it">What’s it?</h2>
<p>A python program used for Monte Carlo simulation (Metropolis algorithm) of XY model.</p>
<h2 id="what-are-the-outputs">What are the outputs?</h2>
<ul>
<li>equilibrium spin configuration in differnet temperature</li>
<li>thermal quantities of XY spin system in different temperature</li>
</ul>
<h2 id="how-to-use-this-program">How to use this program</h2>
<h4 id="import-the-class">import the class</h4>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">XY_model</span> <span class="kn">import</span> <span class="n">XYSystem</span>
</code></pre></div></div>
<h4 id="creating-an-object-as-a-x-y-spin-system-with-given-width-and-temperature">creating an object as a X-Y spin system with given width and temperature</h4>
<p>Use <code class="language-plaintext highlighter-rouge">XYSystem(temperature = , width = )</code> to creat a class object. Two variables can be assigned to initilize the system: the temperature and the width.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">xy_system_1</span> <span class="o">=</span> <span class="n">XYSystem</span><span class="p">(</span><span class="n">temperature</span> <span class="o">=</span> <span class="mf">0.5</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="mi">15</span><span class="p">)</span>
</code></pre></div></div>
<h4 id="visulizingthe-spin-system">visulizingthe spin system</h4>
<p>Using <code class="language-plaintext highlighter-rouge">.show()</code> to visulize the xy spin system as arrows on a two-dimensional plane.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">xy_system_1</span><span class="p">.</span><span class="n">show</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Energy per spin:%.3f'</span><span class="o">%</span><span class="n">xy_system_1</span><span class="p">.</span><span class="n">energy</span><span class="p">)</span>
</code></pre></div></div>
<p><img src="/files/XY_model/output_7_0.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Energy per spin:0.056
</code></pre></div></div>
<h4 id="now-let-the-system-evolve-to-an-equilibrium-state">Now, let the system evolve to an equilibrium state</h4>
<blockquote>
<p><code class="language-plaintext highlighter-rouge">self.equilibrate(self,max_nsweeps=int(1e4),temperature=None,H=None,show = False)</code> allows you to assign a new temperature, just simply do object.equilibrate(temperature = 3). If you want to keep the temperature defined before, leave it blank. And ·sohw=Ture` will let show the configuration of the system for each 1000 sweeps.</p>
</blockquote>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">xy_system_1</span><span class="p">.</span><span class="n">equilibrate</span><span class="p">(</span><span class="n">show</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">xy_system_1</span><span class="p">.</span><span class="n">show</span><span class="p">()</span>
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#sweeps=1
energy=-0.60
</code></pre></div></div>
<p><img src="/files/XY_model/output_9_1.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=0.5
#sweep=504
energy=-1.72
</code></pre></div></div>
<p><img src="/files/XY_model/output_9_3.png" alt="" /></p>
<h4 id="observing-the-thermal-quantities-in-different-temperature---annealing-approach">Observing the thermal quantities in different temperature - annealing approach</h4>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">xy_system_2</span> <span class="o">=</span> <span class="n">XYSystem</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
<span class="n">cool_dat</span><span class="o">=</span><span class="n">xy_system_2</span><span class="p">.</span><span class="n">annealing</span><span class="p">(</span><span class="n">T_init</span><span class="o">=</span><span class="mf">2.5</span><span class="p">,</span><span class="n">T_final</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span><span class="n">nsteps</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span><span class="n">show_equi</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=2.5
#sweep=6802
energy=-0.48
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_1.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=2.2
#sweep=3429
energy=-0.48
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_3.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=2.0
#sweep=9999
energy=-0.47
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_5.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=1.7
#sweep=2809
energy=-0.60
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_7.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=1.4
#sweep=989
energy=-0.74
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_9.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=1.2
#sweep=2253
energy=-1.35
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_11.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=0.9
#sweep=636
energy=-1.68
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_13.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=0.6
#sweep=837
energy=-1.72
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_15.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=0.4
#sweep=548
energy=-1.86
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_17.png" alt="" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>equilibrium state is reached at T=0.1
#sweep=503
energy=-1.95
</code></pre></div></div>
<p><img src="/files/XY_model/output_11_19.png" alt="" /></p>
<p><img src="/files/XY_model/output_11_20.png" alt="" /></p>
<p><img src="/files/XY_model/output_11_21.png" alt="" /></p>Shiling Liang 梁师翎shiling.liang@epfl.chPython codes for XY model simulation. Project page Jupyter notebook