# ALPS 2 Tutorials:MC-02 Susceptibilities

In this tutorial we will learn to calculate susceptibilities for classical and quantum Heisenberg models and contrast the behavior of chains and ladders as well as classical and quantum models. The parameter files, Python scripts and Vistrails files for this tutorial are available in the directory mc-02-susceptibilities

# Susceptibility of classical one-dimensional Heisenberg models

## The one-dimensional Heisenberg classical chain

### Preparing and running the simulation from the command line

The parameter file classical2/parm2a sets up Monte Carlo simulations of the classical Heisenberg model on a one-dimensional chain with 60 sites for a couple of temperatures (T=0.05, 0.1, ..., 1.5) using cluster updates.To set up and run the simulation on the command line you first create a parameter file parm2a :

LATTICE="chain lattice"
L=60
J=-1
THERMALIZATION=15000
SWEEPS=500000
UPDATE="cluster"
MODEL="Heisenberg"
{T=0.05;}
{T=0.1;}
{T=0.2;}
{T=0.3;}
{T=0.4;}
{T=0.5;}
{T=0.6;}
{T=0.7;}
{T=0.8;}
{T=0.9;}
{T=1.0;}
{T=1.25;}
{T=1.5;}


and then tun the simulation by using the standard sequence of commands

parameter2xml parm2a
spinmc --Tmin 10 --write-xml parm2a.in.xml


To extract the results we recommend the Python evaluation tools discussed below

### Preparing and running the simulation using Python

To set up and run the simulation in Python we use the script tutorial2a.py. The first parts of this script imports the required modules and then prepares the input files as a list of Python dictionaries:

import pyalps
import matplotlib.pyplot as plt
import pyalps.pyplot

parms = []
for t in [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0]:
parms.append(
{
'LATTICE'        : "chain lattice",
'T'              : t,
'J'              : -1 ,
'THERMALIZATION' : 10000,
'SWEEPS'         : 500000,
'UPDATE'         : "cluster",
'MODEL'          : "Heisenberg",
'L'              : 60
}
)


To run this, launch your python interpreter using the convenience scripts alpspython or vispython.

We next convert this into a job file in XML format and run the simulation:

input_file = pyalps.writeInputFiles('parm2a',parms)
pyalps.runApplication('spinmc',input_file,Tmin=5,writexml=True)


We now have the same output files as in the command line version.

### Evaluating the simulation and preparing plots using Python

To load the results and prepare plots we load the results from the output files and collect the susceptibility as a function of temperature from all output files starting with parm2a. The script is again in tutorial2a.py

data = pyalps.loadMeasurements(pyalps.getResultFiles(prefix='parm2a'),'Susceptibility')
susceptibility = pyalps.collectXY(data,x='T',y='Susceptibility')


To make plots we call the pyalps.pyplot.plot and then set some nice labels, a title, and a range of y-values:

plt.figure()
pyalps.pyplot.plot(susceptibility)
plt.xlabel('Temperature $T/J$')
plt.ylabel('Susceptibility $\chi J$')
plt.ylim(0,0.22)
plt.title('Classical Heisenberg chain')
plt.show()


### Setting up and running the simulation in Vistrails

To run the simulation in Vistrails open the file mc-02-tutorial.vt and look at the workflow labeled "Classical Heisenberg chain". Click on "Execute" to prepare the input file, run the simulation and create the output figure.

## The one-dimensional classical Heisenberg ladder

The Heisenberg ladder is simulated in a very similar way. The main differences (besides naming the files parm2b*) is a change of the LATTICE and that we have two couplings J0 and J1.

### Preparing and running the simulation from the command line

To set up and run the simulation on the command line you first create a parameter file parm2b :

LATTICE="ladder" L=60 J0=-1 J1=-1 THERMALIZATION=15000 SWEEPS=150000 UPDATE="cluster" MODEL="Heisenberg" {T=0.05;} {T=0.1;} {T=0.2;} {T=0.3;} {T=0.4;} {T=0.5;} {T=0.6;} SWEEPS=500000 {T=0.7;} {T=0.8;} {T=0.9;} {T=1.0;} {T=1.25;} {T=1.5;} {T=1.75;} {T=2.0;}

You may again run the simulation for this model by typing the sequence

parameter2xml parm2b
spinmc --Tmin 10 --write-xml parm2b.in.xml


