Пример #1
0
def get(a):
    n = 10
    # create a random spin chain
    spins = ["S=1/2" for i in range(n)]  # spin 1/2 heisenberg chain

    # create first neighbor exchange
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    #sc.itensor_version = "julia"
    h = 0
    for i in range(n - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)

    sc.kpmmaxm = 20  # KPM maxm
    sc.maxm = 20  # KPM maxm
    A, B = sc.Sz[1], sc.Sz[1]
    es = np.linspace(-0.5, 6, 2000)
    delta = 1e-2
    #sc.kpm_extrapolate = False
    e = sc.gs_energy()
    sc.kpm_extrapolate = True
    sc.kpm_extrapolate_factor = 2.0
    t0 = time.time()
    (x, y) = sc.get_distribution(X=h - e,
                                 xs=es,
                                 delta=delta,
                                 A=A,
                                 B=B,
                                 a=a,
                                 b=0.9)
    t1 = time.time()
    print(a, t1 - t0)
    return (x, y)
Пример #2
0
def get():
  sc = spinchain.Spin_Chain(spins) # create the spin chain
  h = 0
  for i in range(n-1):
      h = h +sc.Sx[i]*sc.Sx[i+1]
      h = h +sc.Sy[i]*sc.Sy[i+1]
      h = h +sc.Sz[i]*sc.Sz[i+1]
  sc.set_hamiltonian(h)
  return sc
Пример #3
0
def get(n):
    spins = ["S=1/2" for i in range(n)]  # spin 1/2 heisenberg chain
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    h = 0
    for i in range(n - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)
    return sc
Пример #4
0
def getsc(iv):
  # create first neighbor exchange
  sc = spinchain.Spin_Chain(spins) # create the spin chain
  def fj(i,j):
    if abs(i-j)==1: return 1.0
    else: return 0.0
  sc.set_exchange(fj)
  sc.itensor_version = iv
  sc.get_gs()
  return sc
Пример #5
0
def get_original_Haldanechain(L=__L__):
    #original Heisenberg
    spins = ["S=1" for i in range(L)]  # S=1 chain
    sc = spinchain.Spin_Chain(spins)  # create spin chain object
    h = 0  # initialize Hamiltonian
    for i in range(len(spins) - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)
    return sc
Пример #6
0
def get(version, n=30):
    spins = ["S=1/2" for i in range(n)]  # spin 1/2 heisenberg chain
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    if version == "julia": sc.setup_julia()  # setup the Julia mode
    h = 0
    for i in range(n - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)
    return sc.gs_energy()
Пример #7
0
def get(version, n=30):
    spins = ["S=1/2" for i in range(n)]  # spin 1/2 heisenberg chain
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    sc.itensor_version = version
    h = 0
    for i in range(n - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)
    return sc.gs_energy()
Пример #8
0
def get_energy(ind):
  """Given a certain ordering of the indexes, return the energy"""
  n = len(ind)
  spins = [2 for i in range(n)] # list with the different spins of your system
  sc = spinchain.Spin_Chain(spins) # create the spin chain object
  sc.maxm = 10 # bond dimension, controls the accuracy
  sc.nsweeps = 3
  def fj(i,j):
      if abs(ind[i]-ind[j])==1: return 1.0
      return 0.0
  sc.set_exchange(fj) # add the exchange couplings
  return sc.gs_energy()
Пример #9
0
def get_transformed_Haldanechain(L=__L__):
    #transformed Heisenberg
    spins = ["S=1" for i in range(L)]  # S=1 chain
    sc2 = spinchain.Spin_Chain(spins)  # create spin chain object
    h = 0  # initialize Hamiltonian
    for i in range(len(spins) - 1):
        expSx = -2 * sc2.Sx[i + 1] * sc2.Sx[i + 1] + mo.obj2MO(1)
        expSz = -2 * sc2.Sz[i] * sc2.Sz[i] + mo.obj2MO(1)
        h = h + sc2.Sx[i] * sc2.Sx[i + 1]
        h = h + sc2.Sy[i] * expSz * expSx * sc2.Sy[i + 1]
        h = h + sc2.Sz[i] * sc2.Sz[i + 1]
    sc2.set_hamiltonian(h)
    return sc2
