<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Optimization of the Exhaustive Enumeration Algorithm in the Ising Model</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Mikhail A. Padalko</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Petr D. Andriushchenko</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Konstantin V. Nefedev</string-name>
          <email>nefedev.kv@dvfu.ru</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Far Eastern Federal University</institution>
          ,
          <addr-line>Vladivostok</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Institute of Applied Mathematics, Russian Academy of Science</institution>
          ,
          <addr-line>Vladivostok</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2019</year>
      </pub-date>
      <fpage>16</fpage>
      <lpage>19</lpage>
      <abstract>
        <p>An optimized method for the precise calculation of the Ising model is presented. The algorithm makes it possible to calculate two-dimensional 10x10 lattices for periodic boundary conditions on ordinary personal computers. The method is applicable to various types of lattices. The proposed optimized method of precise calculation makes it possible to test the effectiveness of Monte Carlo methods.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Z (T , H ) =  g ( E , M )  exp(− E / T − M  H / T )
(2)</p>
      <p>
        E ,M
where g(E, M) – is a multiplicity of the degeneracy of states in energy and magnetization. [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. If one knows the
partition function, it is possible to calculate all basic thermodynamic characteristics, such as internal energy, free
energy, magnetic susceptibility, heat capacity, etc. [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] In the Ising model g(E, M) is a discrete function of variables E
and M [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. For finite lattices g(E, M) can be represented in matrix form. For most systems, the only way to find
precise mean of g(E, M) is an exhaustive enumeration method. The difficulty of this approach is that it is necessary to
go through all the system configurations, the number of which is equal to 2N, where N – is number of spins in the
system. Calculation time using the proposed method grows exponentially with increasing number of spins. It was
verified that the exhaustive enumeration method allows calculating g(E, M) for the Ising model on the 6x6 square
lattice (236 configurations) in a time of the order of several hours using the CPU of ordinary personal computers. For
example, on a quad-core AMD Phenom (tm) II X4 970 processor with a maximum 3.6 GHz frequency with
paralleling on 4 cores, the calculation time is 1 h 32 min. The calculation for the Ising model on the 7x7 square lattice
will take about one and a half years.
      </p>
      <p>We propose an optimized method of calculation, which allows us to significantly reduce the computation time of
the discrete function g(E, M). Using this method, the computation time of the 6x6 2D Ising is 0.875 sec without
parallelization on the same computing power. The method makes available calculations of 10x10 lattices for a time
approximately equal to 1.5 h.</p>
      <p>
        Knowing the partition function allows us to test the effectiveness of various probabilistic algorithms: Metropolis
[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], Svendsen-Wang [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], Wolf [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], Wang-Landau [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], and others.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Algorithm Description</title>
      <p>The idea of the method is to choose a small subsystem, calculate all of its possible states and successively expand
it to the original system. In the case of rectangular lattices, it is advisable to choose one any spin. At each step, the
spin of the original system will be added to the subsystem. The process needs to be continued until the original
system will be obtained.</p>
      <p>Let introduce the concept of opened and closed spins. We call a subsystem spin opened if the number of its
neighbors in a subsystem is less than the number of its neighbors in the original system, i.e. spin borders on a spin
that is not yet included in the considered subsystem. Otherwise we will call it closed. In the process of calculating, it’s
convenient to represent the function g (E, M) as a table or matrix, along the horizontal and vertical axis of which all
possible values of the magnetization and energy are plotted correspondingly. The value of each element of such
matrix is equal to the number of configurations with the corresponding values of energy and magnetization. If a
configuration with certain values of energy and magnetization does not exist, then the value of the matrix element
will be zero (Fig. 1).</p>
      <p>The algorithm is applicable only for cases when the exchange interaction constant is the same for all pairs of
interacting spins. Any lattice architecture and any dimensions may be used.</p>
      <p>The algorithm consists of 9 steps:
1) Choose a small subsystem (for example 1 spin).</p>
      <p>2) Form the list of subsystem open spins: L={s1, s2, …, sn}, here n is quantity of opened spins and s1, s2, …, sn are