### Preparing and running the simulation using Python

To set up and run the simulation in Python we use the script tutorial2b.py: import

pyalps
import matplotlib.pyplot as plt
import pyalps.pyplot

parms = []
for t in [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0]:
parms.append(
{
'T'              : t,
'J'              : -1 ,
'THERMALIZATION' : 10000,
'SWEEPS'         : 500000,
'UPDATE'         : "cluster",
'MODEL'          : "Heisenberg",
'L'              : 60
}
)

input_file = pyalps.writeInputFiles('parm2b',parms)
pyalps.runApplication('spinmc',input_file,Tmin=5)


### Evaluating the simulation and preparing plots using Python

The plotting is again nearly identical to before - up to a change in title and file names. The script is script is again in tutorial2b.py:

data = pyalps.loadMeasurements(pyalps.getResultFiles(prefix='parm2b'),'Susceptibility')
susceptibility = pyalps.collectXY(data,x='T',y='Susceptibility')

plt.figure()
pyalps.pyplot.plot(susceptibility)
plt.xlabel('Temperature $T/J$')
plt.ylabel('Susceptibility $\chi J$')
plt.ylim(0,0.22)
plt.show()


### Setting up and running the simulation in Vistrails

To run the simulation in Vistrails open the file mc-02-tutorial.vt and look at the workflow labeled "Classical Heisenberg ladder". Click on "Execute" to prepare the input file, run the simulation and create the output figure.

## Questions

• How does the susceptibility depend on the lattice?
• Bonus: You can study larger system sizes and different types of lattices ("cubic lattice", "triangular lattice", check the file lattices.xml), as well.

# Susceptibility of one-dimensional quantum Heisenberg models

## The one-dimensional quantum Heisenberg chain

The main change when going to quantum models is that we use the ALPS model library to specify the model, and the ALPS looper QMC code to run the simulations. Note also that in quantum models there is usually a different sign convention for the couplings: positive couplings refer to the antiferromagnet

### Preparing and running the simulation from the command line

To set up and run the simulation on the command line you first create a parameter file parm2c :

   LATTICE="chain lattice"
MODEL="spin"
local_S=1/2
L=60
J=1
THERMALIZATION=15000
SWEEPS=150000
ALGORITHM="loop"
{T=0.05;}
{T=0.1;}
{T=0.2;}
{T=0.3;}
{T=0.4;}
{T=0.5;}
{T=0.6;}
{T=0.7;}
{T=0.75;}
{T=0.8;}
{T=0.9;}
{T=1.0;}
{T=1.25;}
{T=1.5;}
{T=1.75;}
{T=2.0;}


The looper code requires the additional ALGORITHM parameter to choose the algorithm and representation.

The simulation is then run as:

 parameter2xml parm3a
loop --auto-evaluate parm3a.in.xml


Note the --auto-evaluate option required by the looper code to automatically evaluate all results.

### Preparing and running the simulation using Python

To set up and run the simulation in Python we use the script tutorial2c.py:

import pyalps
import matplotlib.pyplot as plt
import pyalps.pyplot

parms = []
for t in [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0]:
parms.append(
{
'LATTICE'        : "chain lattice",
'MODEL'          : "spin",
'local_S'        : 0.5,
'T'              : t,
'J'              : 1 ,
'THERMALIZATION' : 10000,
'SWEEPS'         : 150000,
'L'              : 60,
'ALGORITHM'      : "loop"
}
)


After running the simulation we need to call the evaluateLoop function and pass it the list of output files:

input_file = pyalps.writeInputFiles('parm2c',parms)
res = pyalps.runApplication('loop',input_file)
output_file = res
pyalps.evaluateLoop(output_file)


### Evaluating the simulation and preparing plots using Python

The plotting is again nearly identical to before - up to a change in title and file names. The script is script is again in tutorial2c.py:

data = pyalps.loadMeasurements(pyalps.getResultFiles(prefix='parm2c'),'Susceptibility')
susceptibility = pyalps.collectXY(data,x='T',y='Susceptibility')

plt.figure()
pyalps.pyplot.plot(susceptibility)
plt.xlabel('Temperature $T/J$')
plt.ylabel('Susceptibility $\chi J$')
plt.ylim(0,0.22)
plt.title('Quantum Heisenberg chain')
plt.show()


