Code: Select all

```
from tenpy.models.bose_hubbard_chain import BoseHubbardChain
from tenpy.networks.mps import MPS
import numpy as np
import matplotlib.pyplot as plt
def show_bosonic_occupation(state):
L = state.L
boson_site_number = np.arange(L)
n = state.expectation_value('N')
plt.plot(boson_site_number, n, 'k*')
plt.title("Expectation values of occupation\n")
plt.ylabel('$\langle n\\rangle$')
plt.xlabel('site')
plt.grid()
def psi_superposition(model_params):
model_params['conserve'] = None
M = BoseHubbardChain(model_params)
sites = M.lat.mps_sites()
initial_state = [0]*(model_params['L'])
psi0 = MPS.from_product_state(sites, initial_state , bc='finite')
initial_state = [1]*(model_params['L'])
psi1 = MPS.from_product_state(sites, initial_state , bc='finite')
return psi0.add(psi1, 0.5, 0.5)
""" This is a naive approach to what I want. """
def psi_conserved_superposition(model_params):
model_params['conserve'] = 'N'
M = BoseHubbardChain(model_params)
sites = M.lat.mps_sites()
initial_state = [0]*(model_params['L'])
psi0 = MPS.from_product_state(sites, initial_state , bc='finite')
initial_state = [1]*(model_params['L'])
psi1 = MPS.from_product_state(sites, initial_state , bc='finite')
return psi0.add(psi1, 0.5, 0.5)
def main():
L = 40
t=1.0
U = 1.0
Mu=16.0
verbose_model = 0
model_params = {'L': L,'n_max': 2, 'filling': 0.5, 'bc_MPS': 'finite',
't': t, 'U': U, 'mu': Mu, 'verbose': verbose_model}
psi = psi_superposition(model_params) # works great
#psi = psi_conserved_superposition(model_params) # doesn't work
show_bosonic_occupation(psi)
return 0
if __name__ == '__main__':
main()
```