their numbers.</p>
      <p>3) Using the method of exhaustive enumeration, we calculate the degeneration matrices in energy and
magnetization for each configuration of opened spins.</p>
      <p>4) Expand the subsystem by including the spin of the original system to it.
5) Make a copy of all existing degeneration matrices. So one obtains 2 identical sets of matrices.
6) Let the value of the added spin be -1. For each configuration of spins from the list L, we calculate the changes in
energy ∆E and magnetization ∆M. Then we shift all elements in the corresponding matrices of the 1st set by the
value of ∆E vertically and ∆M horizontally. ∆E is equal to the interaction energy of the added spin with spins from
the list L, ∆M = -1.</p>
      <p>7) Let the value of the added spin be +1. For each configuration of spins from the list L, we calculate the changes
in energy ∆E and magnetization ∆M. Then we shift all elements in the corresponding matrices of the 2nd set by the
value of ∆E vertically and ∆M horizontally. ∆E is equal to the interaction energy of the added spin with spins from
the list L, ∆M = +1.</p>
      <p>8) Update the list L of opened spins, taking into account added spin.</p>
      <p>9) If the extended subsystem is equal to the original system, then the degeneracy matrix g(E, M) of the original
system is obtained by algebraic addition of all degeneration matrices. The calculation is complete. Otherwise, in both
sets, we perform the algebraic addition of the degeneration matrices corresponding to the identical spin configurations
of the list L updated in step 8. Go back to step 4.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Algorithm for the Ising Model on the 2x2 Square Lattice</title>
      <p>Consider ferromagnetic the 2D Ising model on the 2x2 square lattice with free edge boundary conditions. In this
example, it is possible to trace in details all the steps of the algorithm described above. The task is to obtain the
degeneration matrix in energy and magnetization. For convenience, we number the spins, like in Fig. 2.</p>
      <p>Let us choose spin s1 as the initial subsystem. The scheme of expanding the initial subsystem to the original system
is shown in Fig. 3. Notations for the subsystems A, B, C is also given there. The original system is denoted as D. In
the figure, the opened spins of each of the subsystems are shaded.</p>
      <p>Figure 4 shows the first 9 steps of the proposed algorithm. On this picture one can see how an exhaustive
enumeration of the configurations of subsystem A is carried out. In step 5, we copy the set of degeneration matrices
obtained in step 3. Thus, we will obtain 2 identical sets of matrices. In step 6 and 7, the calculation of the changes in
the magnetization ∆M and energy ∆E for each configuration of the spins of the list L and the added spin is shown. In
step 9 we can see that only one matrix corresponds to each configuration of the spins from the updated list L.
Therefore, according to the algorithm, the addition is not necessary. The set of degeneracy matrices obtained in step 9
fully describes the system B. Since B ≠ D, back to step 4.</p>
      <p>At the time of the building system C in step 4, the list L contains 2 spins: s1, s2. Figure 5 shows the further steps of
the algorithm. Add spin s3 to the subsystem B. Copy 4 matrices of degenerations in the second set. Next we calculate
the changes in the energy ∆E and magnetization ∆M for each configuration of spins from the list L = {s1, s2} for the
cases s3 = -1 and s3 = + 1. Shift the matrix elements by the values of ∆E and ∆M vertically and horizontally,
respectively. Next, update the list of opened spins L. Spin s1 becomes closed for subsystem C, since the number of its
neighbors in B is 2, as in the original system. Thus, s2 and s3 will be included in L. Next, we carry out the algebraic
addition of matrices corresponding to the same configurations of the spins of the list L. Since system D is still not
built, go back to step 4.</p>
    </sec>
    <sec id="sec-4">
      <title>Algorithm Performance Analysis</title>
      <p>theoretical ratio ti to ti-1</p>
      <p>Because the number of possible configurations of spins in the KxK square lattice is 2K·K, the calculation will
