Commit be71049b authored by Jefferson Stafusa E. Portela's avatar Jefferson Stafusa E. Portela
Browse files

Minor - removing white space in equation which confuses nbconvert.

parent 635835f2
%% Cell type:markdown id: tags:
# ALF Tutorial 2.0
## Introductory examples and exercises
%% Cell type:markdown id: tags:
This notebook is part of the [Tutorial 2.0](https://git.physik.uni-wuerzburg.de/ALF/ALF_Tutorial) for the quantum Monte Carlo simulation package [*Algorithms for Lattice Fermions* - ALF](https://git.physik.uni-wuerzburg.de/ALF/ALF_code), and can be found, together with its required files, in the [pyALF repository](https://git.physik.uni-wuerzburg.de/ALF/pyALF).
ALF is compiled from source, which is downloaded from the [ALF repository](https://git.physik.uni-wuerzburg.de:ALF) when not found locally.
[**REMEMBER TO UPDATE GIT ADDRESSES**]
%% Cell type:markdown id: tags:
# Projective algorithm
%% Cell type:markdown id: tags:
The projective approach is the method of choice if one is interested in ground-state properties. The starting point is a pair of trial wave functions, $|\Psi_{T,L/R} \rangle$, that are not orthogonal to the ground state $|\Psi_0 \rangle$:
$$
\langle \Psi_{T,L/R} | \Psi_0 \rangle \neq 0.
$$
The ground-state expectation value of any observable $\hat{O} $ can then be computed by propagation along the imaginary time axis:
The ground-state expectation value of any observable $\hat{O}$ can then be computed by propagation along the imaginary time axis:
$$
\frac{ \langle \Psi_0 | \hat{O} | \Psi_0 \rangle }{ \langle \Psi_0 | \Psi_0 \rangle} = \lim_{\theta \rightarrow \infty}
\frac{ \langle \Psi_{T,L} | e^{-\theta \hat{H}} e^{-(\beta - \tau)\hat{H} }\hat{O} e^{- \tau \hat{H} } e^{-\theta \hat{H}} | \Psi_{T,R} \rangle }
{ \langle \Psi_{T,L} | e^{-(2 \theta + \beta) \hat{H} } | \Psi_{T,R} \rangle } ,
$$
where $\beta$ defines the imaginary time range where observables (time displaced and equal time) are measured and $\tau$ varies from $0$ to $\beta$ in the calculation of time-displace observables.
---
**1.** Import `Simulation` class from the `py_alf` python module, which provides the interface with ALF, as well as mathematics and plotting packages:
%% Cell type:code id: tags:
``` python
from py_alf import Simulation # Interface with ALF
#
import numpy as np # Numerical library
from scipy.optimize import curve_fit # Numerical library
import matplotlib.pyplot as plt # Plotting library
```
%% Cell type:markdown id: tags:
**2.** Create instances of `Simulation`, specifying the necessary parameters, in particular the `Projector` to `True`:
%% Cell type:code id: tags:
``` python
sims = [] # Vector of Simulation instances
print('Theta values used:')
for theta in [5, 10, 20]: # Values of Theta
print(theta)
sim = Simulation(
'Hubbard', # Hamiltonian
{ # Model and simulation parameters for each Simulation instance
'Model': 'Hubbard', # Base model
'Lattice_type': 'N_leg_ladder', # Lattice type
'L1': 4, # Lattice length in the first unit vector direction
'L2': 1, # Lattice length in the second unit vector direction
'Checkerboard': False, # Whether checkerboard decomposition is used or not
'Symm': True, # Whether symmetrization takes place
'Projector': True, # Whether to use the projective algorithm
'Theta': theta, # Projector parameter
'ham_T': 1.0, # Hopping parameter
'ham_U': 4.0, # Hubbard interaction
'ham_Tperp': 0.0, # For bilayer systems
'beta': 1.0, # Inverse temperature
'Ltau': 0, # '1' for time-displaced Green functions; '0' otherwise
'NSweep': 400, # Number of sweeps
'NBin': 10, # Number of bins
'Dtau': 0.05, # Only dtau varies between simulations, Ltrot=beta/Dtau
'Mz': True, # If true, sets the M_z-Hubbard model: Nf=2, N_sum=1,
}, # HS field couples to z-component of magnetization
alf_dir='~/Programs/ALF', # Local ALF copy, if present
)
sims.append(sim)
```
%% Output
Theta values used:
5
10
20
%% Cell type:markdown id: tags:
**3.** Compile ALF, downloading it first if not found locally. This may take a few minutes:
%% Cell type:code id: tags:
``` python
sims[0].compile() # Compilation needs to be performed only once
```
%% Output
Compiling ALF... Done.
%% Cell type:markdown id: tags:
**4.** Perform the simulations, as specified in each element of `sim`:
%% Cell type:code id: tags:
``` python
for i, sim in enumerate(sims):
sim.run() # Perform the actual simulation in ALF
```
%% Output
Prepare directory "/home/stafusa/ALF/pyALF/Hubbard_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_Projector=True_Theta=5_T=1.0_U=4.0_Tperp=0.0_beta=1.0_Dtau=0.05_Mz=True" for Monte Carlo run.
Create new directory.
Run /home/stafusa/Programs/ALF/Prog/Hubbard.out
Prepare directory "/home/stafusa/ALF/pyALF/Hubbard_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_Projector=True_Theta=10_T=1.0_U=4.0_Tperp=0.0_beta=1.0_Dtau=0.05_Mz=True" for Monte Carlo run.
Create new directory.
Run /home/stafusa/Programs/ALF/Prog/Hubbard.out
Prepare directory "/home/stafusa/ALF/pyALF/Hubbard_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_Projector=True_Theta=20_T=1.0_U=4.0_Tperp=0.0_beta=1.0_Dtau=0.05_Mz=True" for Monte Carlo run.
Create new directory.
Run /home/stafusa/Programs/ALF/Prog/Hubbard.out
%% Cell type:markdown id: tags:
**5.** Calculate the internal energies:
%% Cell type:code id: tags:
``` python
%%capture
ener = np.empty((len(sims), 2)) # Matrix for storing energy values
thetas = np.empty((len(sims),)) # Matrix for Thetas values, for plotting
for i, sim in enumerate(sims):
print(sim.sim_dir) # Directory containing the simulation output
sim.analysis() # Perform default analysis
thetas[i] = sim.sim_dict['Theta'] # Store Theta value
ener[i] = sim.get_obs(['Ener_scalJ'])['Ener_scalJ']['obs'] # Store internal energy
```
%% Cell type:markdown id: tags:
Where the _cell magic_ `%%capture` suppresses the output of `sim.analysis()`, which lists the data directories and observables.
%% Cell type:code id: tags:
``` python
print('For Theta values', thetas, 'the measured energies are:\n', ener)
```
%% Output
For Theta values [ 5. 10. 20.] the measured energies are:
[[-2.137697 0.025552]
[-2.108235 0.023964]
[-2.089294 0.025426]]
%% Cell type:code id: tags:
``` python
plt.errorbar(1/thetas, ener[:, 0], ener[:, 1])
```
%% Output
<ErrorbarContainer object of 3 artists>
%% Cell type:markdown id: tags:
---
## Exercises
1. Try .......................... reference plot below (found in Sec. 3.3 - Comparison of finite and projective codes - of the [ALF documentation](https://git.physik.uni-wuerzburg.de/ALF/ALF_code/-/blob/master/Documentation/ALF_v1.0.pdf)).
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment