Skip to content

Commit 3cdc740

Browse files
authored
Merge pull request #73 from ALPSim/docs/improve-mc-quickstart
docs: improve Classical Monte Carlo quickstart and fix math rendering
2 parents 11d1b49 + a6e88d4 commit 3cdc740

108 files changed

Lines changed: 762 additions & 681 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/en/documentation/alpsize/alpsize00.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ Flow of packaging (missing picture)
4646

4747
### Packaging with Cmake
4848

49-
00\_cmake
49+
00_cmake
5050

5151
$ cmake .
5252
$ make
5353
$ ./hello
5454

5555
### Implementation of the Wolff algorithm in C language
5656

57-
01\_original-c
57+
01_original-c
5858

5959
$ cmake .
6060
$ make
6161
$ ./wolff
6262

6363
### Implementation of the Wolff algorithm in C++ language
6464

65-
02\_basic-cpp
65+
02_basic-cpp
6666

6767
- modify header file: \<math.h\> to \<cmath\>,etc..
6868
- std name space
@@ -75,7 +75,7 @@ Flow of packaging (missing picture)
7575

7676
### Using Standard Template Library
7777

78-
03\_stl
78+
03_stl
7979

8080
- std::vector<>:1D-array
8181
- std::stack<>:stack
@@ -88,7 +88,7 @@ Flow of packaging (missing picture)
8888

8989
### Using Boost C++ Library
9090

91-
04\_boost
91+
04_boost
9292

9393
- <boost/array.hpp>
9494
- fixed-length array
@@ -105,23 +105,23 @@ Flow of packaging (missing picture)
105105

106106
### Using ALPS/parameters
107107

108-
05\_parameters
108+
05_parameters
109109

110110
$ cmake .
111111
$ make
112112
$ ./wolff <wolff.ip
113113

114114
### Using ALPS/alea
115115

116-
06\_alea
116+
06_alea
117117

118118
$ cmake .
119119
$ make
120120
$ ./wolff wolff.ip
121121

122122
### Using ALPS/lattice
123123

124-
07\_lattice
124+
07_lattice
125125

126126
$ cmake .
127127
$ make
@@ -130,7 +130,7 @@ Flow of packaging (missing picture)
130130

131131
### Full ALPSize using ALPS/Parapack Scheduler
132132

133-
08\_scheduler
133+
08_scheduler
134134

135135
- encapsulated code: Worker class
136136
- Function, must be implemented by Worker Class
@@ -140,7 +140,7 @@ Flow of packaging (missing picture)
140140
- save&load member function
141141
- Worker registration to the scheduler running the macro of PARAPACK_REGISTER_WORKER
142142
- preparation of Parameters and ObservableSet by scheduler,and setting constructor、init_observables-function、run-function
143-
- Because lattice_mc_workerはlattice\_helper has inherited rng_helper、that can activate the function of lattice_helper,rng_helper.
143+
- Because lattice_mc_workerはlattice_helper has inherited rng_helper、that can activate the function of lattice_helper,rng_helper.
144144

145145
$ cmake .
146146
$ make

content/en/documentation/codedev/code01.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The `run` method manages the Monte Carlo updates defined in the step routine and
7878
# Flip s_k with probability exp(2 beta e)
7979
...
8080

81-
The Monte Carlo sweeps are done in the `step` method. In the Metropolis algorithm a spin is a randomly picked and flipped with probability $p\_{accept} = min(1,e^{-\beta \Delta E})$, $\Delta E$ being the energy difference of the initial and proposed configuration. This procedure is repeated $L^2$ times. The implementation of the Metropolis algorithm is left to you as an exercise. You can make use of the `randint` function defined below:
81+
The Monte Carlo sweeps are done in the `step` method. In the Metropolis algorithm a spin is a randomly picked and flipped with probability $p_{accept} = min(1,e^{-\beta \Delta E})$, $\Delta E$ being the energy difference of the initial and proposed configuration. This procedure is repeated $L^2$ times. The implementation of the Metropolis algorithm is left to you as an exercise. You can make use of the `randint` function defined below:
8282

8383
def randint(self,max):
8484
return int(max*self.rng())

content/en/documentation/codedev/code02.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This tutorial shows how to write a Monte Carlo simulation in C++ using the ALPS
1010