depend on K as
where C1 is a constant defined by the implementation of the algorithm and the features of the computer architecture.
Accordingly, with an increase in the linear size of the lattice from K to K + 1, the calculation time increases as
t ( K ) = C1 2 K K ,
t ( K + 1) / t ( K ) = 22 K +1.</p>
      <p>In the last column of Table 1 one can see the time ratios calculated by the formula (4). They are approximately
consistent with the real values in column 4. Using the formula (4), one can calculate the approximate time of the
calculation of the 7x7 spin lattice: it will be longer than 6x6 213 times and will be 529 days with the same computing
power.</p>
      <p>For comparison, Table 2 shows the performance of the exhaustive enumeration method on the example of the
Ising model on the KxK square lattice with periodic boundary conditions.
(6)</p>
      <p>The initial subsystem was the lower left spin of t. The expansion to the original system was carried out row by
row, from bottom to top. Each row was completed sequentially from left to right. In accordance with the algorithm,
after each addition of the spin, degeneracy matrices were recalculated.</p>
      <p>On can estimate the speed of the algorithm. In total, K2 steps should be carried out until the KxK system is get.
Using the expansion scheme as described above (row by row, from bottom to top), the number of opened spins at
each step is approximately equal to 2·K. The upper and lower boundary spins will be opened. In accordance with the
algorithm, when one adding the next spin, all possible 22·K configurations of opened spins should be handled. Each
configuration of opened spins corresponds to a matrix of degeneracy of states in energy and magnetization. To change
the matrix of degenerations it is necessary to carry out a double cycle in rows and columns. The number of matrix
elements is equal to the product of all possible values of energy (4K2 + 1) and magnetization (2K2 + 1). Thus, the
calculation time will be proportional to the number of lattice spins, the number of possible configurations of
boundaries and the number of elements of the degeneration matrix:</p>
      <p>top ( K ) = C2  K 2  2 2 K  (2 K 2 + 1)(4 K 2 + 1), (5)
where C2 is a constant defined by the implementation of the algorithm and the features of the computer architecture.
So, it is now possible to calculate the time ratio with an increase the system linear size:
top ( K + 1) / top ( K ) = 4 
( K + 1)2  (2( K + 1)2 + 1)  (4( K + 1) 2 + 1)</p>
      <p>K 2 (2 K 2 + 1)(4 K 2 + 1)
.</p>
      <p>In the last column of Table 2 we can see the time ratios calculated by the formula (6). In general, they are also
consistent with the real values in column 4. It can be noted that with an increase in the linear size of the lattice, the
ratio of times decreases, with the exception of small systems. The discrepancy between the theoretical and real values
for the small size lattices can be explained by the features of the processor architecture. From formula (6), one can
conclude that the calculation time for the 9x9 spin lattice will increase by about 8.09 times compared to 8x8 and will
be about 11 minutes.
5</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusion</title>
      <p>The optimized algorithm for an exhaustive enumeration is presented. It was tested on a square spin lattice with
periodic boundary conditions. The calculation time of the not optimized exhaustive enumeration method increases with
the size of the lattice mainly as 2L·L, as time for the optimized version of the algorithm time grows mostly as 22 · L.</p>
      <p>The proposed algorithm can be easily changed under various boundary conditions and any lattice architecture.</p>
      <p>
        There are many papers devoted to various probabilistic methods for calculating the Ising models [
        <xref ref-type="bibr" rid="ref8 ref9">8, 9</xref>
        ], but the