Пример #10
0
def gets(b):
    n = 30
    spins = ["S=1/2" for i in range(n)]  # spin 1/2 heisenberg chain
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    h = 0
    for i in range(n - 1):
        h = h - sc.Sz[i] * sc.Sz[i + 1]
    for i in range(n):
        h = h - b * sc.Sx[i]

    sc.set_hamiltonian(h)
    wf = sc.get_gs()  # compute ground state
    return wf.get_entropy(n // 2)
Пример #11
0
def get_gap(bx):
    """
    Compute the gap of the 1D Ising model with DMRG
    """
    print("Computing B_x = ", bx)
    sc = spinchain.Spin_Chain([2 for i in range(30)])  # create
    h = 0
    for i in range(sc.ns - 1):
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    for i in range(sc.ns):
        h = h + bx * sc.Sx[i]
    sc.set_hamiltonian(h)
    return abs(sc.vev(sc.Sz[0]))
    es = sc.get_excited(mode="DMRG", n=2)  # compute the first two energies
    return es[1] - es[0]  # return the gap
Пример #12
0
def getm(b):
  n = 100 # number of sites in your chain
  spins = ["S=1/2" for i in range(n)] # create the sites
  sc = spinchain.Spin_Chain(spins) # create the chain
  h = 0
  for i in range(n-1): 
      h = h + sc.Sx[i]*sc.Sx[i+1] # add exchange
      h = h + sc.Sy[i]*sc.Sy[i+1] # add exchange
      h = h + sc.Sz[i]*sc.Sz[i+1] # add exchange
  for i in range(n): h = h + b*sc.Sz[i] # add transverse field
  Mz = 0
  for i in range(n): Mz = Mz + sc.Sz[i]
  sc.set_hamiltonian(h) # and initialize the Hamiltonian
  mz = sc.vev(Mz,mode="DMRG").real
  return mz
Пример #13
0
def get(c01):
    """Compute mutual information"""
    # Heisenberg model
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    h = 0
    for i in range(n - 1):
        c = 1.0  # default coupling
        if i == 1: c = c01  # if it is the middle, change the coupling
        h = h + c * sc.Sx[i] * sc.Sx[i + 1]
        h = h + c * sc.Sy[i] * sc.Sy[i + 1]
        h = h + c * sc.Sz[i] * sc.Sz[i + 1]
    sc.set_hamiltonian(h)
    wf = sc.get_gs()  # compute ground state
    s = wf.get_mutual_information(1, 2)  # mutual information
    print(c01, s)
    return s
Пример #14
0
def get(n=2,bx=0.):
    g = geometry.single_square_lattice()
    m = g.get_supercell(n).get_hamiltonian(has_spin=False).get_hk_gen()([0.,0.,0.])
    
    n = m.shape[0] # number of sites in your chain
    spins = ["S=1/2" for i in range(n)] # create the sites
    sc = spinchain.Spin_Chain(spins) # create the chain
    
    h = 0
    # now define the Hamiltonian
    for i in range(n):
        for j in range(n):
            h = h + (-1)*m[i,j]*sc.Sz[i]*sc.Sz[j]
    
    h = 4*h + 2*bx*sum(sc.Sx)
    sc.set_hamiltonian(h)
    es = sc.get_excited(n=2,mode="ED")
    return es[1]-es[0]
Пример #15
0
def get(c01):
    """Compute entropy"""
    # Heisenberg model
    sc = spinchain.Spin_Chain(spins) # create the spin chain
    h = 0
    for i in range(n-1):
        c = 1.0 # default coupling
        if i==1: c = c01 # if it is the middle, change the coupling
        h = h +c*sc.Sx[i]*sc.Sx[i+1]
        h = h +c*sc.Sy[i]*sc.Sy[i+1]
        h = h +c*sc.Sz[i]*sc.Sz[i+1]
    sc.set_hamiltonian(h)
    wf = sc.get_gs() # compute ground state
    s = wf.get_pair_entropy(0,1) # entropy of the sites (0,1) with the rest
#   Alternative method
#    s1 = wf.get_bond_entropy(1,2) # compute entropy at this bond
#    print(s,s1,s1/s)
    return s
Пример #16
0
def run_classcal_precalculation(n_qubit, hamiltonian: QubitOperator, calc_2DM=False, get_amps=False):
    spins = ["S=1/2" for i in range(n_qubit)]
    sc = spinchain.Spin_Chain(spins)
    dmrgpy_hamiltonian = QubitOperator2DmrgpyOperator(n_qubit, hamiltonian)
    # print(dmrgpy_hamiltonian.op)
    sc.set_hamiltonian(dmrgpy_hamiltonian)
    gs_energy = sc.gs_energy(mode="ED")
    ed_obj = sc.get_ED_obj()

    res = {}
    res["energy"] = gs_energy
    if calc_2DM:
        one_DM, two_DM = get_one_two_density_matrix(n_qubit, ed_obj)
        res["2DM"] = two_DM
        res["1DM"] = one_DM
        entropy = [entropy_one_DM(one_DM[i]) for i in range(n_qubit)]
        res["entropy"] = entropy
    if get_amps:
        res["amplitudes"]=ed_obj.get_gs()
        
    return res
Пример #17
0
def get(D):
    sc = spinchain.Spin_Chain(spins)  # create the spin chain
    h = 0
    for i in range(len(spins) - 1):
        h = h + sc.Sx[i] * sc.Sx[i + 1]
        h = h + sc.Sy[i] * sc.Sy[i + 1]
        h = h + sc.Sz[i] * sc.Sz[i + 1]
    for i in range(len(spins)):
        h = h - D * sc.Sz[i] * sc.Sz[i]
    # define a Neel Hamiltonian
    h0 = 0
    for i in range(len(spins)):
        h0 = h0 + ((-1)**i) * sc.Sz[i]
    sc.nsweeps = 5
    sc.maxm = 20
    sc.set_hamiltonian(h0)
    wf = sc.get_gs()  # get the Neel wavefunction

    sc.set_hamiltonian(h)
    nc = len(spins) // 3
    wf = sc.get_gs(wf0=wf)
    print(D)
    return wf.get_entropy(len(spins) // 2)
Пример #18
0
# Add the root path of the dmrgpy library
import os
import sys
sys.path.append(os.getcwd() + '/../../src')

import numpy as np
from dmrgpy import spinchain
n = 6
spins = [2 for i in range(n)]  # spin 1/2 heisenberg chain
sc = spinchain.Spin_Chain(spins)  # create the spin chain
e = sc.gs_energy()  # compute the ground state energy
# now get the low energy Hamiltonian
h, b = sc.get_effective_hamiltonian()
print(sc.get_excited(n=4))
import scipy.linalg as lg
print(np.round(lg.eigvalsh(b), 3))
es, vs = lg.eigh(-b)
vs = vs.transpose()
print(vs[0].real)
print(np.round(lg.eigvalsh(h), 3))
Пример #19
0
    if i == j: return -2 * U  # set to half filling
    return 0.0


def fu(i, j):
    if i == j: return U
    return 0.0


fc.set_hoppings(ft)  # add the term to the Hamiltonian
fc.set_hubbard(fu)  # add the term to the Hamiltonian
pairs = [(0, i) for i in range(n)]
ch = fc.get_correlator(pairs=pairs, name="YY", mode="DMRG").real
print(fc.get_density_spinful())

# now create the Heisenberg chain
sc = spinchain.Spin_Chain([2 for i in range(n)])
sc.set_exchange(lambda i, j: 1.0 * (abs(i - j) == 1))
cs = sc.get_correlator(pairs=pairs, name="XX", mode="DMRG").real

import matplotlib.pyplot as plt

inds = range(len(ch))
plt.scatter(inds, ch, c="red", label="Hubbard")
plt.plot(inds, cs, c="blue", label="Heisenberg")
#plt.plot(inds,mz2,c="green",label="Exact")
plt.legend()
plt.xlabel("Site")
plt.ylabel("Correlator")
plt.show()
Пример #20
0
# Add the root path of the dmrgpy library
import os
import sys

sys.path.append(os.getcwd() + '/../../src')

import numpy as np  # conventional numpy library
import matplotlib.pyplot as plt  # library to plot the results

from dmrgpy import spinchain

ns = 6  # number of sites in the spin chain
spins = [3 for i in range(ns)]  # S=1 chain
sc = spinchain.Spin_Chain(spins)  # create spin chain object

# now define a custom Hamiltonian
h = 0.0  # initialize Hamiltonian
Si = [sc.Sx, sc.Sy, sc.Sz]  # store the three components
for i in range(ns - 1):  # loop
    for S in Si:
        h = h + S[i] * S[i + 1]  # bilinear
    for S in Si:
        h = h + 1. / 3. * S[i] * S[i + 1] * S[i] * S[i + 1]  # biquadratic
sc.set_hamiltonian(h)  # create the Hamiltonian
print("Energy with DMRG", sc.gs_energy(mode="DMRG"))
print("Energy with ED", sc.gs_energy(mode="ED"))