1111
As a simple example, we will write a simulation of the classical 2D Ising model with local updates. The file `ising-skeleton.cpp` contains a skeleton code which already has all the infrastructure we will need: First it includes all needed headers, then it initializes a random number generator and three `alps::RealObservable` objects. Then it sets up a square lattice of Ising spins. It also provides a table of probabilities that can be used for Metropolis updates. The interface is the same as in the python script you implemented in the previous [tutorial](../../codedev/code01).
1212

13-
Your job is again to complete the methods `step()` and `measure()`: `step()` should choose a random spin from the lattice and flip it with the Metropolis probability $p\_{accept} = min(1,e^{-\beta \Delta E})$ where $\Delta E$ is the energy change the spin flip would cause. `measure()` determines the energy and magnetization of a spin configuration and adds this sample to the observable objects.
13+
Your job is again to complete the methods `step()` and `measure()`: `step()` should choose a random spin from the lattice and flip it with the Metropolis probability $p_{accept} = min(1,e^{-\beta \Delta E})$ where $\Delta E$ is the energy change the spin flip would cause. `measure()` determines the energy and magnetization of a spin configuration and adds this sample to the observable objects.
1414

1515
After replacing all ellipses with code, you can compile the simulation with this `Makefile`: Save the `Makefile` to the same directory as the `.cpp` file, edit the second line to point to your ALPS installation (if you haven't already set the environment variable ALPS_ROOT) and type `make`. This will produce an executable `ising`. Run it and you will see a scan over different values of $\beta = 1/k_B T$.
1616

content/en/documentation/intro/runalps/usepython.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The preparation, simulation, and evaluation tasks can also be split into subtask
166166

167167
## More examples
168168

169-
More example usage of the various functions and more advanced applications can be found in the tutorials. Also, don't forget to look at the documentation of the various functions using the \_\_doc\_\_ member variable of the functions, as in:
169+
More example usage of the various functions and more advanced applications can be found in the tutorials. Also, don't forget to look at the documentation of the various functions using the __doc__ member variable of the functions, as in:
170170

171171
print pyalps.plot.plot.__doc__
172172

content/en/documentation/lib/alea/_index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Here is an overview of the functions available
1515
| `mean` | Timeseries | None | `AverageType` |
1616
| `variance` | Timeseries | None | `AverageType` |
1717
| `error` | Timeseries | uncorrelated, binning | `AverageType` |
18-
| `autocorrelation` | Timeseries | \_distance, \_limit | `mctimeseries<AverageType>` |
19-
| `exponential_autocorrelation_time` | Scalar MCTimeseries | \_from & \_to, \_max & \_min | `std::pair<AverageType, AverageType>` |
18+
| `autocorrelation` | Timeseries | _distance, _limit | `mctimeseries<AverageType>` |
19+
| `exponential_autocorrelation_time` | Scalar MCTimeseries | _from & _to, _max & _min | `std::pair<AverageType, AverageType>` |
2020
| `integrated_autocorrelation_time` | Scalar MCTimeseries, `std::pair<AverageType, AverageType>` | None | `AverageType` |
2121
| `running_mean` | Timeseries | None | `mctimeseries<AverageType>` |
2222
| `reverse_running_mean` | Timeseries | None | `mctimeseries<AverageType>` |
@@ -27,8 +27,8 @@ The objects `mctimeseries<ValueType>` and `mctimeseries_view<ValueType>` are ess
2727

2828
| **Function Name** | **Argument(s)** | **Options** | **Return Type** |
2929
| :---------------- | :-------------- | :---------- | :-------------- |
30-
| `cut_head` | Timeseries | \_distance, \_limit | `mctimeseries_view<ValueType>` |
31-
| `cut_tail` | Timeseries | \_distance, \_limit | `mctimeseries_view<ValueType>` |
30+
| `cut_head` | Timeseries | _distance, _limit | `mctimeseries_view<ValueType>` |
31+
| `cut_tail` | Timeseries | _distance, _limit | `mctimeseries_view<ValueType>` |
3232

3333

3434
## Mean

content/en/documentation/methods/dmft/dmft.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ weight: 9
3434
| MAX_IT | maximum number of iteration in self-consistency loop (usually 10-20 will be enough) |
3535
| CONVERGED | criterium for stopping the self-consistency loop before reaching MAX_IT - if the maximum change in Green's function in Matsubara representation is less than CONVERGED, the loop will stop |
3636
| TOLERANCE | (only for hirschfyesim) as above |
37-
| RELAX_RATE | (by default 1; currently implemented only for selfconsistency loop with OMEGA_LOOP switched on) the new Green's function are in general computed as RELAX\_RATE \* $G\_{new}(i\omega_n)$ + (1-RELAX\_RATE) \* $G\_{old}(i\omega_n)$, which may help if oscillations occur |
37+
| RELAX_RATE | (by default 1; currently implemented only for selfconsistency loop with OMEGA_LOOP switched on) the new Green's function are in general computed as RELAX_RATE \* $G_{new}(i\omega_n)$ + (1-RELAX_RATE) \* $G_{old}(i\omega_n)$, which may help if oscillations occur |
3838

3939
### General parameters
4040

@@ -147,7 +147,7 @@ weight: 9
147147

148148
### The output files for the hybridization expansion impurity solver: (text files)
149149

150-
- overlap: i-th row contains the $\langle n\_\downarrow n\_\uparrow\rangle$ in the i-th iteration
150+
- overlap: i-th row contains the $\langle n_\downarrow n_\uparrow\rangle$ in the i-th iteration
151151
- matrix_size:
152152

153153

content/en/documentation/methods/ed/fulldiag/implem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ weight: 3
99

1010
The `fulldiag` package uses LAPACK library for a complete diagonalization of the Hamiltonian. Hence, it can be used for computing thermodynamic properties of any model that can be defined using the ALPS libraries. The main limitation is one of size, i.e., memory and CPU time may become unacceptable at sizes where other, more specialized applications still work well.
1111

12-
Release 1.3 allows the computation of magnetic or charge properties properties for models with a coupling to a conserved quantity of the form $-hS\_z$ or $-\mu N$, i.e., a SITETERM $-h S_z(i)$ or $-\mu n(i)$. In fact, adaptation to other situations with a coupling to a conserved quantity should be relatively straightforward by changing a few lines in the source file fulldiag.h (this is just not supported at the moment, since it requires the modification of at least 5 strings by the user). If the conserved quantity is not present, two quantities less will be evaluated (see below).
12+
Release 1.3 allows the computation of magnetic or charge properties properties for models with a coupling to a conserved quantity of the form $-hS_z$ or $-\mu N$, i.e., a SITETERM $-h S_z(i)$ or $-\mu n(i)$. In fact, adaptation to other situations with a coupling to a conserved quantity should be relatively straightforward by changing a few lines in the source file fulldiag.h (this is just not supported at the moment, since it requires the modification of at least 5 strings by the user). If the conserved quantity is not present, two quantities less will be evaluated (see below).
1313

1414
**Warning:** Incorrect results may be obtained if the supposed conserved quantity does actually not commute with the Hamiltonian. Incorrect results will also in general be obtained if the coefficients are not of the above form, and the magnetic field $h$ or chemical potential $\mu$ are changed by `fulldiag_evaluate`.
1515

content/en/documentation/methods/ed/fulldiag/jacobi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $$
2121

2222
where $D$ is a diagonal matrix containing the eigenvalues of $A$, and the columns of $P$ are the corresponding eigenvectors.
2323

24-
The Jacobi method achieves this by applying a sequence of orthogonal transformations (rotations) to $A$. Each rotation targets a specific off-diagonal element $A\_{ij}$ and zeroes it out.
24+
The Jacobi method achieves this by applying a sequence of orthogonal transformations (rotations) to $A$. Each rotation targets a specific off-diagonal element $A_{ij}$ and zeroes it out.
2525

2626

2727
## Rotation Matrix
@@ -40,18 +40,18 @@ R = \begin{pmatrix}
4040
\end{pmatrix}
4141
$$
4242

43-
Here, $\cos \theta$ and $\sin \theta$ are placed at the intersections of the $i$-th and $j$-th rows and columns. The angle $\theta$ is chosen such that the off-diagonal element $A\_{ij}$ is zeroed out.
43+
Here, $\cos \theta$ and $\sin \theta$ are placed at the intersections of the $i$-th and $j$-th rows and columns. The angle $\theta$ is chosen such that the off-diagonal element $A_{ij}$ is zeroed out.
4444

4545

4646
## Algorithm
4747

4848
1. **Identify the Largest Off-Diagonal Element**:
49-
- Find the largest off-diagonal element $A\_{ij}$ (in absolute value) in the matrix $A$.
49+
- Find the largest off-diagonal element $A_{ij}$ (in absolute value) in the matrix $A$.
5050

5151
2. **Compute the Rotation Angle $\theta$**:
5252
- The angle $\theta$ is chosen to satisfy:
5353
$$
54-
\tan(2\theta) = \frac{2A\_{ij}}{A\_{ii} - A\_{jj}}
54+
\tan(2\theta) = \frac{2A_{ij}}{A_{ii} - A_{jj}}
5555
$$
5656
- From this, compute $\cos \theta$ and $\sin \theta$.
5757

@@ -63,7 +63,7 @@ Here, $\cos \theta$ and $\sin \theta$ are placed at the intersections of the $i$
6363
$$
6464
A^{\prime} = R^T A R
6565
$$
66-
- This transformation zeroes out $A\_{ij}$ and $A\_{ji}$.
66+
- This transformation zeroes out $A_{ij}$ and $A_{ji}$.
6767

6868
5. **Accumulate the Transformations**:
6969
- Update the eigenvector matrix $P$ as:

content/en/documentation/methods/ed/fulldiag/qrfactor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ The eigenvalues of $A$ are found on the diagonal of the final matrix $A_k$, and
4444
3. **Reconstruction**:
4545
- Reconstruct the matrix $A_{k+1}$ as:
4646
$$
47-
A\_{k+1} = R_k Q_k
47+
A_{k+1} = R_k Q_k
4848
$$
4949

5050
4. **Accumulate Transformations**:
5151
- Update the eigenvector matrix $P$ as:
5252
$$
53-
P\_{k+1} = P_k Q_k
53+
P_{k+1} = P_k Q_k
5454
$$
5555
- Initialize $P_0 = I$ (identity matrix).
5656

content/en/documentation/methods/ed/intro.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ Exact diagonalization (ED) is a numerical technique used to solve quantum many-b
1111
The Heisenberg model is defined by the Hamiltonian:
1212

1313
$$
14-
\mathcal{H} = J \sum\_{\langle i,j \rangle} \mathbf{S}\_i \cdot \mathbf{S}\_j,
14+
\mathcal{H} = J \sum_{\langle i,j \rangle} \mathbf{S}_i \cdot \mathbf{S}_j,
1515
$$
1616

17-
where $\mathbf{S}\_i$ is the spin-1/2 operator at site $i$, $J$ is the exchange interaction (ferromagnetic for $J \lt 0$ and antiferromagnetic for $J \gt 0$), and the sum runs over nearest-neighbor pairs $\langle i,j \rangle$. For simplicity, we consider a 1D chain with periodic boundary conditions.
17+
where $\mathbf{S}_i$ is the spin-1/2 operator at site $i$, $J$ is the exchange interaction (ferromagnetic for $J \lt 0$ and antiferromagnetic for $J \gt 0$), and the sum runs over nearest-neighbor pairs $\langle i,j \rangle$. For simplicity, we consider a 1D chain with periodic boundary conditions.
1818

1919
### Example: 4-Site 1D Heisenberg Chain
2020

2121
Let’s study a 4-site 1D Heisenberg chain with periodic boundary conditions. The Hamiltonian for this system is:
2222

2323
$$
24-
\mathcal{H} = J \left( \mathbf{S}\_1 \cdot \mathbf{S}\_2 + \mathbf{S}\_2 \cdot \mathbf{S}\_3 + \mathbf{S}\_3 \cdot \mathbf{S}\_4 + \mathbf{S}\_4 \cdot \mathbf{S}\_1 \right).
24+
\mathcal{H} = J \left( \mathbf{S}_1 \cdot \mathbf{S}_2 + \mathbf{S}_2 \cdot \mathbf{S}_3 + \mathbf{S}_3 \cdot \mathbf{S}_4 + \mathbf{S}_4 \cdot \mathbf{S}_1 \right).
2525
$$
2626

27-
The spin-1/2 operators $\mathbf{S}\_i = (S_i^x, S_i^y, S_i^z)$ can be expressed in terms of Pauli matrices $\boldsymbol{\sigma}\_i$ as $\mathbf{S}\_i = \frac{1}{2} \boldsymbol{\sigma}\_i$. The dot product $\mathbf{S}\_i \cdot \mathbf{S}\_j$ can be written as:
27+
The spin-1/2 operators $\mathbf{S}_i = (S_i^x, S_i^y, S_i^z)$ can be expressed in terms of Pauli matrices $\boldsymbol{\sigma}_i$ as $\mathbf{S}_i = \frac{1}{2} \boldsymbol{\sigma}_i$. The dot product $\mathbf{S}_i \cdot \mathbf{S}_j$ can be written as:
2828

2929
$$
30-
\mathbf{S}\_i \cdot \mathbf{S}\_j = S_i^x S_j^x + S_i^y S_j^y + S_i^z S_j^z.
30+
\mathbf{S}_i \cdot \mathbf{S}_j = S_i^x S_j^x + S_i^y S_j^y + S_i^z S_j^z.
3131
$$
3232

3333
### Basis States
@@ -36,15 +36,15 @@ For a 4-site system with spin-1/2 particles, the Hilbert space has $2^4 = 16$ ba
3636

3737
The basis states are eigen states of $S_i^z$ operators. When it is applied to the $i$'th site, it gives
3838
$$
39-
S\_i^z|\uparrow\rangle = \frac{1}{2}|\uparrow\rangle,
39+
S_i^z|\uparrow\rangle = \frac{1}{2}|\uparrow\rangle,
4040
$$
4141
and
4242
$$
43-
S\_i^z|\downarrow\rangle = -\frac{1}{2}|\downarrow\rangle.
43+
S_i^z|\downarrow\rangle = -\frac{1}{2}|\downarrow\rangle.
4444
$$
4545
To see the result of applying Hamiltonian to the basis states, we need to express the off-diagonal operators, i.e., $S_i^x$ and $S_i^y$ in terms of raising $S^{\dagger}$ and lowering $S^{-}$ operators:
4646
$$
47-
S\_i^x=\frac{1}{2}(S_i^{\dagger}+S_i^{-}),
47+
S_i^x=\frac{1}{2}(S_i^{\dagger}+S_i^{-}),
4848
$$
4949
$$
5050
S_i^y=\frac{1}{2i}(S_i^{\dagger}-S_i^{-}),
@@ -59,21 +59,21 @@ $$
5959
where $S=1/2$ and $s=-1/2, 1/2$.
6060
With the above transformation, the Hamiltonian element becomes
6161
$$
62-
\mathbf{S}\_i \cdot \mathbf{S}\_j = \frac{1}{2}(S_i^{\dagger}S_j^{-}+S_i^{-}S_j^{\dagger})+S\_i^zS\_j^z.
62+
\mathbf{S}_i \cdot \mathbf{S}_j = \frac{1}{2}(S_i^{\dagger}S_j^{-}+S_i^{-}S_j^{\dagger})+S_i^zS_j^z.
6363
$$
6464

6565
### Hamiltonian Matrix
6666

67-
To construct the Hamiltonian matrix, we evaluate the action of $\mathcal{H}$ on each basis state. For instance, consider the term $\mathbf{S}\_1 \cdot \mathbf{S}\_2$:
67+
To construct the Hamiltonian matrix, we evaluate the action of $\mathcal{H}$ on each basis state. For instance, consider the term $\mathbf{S}_1 \cdot \mathbf{S}_2$:
6868

6969
$$
70-
\mathbf{S}\_1 \cdot \mathbf{S}\_2 = \frac{1}{2}(S_1^{\dagger}S_2^{-}+S_1^{-}S_2^{\dagger})+S\_1^zS\_2^z.
70+
\mathbf{S}_1 \cdot \mathbf{S}_2 = \frac{1}{2}(S_1^{\dagger}S_2^{-}+S_1^{-}S_2^{\dagger})+S_1^zS_2^z.
7171
$$
7272

7373
This term flips spins at sites 1 and 2 if they are antiparallel and contributes a factor of $\frac{1}{4}$ if they are parallel. For example:
7474

7575
$$
76-
\mathbf{S}\_1 \cdot \mathbf{S}\_2 | \uparrow \downarrow \uparrow \uparrow \rangle = \frac{1}{4} \left( | \downarrow \uparrow \uparrow \uparrow \rangle - | \uparrow \downarrow \uparrow \uparrow \rangle \right).
76+
\mathbf{S}_1 \cdot \mathbf{S}_2 | \uparrow \downarrow \uparrow \uparrow \rangle = \frac{1}{4} \left( | \downarrow \uparrow \uparrow \uparrow \rangle - | \uparrow \downarrow \uparrow \uparrow \rangle \right).
7777
$$
7878

7979
Repeating this process for all terms in $\mathcal{H}$ and all basis states, we construct the $16 \times 16$ Hamiltonian matrix. For brevity, we do not write the full matrix here, but it can be systematically built using the above rules.

0 commit comments

Comments
 (0)