### Setting up and running the simulation in Vistrails

To run the simulation in Vistrails open the file mc-02-tutorial.vt and look at the workflow labeled "Quantum Heisenberg chain". Click on "Execute" to prepare the input file, run the simulation and create the output figure.

## The one-dimensional quantum Heisenberg ladder

We finally look at a quantum Heisenberg ladder. By now you should be an expert ALPS user so that we only give the input files and scripts.

### Preparing and running the simulation from the command line

To set up and run the simulation on the command line you first create a parameter file parm2d :

 LATTICE="ladder"
MODEL="spin"
local_S=1/2
L=60
J0=1
J1=1
THERMALIZATION=15000
SWEEPS=150000
ALGORITHM="loop"
{T=0.1;}
{T=0.2;}
{T=0.3;}
{T=0.4;}
{T=0.5;}
{T=0.6;}
{T=0.7;}
{T=0.8;}
{T=1.0;}
{T=1.25;}
{T=1.5;}
{T=1.75;}
{T=2.0;}


And you run it again using

 parameter2xml parm2d
loop --auto-evaluate parm2d.in.xml


### Preparing and running the simulation using Python

To set up and run the simulation in Python we use the script tutorial2d.py:

import pyalps
import matplotlib.pyplot as plt
import pyalps.pyplot

parms = []
for t in [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0]:
parms.append(
{
'MODEL'          : "spin",
'local_S'        : 0.5,
'T'              : t,
'J0'             : 1 ,
'J1'             : 1 ,
'THERMALIZATION' : 10000,
'SWEEPS'         : 150000,
'L'              : 60,
'ALGORITHM'      : "loop"
}
)


input_file = pyalps.writeInputFiles('parm2d',parms) res = pyalps.runApplication('loop',input_file) output_file = res pyalps.evaluateLoop(output_file)

### Evaluating the simulation and preparing plots using Python

The plotting is again nearly identical to before - up to a change in title and file names. The script is script is again in tutorial2d.py:

data = pyalps.loadMeasurements(pyalps.getResultFiles(prefix='parm2d'),'Susceptibility')
susceptibility = pyalps.collectXY(data,x='T',y='Susceptibility')

plt.figure()
pyalps.pyplot.plot(susceptibility)
plt.xlabel('Temperature $T/J$')
plt.ylabel('Susceptibility $\chi J$')
plt.ylim(0,0.22)
plt.show()


### Setting up and running the simulation in Vistrails

To run the simulation in Vistrails open the file mc-02-tutorial.vt and look at the workflow labeled "Quantum Heisenberg ladder". Click on "Execute" to prepare the input file, run the simulation and create the output figure.

# Combining all simulations

We finally want to combine all four plots.

## Using Python

After running all four simulations you can use the script tutorial2full.py.

First load all results and flatten the data structure to one list of results:

import pyalps
import matplotlib.pyplot as plt
import pyalps.pyplot

data = pyalps.loadMeasurements(pyalps.getResultFiles(),'Susceptibility')
data = pyalps.flatten(data)


Then collect the susceptibility as a function of temperature, into different data sets depending on the value of the LATTICE and MODEL parameters:

susceptibility = pyalps.collectXY(data,x='T',y='Susceptibility',foreach=['MODEL','LATTICE'])


Next, write some Python code to set some sensible labels, and print the properties of each set to show the parameters:

for s in susceptibility:
if s.props['LATTICE']=='chain lattice':
s.props['label'] = "chain"
if s.props['MODEL']=='spin':
s.props['label'] = "quantum " + s.props['label']
elif s.props['MODEL']=='Heisenberg':
s.props['label'] = "classical " + s.props['label']


Finally make a plot:

plt.figure()
pyalps.pyplot.plot(susceptibility)
plt.xlabel('Temperature $T/J$')
plt.ylabel('Susceptibility $\chi J$')
plt.ylim(0,0.25)
plt.legend()
plt.show()


## Using Vistrails

The same plot can also be easily created in Vistrails in the file mc-02-tutorial.vt by executing the workflow labeled "all plots".

# Questions

• Is there a difference between the classical and quantum calculation?
• How does the susceptibility depend on the lattice?
• Why does the susceptibility change?

© 2003-2010 by Simon Trebst, Fabien Alet, Matthias Troyer, Synge Todo, and Emanuel Gull