Commit 9df00b64 authored by Jonas Schwab's avatar Jonas Schwab
Browse files

Small tweaking on notebooks

parent e3834c05
%% Cell type:markdown id: tags:
# A minimal ALF run
%% Cell type:markdown id: tags:
In this bare-bones example we use the [pyALF](https://git.physik.uni-wuerzburg.de/ALF/pyALF) interface to run the canonical Hubbard model on a default configuration: a $6\times6$ square grid, with interaction strength $U=4$ and inverse temperature $\beta = 5$.
Bellow we go through the steps for performing the simulation and outputting observables.
---
**1.** Import `Simulation` class from the `py_alf` python module, which provides the interface with ALF:
%% Cell type:code id: tags:
``` python
import os
from py_alf import Simulation # Interface with ALF
```
%% Cell type:markdown id: tags:
**2.** Create an instance of `Simulation`, setting parameters as desired:
%% Cell type:code id: tags:
``` python
sim = Simulation(
"Hubbard", # Hamiltonian
{ # Model and simulation parameters for each Simulation instance
"Model": "Hubbard", # Base model
"Lattice_type": "Square"}, # Lattice type
alf_dir=os.getenv('ALF_DIR', './ALF'), # Directory with ALF source code. Gets it from
# environment variable ALF_DIR, if present
)
```
%% Cell type:markdown id: tags:
**3.** Compile ALF, downloading it first from the [ALF repository](https://git.physik.uni-wuerzburg.de:ALF) if not found locally. This may take a few minutes:
%% Cell type:code id: tags:
``` python
sim.compile() # Compilation needs to be performed only once
```
%% Output
Compiling ALF... Done.
%% Cell type:markdown id: tags:
**4.** Perform the simulation as specified in `sim`:
%% Cell type:code id: tags:
``` python
sim.run() # Perform the actual simulation in ALF
```
%% Output
Prepare directory "/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square" for Monte Carlo run.
Prepare directory "/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square" for Monte Carlo run.
Create new directory.
Run /home/stafusa/ALF/ALF/Prog/Hubbard.out
Run /home/jonas/Programs/ALF/Prog/Hubbard.out
%% Cell type:markdown id: tags:
**5.** Perform some simple analyses:
%% Cell type:code id: tags:
``` python
sim.analysis() # Perform default analysis; list observables
```
%% Output
Analysing Ener_scal
Analysing Part_scal
Analysing Pot_scal
Analysing Kin_scal
Analysing Den_eq
Analysing Ener_scal
Analysing Pot_scal
Analysing SpinT_eq
Analysing SpinZ_eq
Analysing Green_eq
Analysing SpinXY_eq
Analysing SpinT_eq
Analysing SpinXY_tau
Analysing Green_eq
Analysing Den_eq
Analysing SpinZ_tau
Analysing Den_tau
Analysing Green_tau
Analysing SpinXY_tau
Analysing SpinT_tau
Analysing Green_tau
%% Cell type:markdown id: tags:
**6.** Store computed observables list:
%% Cell type:code id: tags:
``` python
obs = sim.get_obs() # Dictionary for the observables
```
%% Output
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Kin_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Part_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Ener_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Pot_scalJ 1
/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square/Pot_scalJ 1
/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square/Ener_scalJ 1
/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square/Kin_scalJ 1
/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square/Part_scalJ 1
%% Cell type:markdown id: tags:
which are available for further analyses. For instance, the internal energy of the system (and its error) is accessed by:
%% Cell type:code id: tags:
``` python
obs['Ener_scalJ']['obs']
```
%% Output
array([[-29.893866, 0.109235]])
array([[-29.84515829, 0.18265326]])
%% Cell type:markdown id: tags:
---
**7.** Running again: The simulation can be resumed to increase the precision of the results.
%% Cell type:code id: tags:
``` python
sim.run()
sim.analysis()
obs2 = sim.get_obs()
print(obs2['Ener_scalJ']['obs'])
print("\nRunning again reduced the error from ", obs['Ener_scalJ']['obs'][0][1]," to ", obs2['Ener_scalJ']['obs'][0][1], ".")
```
%% Output
Prepare directory "/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square" for Monte Carlo run.
Prepare directory "/home/jonas/Programs/pyALF/Notebooks/ALF_data/Hubbard_Square" for Monte Carlo run.
Resuming previous run.
Run /home/stafusa/ALF/ALF/Prog/Hubbard.out
Analysing Ener_scal
Run /home/jonas/Programs/ALF/Prog/Hubbard.out
Analysing Part_scal
Analysing Pot_scal
Analysing Kin_scal
Analysing Den_eq
Analysing SpinZ_eq
Analysing Green_eq
Analysing SpinXY_eq
Analysing SpinT_eq
Analysing SpinXY_tau
Analysing SpinZ_tau
Analysing Den_tau
Analysing Green_tau
Analysing SpinT_tau
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Kin_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Part_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Ener_scalJ 1
/home/stafusa/ALF/pyALF/Notebooks/ALF_data/Hubbard_Square/Pot_scalJ 1
[[-29.839345 0.049995]]
Running again reduced the error from 0.109235 to 0.049995 .
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-8-8fe25d84a329> in <module>
1 sim.run()
----> 2 sim.analysis()
3 obs2 = sim.get_obs()
4 print(obs2['Ener_scalJ']['obs'])
5 print("\nRunning again reduced the error from ", obs['Ener_scalJ']['obs'][0][1]," to ", obs2['Ener_scalJ']['obs'][0][1], ".")
~/Programs/pyALF/py_alf.py in analysis(self)
147 os.path.join(self.sim_dir, "Temp_{}".format(i)))
148 else:
--> 149 analysis(self.alf_dir, self.sim_dir)
150
151 def get_obs(self, names=None):
~/Programs/pyALF/py_alf.py in analysis(alf_dir, sim_dir)
330 print('Analysing {}'.format(name))
331 executable = os.path.join(alf_dir, 'Analysis', 'ana.out')
--> 332 subprocess.run([executable, name], check=True, env=env)
333
334 for name in os.listdir():
/opt/intel/intelpython3/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
486 kwargs['stderr'] = PIPE
487
--> 488 with Popen(*popenargs, **kwargs) as process:
489 try:
490 stdout, stderr = process.communicate(input, timeout=timeout)
/opt/intel/intelpython3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
798 c2pread, c2pwrite,
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
802 # Cleanup if the child failed starting.
/opt/intel/intelpython3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1549 if errno_num == errno.ENOENT:
1550 err_msg += ': ' + repr(err_filename)
-> 1551 raise child_exception_type(errno_num, err_msg, err_filename)
1552 raise child_exception_type(err_msg)
1553
FileNotFoundError: [Errno 2] No such file or directory: '/home/jonas/Programs/ALF/Analysis/ana.out': '/home/jonas/Programs/ALF/Analysis/ana.out'
%% Cell type:markdown id: tags:
**Note**: To run a fresh simulation - instead of performing a refinement over previous run(s) - the Monte Carlo run directory should be deleted before rerunning.
%% Cell type:markdown id: tags:
---
## Exercises
1. Rerun once again and check the new improvement in precision.
2. Look at a few other observables (`sim.analysis()` outputs the names of those available).
3. Change the lattice size by adding, e.g., `"L1": 4,` and `"L2": 1,` to the simulation parameters definitions of `sim` (step 2).
......
This diff is collapsed.
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