MC-04 Measurements
Correlation measurements in the directed loop and worm codes
In this tutorial, we will measure correlation functions with the directed loop and worm codes.
Two-dimensional Heisenberg square lattice
Preparing and running the simulation from the command line
The parameter file parm4 sets up Monte Carlo simulations of the quantum mechanical S=1/2 Heisenberg model on a square lattice, and enables various measurement options:
MODEL="spin";
LATTICE="square lattice";
REPRESENTATION="SSE";
MEASURE[Correlations]=true;
MEASURE[Structure Factor]=true;
MEASURE[Green Function]=true;
THERMALIZATION=10000;
SWEEPS=500000;
J= 1;
L=4;
W=4;
T=0.3;
{h=0.1;}Using the standard sequence of commands you can run the simulation using the quantum SSE code.
parameter2xml parm4
dirloop_sse --Tmin 10 --write-xml parm4.in.xmlPreparing and running the simulation using Python
To set up and run the simulation in Python we use the script tutorial4.py:
import pyalps
parms = [{
'LATTICE' : "square lattice",
'MODEL' : "spin",
'MEASURE[Correlations]' : True,
'MEASURE[Structure Factor]' : True,
'MEASURE[Green Function]' : True,
'local_S' : 0.5,
'T' : 0.3,
'J' : 1 ,
'THERMALIZATION' : 10000,
'SWEEPS' : 500000,
'L' : 4,
'h' : 0.1
}]
input_file = pyalps.writeInputFiles('parm4',parms)
res = pyalps.runApplication('dirloop_sse',input_file,Tmin=5)Evaluating the simulation
To look at the results, we now load ALL measurements from output files starting with parm4. The code to do this is in tutorial4.py, but we may again copy it to a new script loader4.py if we ever want to view the results again without running the simulation.
data = pyalps.loadMeasurements(pyalps.getResultFiles())We now loop through all measurements and print them:
for s in pyalps.flatten(data):
if len(s.x)==1:
print s.props['observable'], ' : ', s.y[0]
else:
for (x,y) in zip(s.x,s.y):
print s.props['observable'], x, ' : ', yThe if statement checks whether the measured quantity is a scalar or vector-valued quantity.