Commit 85d5440b authored by Valerio's avatar Valerio
Browse files

Solution ex 11 and text last exercise ;)

parent 0583f9b8
%% Cell type:code id: tags:
``` python
from tenpy.models.lattice import Lattice
from tenpy.models.model import CouplingMPOModel
from tenpy.networks.site import SpinSite
from tenpy.tools.params import get_parameter
from tenpy.algorithms import dmrg
from tenpy.networks.mps import MPS
import numpy as np
import matplotlib.pyplot as plt
import time
import random
```
%% Cell type:markdown id: tags:
# Model Definition
%% Cell type:code id: tags:
``` python
#Create a ComplingMPOModel to describe the system.
#The parameters are passed via model_params
class Heisenberg(CouplingMPOModel):
def __init__(self,model_params):
CouplingMPOModel.__init__(self,model_params)
def init_lattice(self, model_params):
#Here initialize the type of lattice considered
lattice = get_parameter(model_params, 'lattice', self.name, False)
return lattice
def init_terms(self, model_params):
D= get_parameter(model_params, 'D', 0., self.name, True)
#Try to get also the J and lambda paramter in the same way
#J= ...
#lam= ...
#Here implement the couplings of the chain
#D term
self.add_onsite(D, 0, 'Sz Sz')
#Heisenberg interaction
self.add_coupling(J, 0, 'Sx', 0, 'Sx', 1,)
#Implement the remaining couplings for the Heisenberg exchange
#Have a look at the documentation of the function add_coupling()
#
#
#Quadratic Heisenberg term, the one with lambda
#Implement this term yourself
```
%% Cell type:markdown id: tags:
# Phase diagram for $\lambda=0$ and varying $D$
%% Cell type:markdown id: tags:
## Define the model
%% Cell type:code id: tags:
``` python
L=2 #Chain length (2 for the iMPS)
J=1 #Anitferromagnetic interaction
lam=0 #Quadratic term
Dmin=-1
Dmax=2
points=30
d=np.linspace(Dmin,Dmax,points,endpoint=True) #Values considered for D
#Definition of the lattice model
#Define the local Hilbert space, have a look at the documentation of SpinSite
#site=SpinSite(...)
#Define the lattice by looking at the documentation of Lattice
#Inifinite MPS requires periodic boundaries for the lattice
#lat=Lattice(...) #We choose an infinite MPS
```
%% Cell type:markdown id: tags:
## Perform iDMRG
%% Cell type:code id: tags:
``` python
entEnt=[]
entSp=[]
stagMag=[]
for D in d:
#Define the paramters of the model
model_params={
'verbose':0,
'J':J,
'D':D,
'lambda':lam,
'lattice':lat
}
#Create the model
chain=Heisenberg(model_params)
#Define the paramters for the DMRG
dmrg_paramsGs = {
'trunc_params': {
'chi_max': 20 #Maximum bond dimension
},
'verbose': 1
}
#Initialize the MPS with an arbitrary product state
product_state=['up',0]
#Have a look at the documentation MPS.from_product_state()
#psiGs=MPS.from_product_state(...)
#Perform iDMRG
#Check documentation of dmrg.run
#info=dmrg.run(...)
#Check documentation for expectation_value(). Which operator do you want to measure for magnetization?
#mag=psiGs.expectation_value(...) #Measure magnetization
#Implement function to compute staggered magnetization from mag
#staggered=...
stagMag.append(staggered) #Compute staggered magnetization
#Check documentation of entanglement_spectrum() and compute it
#spectrum=...
entSp.append(spectrum[0])
#Check documentation of entanglement_entropy() and compute it
#entropy=...
entEnt.append(entropy[0])
```
%% Cell type:markdown id: tags:
## Study staggered magnetization
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(14,5))
plt.plot(d,stagMag,'o',ls='-',c='k')
plt.xlabel('D');
plt.ylabel('Staggered magnetization');
plt.axvspan(-1, -0.33, alpha=0.2, color='red')
plt.axvspan(-0.33, 1, alpha=0.2, color='b')
plt.axvspan(1, 2, alpha=0.2, color='g')
plt.xlim(-1,2)
```
%% Cell type:markdown id: tags:
## Study of the entanglement entropy
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(14,5))
plt.tight_layout()
plt.plot(d,entEnt,'o',ls='-',c='k')
plt.xlabel('D');
plt.ylabel('Entanglement Entropy');
plt.axvspan(-1, -0.33, alpha=0.2, color='red')
plt.axvspan(-0.33, 1, alpha=0.2, color='b')
plt.axvspan(1, 2, alpha=0.2, color='g')
plt.xlim(-1,2);
```
%% Cell type:markdown id: tags:
## Study of the entanglement spectrum
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(14,5))
plt.tight_layout()
for i in range(len(d)):
for j in range(int(len(entSp[i])/2)):
if abs(entSp[i][2*j]-entSp[i][2*j+1])<1e-4:
plt.scatter(d[i]-0.01,entSp[i][2*j],c='k',s=50,marker='.')
plt.scatter(d[i]+0.01,entSp[i][2*j+1],c='k',s=50,marker='.')
plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j],entSp[i][2*j]],c='k')
else:
plt.scatter(d[i],entSp[i][2*j],c='k',s=50,marker='.')
plt.scatter(d[i],entSp[i][2*j+1],c='k',s=50,marker='.')
plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j],entSp[i][2*j]],c='k')
plt.plot([d[i]-0.03,d[i]+0.03],[entSp[i][2*j+1],entSp[i][2*j+1]],c='k')
plt.xlabel('D');
plt.ylabel('Entanglement Spectrum');
plt.axvspan(-1.1, -0.33, alpha=0.2, color='red')
plt.axvspan(-0.33, 1, alpha=0.2, color='b')
plt.axvspan(1, 2.1, alpha=0.2, color='g')
plt.xlim(-1.1,2.1);
```
%% Cell type:markdown id: tags:
# Phase diagram for $D=0$ and varying $\lambda$
%% Cell type:code id: tags:
``` python
#Do the same studies for this new situation.
```