I have been reading the Overview section of the tenpy documentation. This can be found in the following link: https://tenpy.readthedocs.io/en/latest/ ... rview.html
Today I have looked at the SpinHalfSites sample code. After I have understood most of it, I adapted the code to implement a lattice of six spin-2 particles. The code and the output are provided below.
Input:
Code: Select all
# Let us play with SpinSite for spin S
# Step 1: Make the important imports
from tenpy.networks.site import SpinSite
from tenpy.networks.mps import MPS
from tenpy.networks.mpo import MPO
# Step 2: Create one spin S=2 object and check that we get the correct matrix Sz, Sp, Sm
spin2 = SpinSite(S=2, conserve='Sz')
print('The Sz matrix is')
print(spin2.Sz.to_ndarray())
print('The S+ matrix is')
print(spin2.Sp.to_ndarray())
print('The S- matrix is')
print(spin2.Sm.to_ndarray())
# Step 3: Create a 1D lattice of N = 6 spin 2 particles
N = 6
sites2 = [spin2] * N
print(sites2)
#Step 4: Create one state for the sites (i.e. one specific way the spins are "pointing" - here "up" = 4 and "down" = 0)
pstate2 = [0,1,2,3,4,2]
print(pstate2)
#Step 5: Create a MPS wave function
psi = MPS.from_product_state(sites2, pstate2, bc="finite")
print("<Sz> =", psi.expectation_value("Sz"))
# <Sz> = [ 0.5 -0.5 0.5 -0.5 0.5 -0.5]
print("<Sp_i Sm_j> =", psi.correlation_function("Sz", "Sz"), sep="\n")
# <Sp_i Sm_j>
Code: Select all
The Sz matrix is
[[-2. 0. 0. 0. 0.]
[ 0. -1. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 1. 0.]
[ 0. 0. 0. 0. 2.]]
The S+ matrix is
[[0. 0. 0. 0. 0. ]
[2. 0. 0. 0. 0. ]
[0. 2.44948974 0. 0. 0. ]
[0. 0. 2.44948974 0. 0. ]
[0. 0. 0. 2. 0. ]]
The S- matrix is
[[0. 2. 0. 0. 0. ]
[0. 0. 2.44948974 0. 0. ]
[0. 0. 0. 2.44948974 0. ]
[0. 0. 0. 0. 2. ]
[0. 0. 0. 0. 0. ]]
[SpinSite(S=2.0, 'Sz'), SpinSite(S=2.0, 'Sz'), SpinSite(S=2.0, 'Sz'), SpinSite(S=2.0, 'Sz'), SpinSite(S=2.0, 'Sz'), SpinSite(S=2.0, 'Sz')]
[0, 1, 2, 3, 4, 2]
<Sz> = [-2. -1. 0. 1. 2. 0.]
<Sp_i Sm_j> =
[[ 4. 2. 0. -2. -4. 0.]
[ 2. 1. 0. -1. -2. 0.]
[ 0. 0. 0. 0. 0. 0.]
[-2. -1. 0. 1. 2. 0.]
[-4. -2. 0. 2. 4. 0.]
[ 0. 0. 0. 0. 0. 0.]]
https://tenpy.github.io/reference/tenpy ... nSite.html
Here is the code that I ran:
Code: Select all
# Now let us try to implement a latice of bosons
# Step 1: Important Imports
from tenpy.networks.site import BosonSite
from tenpy.networks.mps import MPS
from tenpy.networks.mpo import MPO
#Step 2: Initialize one Boson site
boson = BosonSite(Nmax = 10, conserve ='N', filling=0.0)
print(boson.N.to_ndarray())
Code: Select all
[[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 2. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 3. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 4. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 5. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 6. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 7. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 8. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 9. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10.]]
Question 2: Suppose I want to create a lattice of 5 boson sites, each of which can hold at most 10 bosons, such that the total number of bosons in the entire lattice is fixed to be, let's say, 15. How would I do that?
Question 3: In the code for the spin-2 sites, I was able to create a variable called pstate2 that contained one specific set of spin orientations for the six spin-2 particles. This pstate2 was required to create the MPS wavefunction. Since I am trying to create an MPS state for my lattice of boson sites (so far there is only one site) how can I create a variable similar to pstate2? For instance, suppose I create a lattice of 5 boson sites with the properties mentioned in question 2. Then one possible state is as follows: site 1 = 6 bosons, site 2 = 4 bosons, site 3 = 0 bosons, site 4 = 4 bosons, site 5 = 1 boson. Would my pstate2 variable be [6,4,0,4,1] (I tried running it by creating an MPS state and no error message popped up, but I am not sure if I did it correctly)? If not, that how can I implement this initial state?
Question 4: In the spin-2 boson lattice example, after I was able to implement the MPS state, I was able to print out the expectation values of S_z? What expectation values can I print out for my lattice of boson sites?