Exemplo n.º 1
0
# define model params
L=100 # system size
J=1.0 #uniform hopping
deltaJ=0.2 # hopping difference
Delta=0.2 # staggered potential
# define site-coupling lists
hopping=[[J+deltaJ*(-1)**i,i,(i+1)%L] for i in range(L)] # PBC
stagg_pot=[[Delta,i] for i in range(L)]	
# define basis
basis=spin_basis_1d(L,Nup=1,pauli=False)
basis_args = (L,)
blocks=(dict(Nup=1,pauli=False,kblock=i,a=2) for i in range(L//2))
# define static and dynamic lists
static=[["+-",hopping],["-+",hopping],['z',stagg_pot]]
dynamic=[]
#### calculate Hamiltonian
H=hamiltonian(static,dynamic,basis=basis,dtype=np.float64)
E=H.eigvalsh()

_,Hblock = block_diag_hamiltonian(blocks,static,dynamic,spin_basis_1d,basis_args,np.complex128)
Eblock=Hblock.eigvalsh()

#print(_.shape)

print(E)
print(Eblock)

plt.scatter(np.arange(L),E)
plt.show()

Exemplo n.º 2
0
stagg_pot=[[Delta*(-1)**i,i] for i in range(L)]	
# define static and dynamic lists
static=[["+-",hop_pm],["-+",hop_mp],['n',stagg_pot]]
dynamic=[]
# build real-space Hamiltonian
H=hamiltonian(static,dynamic,basis=basis,dtype=np.float64)
print(H.toarray())
# diagonalise real-space Hamiltonian
E,V=H.eigh()
#
##### compute Fourier transform and momentum-space Hamiltonian #####
# define basis blocks and arguments
blocks=[dict(Nf=1,kblock=i,a=2) for i in range(L//2)] # only L//2 distinct momenta
basis_args = (L,)
# construct block-diagonal Hamiltonian
FT,Hblock = block_diag_hamiltonian(blocks,static,dynamic,spinless_fermion_basis_1d,
						basis_args,np.complex128,get_proj_kwargs=dict(pcon=True))
print(np.around(Hblock.toarray(),2))
# diagonalise momentum-space Hamiltonian
Eblock,Vblock=Hblock.eigh()
#
##### plot spectra
import matplotlib.pyplot as plt # plotting library
plt.plot(np.arange(H.Ns),E/L,
					marker='o',color='b',label='real space')
plt.plot(np.arange(Hblock.Ns),Eblock/L,
					marker='x',color='r',markersize=2,label='momentum space')
plt.xlabel('state number',fontsize=16)
plt.ylabel('energy',fontsize=16)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.legend(fontsize=16)
Exemplo n.º 3
0
def test():
    L = 5

    start = 0
    stop = 10
    num = 10

    J = [[1.0, i, (i + 1) % L] for i in range(L)]
    h = [[1.0, i] for i in range(L)]

    static = [["xx", J], ["yy", J], ["zz", J]]
    dynamic = [["z", h, np.sin, ()]]

    blocks = []

    for Nup in range(L + 1):
        blocks.append({"Nup": Nup})

    H_block = block_diag_hamiltonian(blocks, static, dynamic, spin_basis_1d,
                                     (L, ), np.float64)
    H = hamiltonian(static, dynamic, N=L)

    for t in np.linspace(0, 2 * np.pi):
        E = H.eigvalsh(time=t)
        E_blocks = H.eigvalsh(time=t)
        np.testing.assert_allclose(E, E_blocks)

    static = [["zz", J]]
    dynamic = [["x", h, f, []]]

    blocks = []
    for kblock in range(L):
        blocks.append({"kblock": kblock})

    H = hamiltonian(static, dynamic, N=L)

    [E0] = H.eigsh(time=0.3, k=1, which='SA', return_eigenvectors=False)

    block_op = block_ops(blocks,
                         static,
                         dynamic,
                         spin_basis_1d, (L, ),
                         np.complex128,
                         compute_all_blocks=True)

    # real time.
    expH = exp_op(H,
                  a=-1j,
                  start=start,
                  stop=stop,
                  iterate=True,
                  num=num,
                  endpoint=True)

    times = np.linspace(start, stop, num=num, endpoint=True)

    psi0 = np.random.ranf(H.Ns)
    psi0 /= np.linalg.norm(psi0)

    psi_exact_1 = H.evolve(psi0,
                           0,
                           times,
                           iterate=True,
                           atol=1e-15,
                           rtol=1e-15)
    psi_block_1 = block_op.evolve(psi0,
                                  0,
                                  times,
                                  iterate=True,
                                  atol=1e-15,
                                  rtol=1e-15,
                                  n_jobs=4)

    psi_exact_2 = expH.dot(psi0, time=0.3)
    psi_block_2 = block_op.expm(psi0,
                                H_time_eval=0.3,
                                start=start,
                                stop=stop,
                                iterate=True,
                                num=num,
                                endpoint=True,
                                n_jobs=2,
                                block_diag=True)

    for psi_e_1, psi_e_2, psi_b_1, psi_b_2 in izip(psi_exact_1, psi_exact_2,
                                                   psi_block_1, psi_block_2):
        np.testing.assert_allclose(psi_b_1, psi_e_1, atol=1e-7)
        np.testing.assert_allclose(psi_b_2, psi_e_2, atol=1e-7)

    expH.set_iterate(False)

    psi_exact_1 = H.evolve(psi0,
                           0,
                           times,
                           iterate=False,
                           atol=1e-15,
                           rtol=1e-15)
    psi_block_1 = block_op.evolve(psi0,
                                  0,
                                  times,
                                  iterate=False,
                                  atol=1e-15,
                                  rtol=1e-15,
                                  n_jobs=4)

    psi_exact_2 = expH.dot(psi0, time=0.3)
    psi_block_2 = block_op.expm(psi0,
                                H_time_eval=0.3,
                                start=start,
                                stop=stop,
                                iterate=False,
                                num=num,
                                endpoint=True,
                                block_diag=True)

    for psi_e_1, psi_b_1 in izip(psi_exact_1, psi_block_1):
        np.testing.assert_allclose(psi_b_1, psi_e_1, atol=1e-7)

    for psi_e_2, psi_b_2 in izip(psi_exact_2, psi_block_2):
        np.testing.assert_allclose(psi_b_2, psi_e_2, atol=1e-7)

    # imaginary time
    expH = exp_op(H,
                  a=-1,
                  start=start,
                  stop=stop,
                  iterate=True,
                  num=num,
                  endpoint=True)

    times = np.linspace(start, stop, num=num, endpoint=True)

    psi0 = np.random.ranf(H.Ns)
    psi0 /= np.linalg.norm(psi0)

    psi_exact_2 = expH.dot(psi0, time=0.3, shift=-E0)
    psi_block_2 = block_op.expm(psi0,
                                a=-1,
                                shift=-E0,
                                H_time_eval=0.3,
                                start=start,
                                stop=stop,
                                iterate=True,
                                num=num,
                                endpoint=True,
                                block_diag=True)

    for psi_e_2, psi_b_2 in izip(psi_exact_2, psi_block_2):
        np.testing.assert_allclose(psi_b_2, psi_e_2, atol=1e-7)

    # same for iterate=False
    expH.set_iterate(False)

    psi_exact_2 = expH.dot(psi0, time=0.3, shift=-E0)
    psi_block_2 = block_op.expm(psi0,
                                a=-1,
                                shift=-E0,
                                H_time_eval=0.3,
                                start=start,
                                stop=stop,
                                iterate=False,
                                num=num,
                                endpoint=True,
                                block_diag=True)

    for psi_e_2, psi_b_2 in izip(psi_exact_2, psi_block_2):
        np.testing.assert_allclose(psi_b_2, psi_e_2, atol=1e-7)