question of the quality of the results obtained with their help remains opened [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. The method of exhaustive
enumeration allows to check the accuracy of probabilistic approaches.
      </p>
      <p>
        In the future, the proposed algorithm can be improved if we reduce the used memory to store degeneration
matrices and use symmetry to spin permutations. It is expected that an improved parallelized algorithm will make it
possible to calculate spin lattices up to sizes 15x15 using the computational power of the Computing Center of the Far
Eastern Branch of the Russian Academy of Sciences [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Van</given-names>
            <surname>Vleck</surname>
          </string-name>
          ,
          <string-name>
            <surname>J. H.</surname>
          </string-name>
          :
          <source>The Theory of Electric and Magnetic Susceptibilities</source>
          , Oxford University Press,.
          <volume>384</volume>
          p. (
          <year>1932</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Landau</surname>
            ,
            <given-names>L.D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifshitz</surname>
            ,
            <given-names>E.M.</given-names>
          </string-name>
          :
          <source>Course of Theoretical Physics. Volume 5. Statistical physics</source>
          ,
          <volume>3</volume>
          <fpage>edition</fpage>
          . - Butterworth-Heinemann,
          <volume>544</volume>
          p. (
          <year>1975</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Baxter</surname>
          </string-name>
          , R. J.:
          <article-title>Exactly solved models in statistical mechanics</article-title>
          , London: Academic Press Inc. [Harcourt Brace Jovanovich Publishers] ,
          <volume>498</volume>
          p. (
          <year>1989</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Metropolis</surname>
            ,
            <given-names>N.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosenbluth</surname>
            ,
            <given-names>A.W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosenbluth</surname>
            ,
            <given-names>M.N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Teller</surname>
            ,
            <given-names>A.H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Teller</surname>
            ,
            <given-names>E.H.</given-names>
          </string-name>
          :
          <article-title>Equation of state calculation by fast computing machines /</article-title>
          / J. Chem.
          <string-name>
            <surname>Phys</surname>
          </string-name>
          . - V.
          <year>21</year>
          . - P.
          <fpage>1087</fpage>
          -
          <lpage>1092</lpage>
          . (
          <year>1953</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Swendsen</surname>
            ,
            <given-names>R.H</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>J.S.:</given-names>
          </string-name>
          <article-title>Nonuniversal critical dynamics in Monte-Carlo simulations // Phys</article-title>
          . Rev.
          <string-name>
            <surname>Lett</surname>
          </string-name>
          . - -V.-
          <volume>58</volume>
          , No. 2. - P.
          <fpage>86</fpage>
          -
          <lpage>88</lpage>
          . (
          <year>1987</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Wolff</surname>
            ,
            <given-names>U.</given-names>
          </string-name>
          :
          <string-name>
            <surname>Collective</surname>
          </string-name>
          Monte-Carlo
          <source>Updating fir Spin Systems // Phys. Rev. Lett</source>
          . -V. 2, No. 4. - P.
          <fpage>361</fpage>
          -
          <lpage>364</lpage>
          . (
          <year>1989</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Landau</surname>
            ,
            <given-names>D. P.</given-names>
          </string-name>
          : Efficient,
          <article-title>Multiple-Range Random Walk Algorithm to Calculate the Density of States</article-title>
          .
          <source>Phys. Rev. Lett. American Physical Society</source>
          .
          <volume>86</volume>
          (
          <issue>10</issue>
          ):
          <fpage>2050</fpage>
          -
          <lpage>2053</lpage>
          . (
          <year>2001</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Newman</surname>
            ,
            <given-names>M.E.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Barkema</surname>
          </string-name>
          , G.T.: Monte Carlo Methods in Statistical Physics, Clarendon Press, 136 p. (
          <year>1999</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Landau</surname>
            ,
            <given-names>D. P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Binder</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          :
          <article-title>A guide to Monte Carlo simulations in statistical physics</article-title>
          , 4th ed. Cambridge University Press, 530 p. (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Barash</surname>
            ,
            <given-names>L.Yu.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fadeeva</surname>
            ,
            <given-names>M.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shchur</surname>
            ,
            <given-names>L.N.</given-names>
          </string-name>
          :
          <article-title>Control of accuracy in the Wang-Landau algorithm // Phys</article-title>
          . Rev. E
          <volume>96</volume>
          ,
          <fpage>043307</fpage>
          . (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <article-title>Computer Center of the Far Eastern Branch of the Russian Academy of Sciences</article-title>
          , URL: http://www.ccfebras.ru/
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>