Example #1
0
def test_dmrg_excited(eps=1.e-12):
    # checks ground state and 2 excited states (in same symmetry sector) for a small system
    # (without truncation)
    L, g = 8, 1.3
    bc = 'finite'
    model_params = dict(L=L, J=1., g=g, bc_MPS=bc, conserve='parity', verbose=0)
    M = TFIChain(model_params)
    # compare to exact solution
    ED = ExactDiag(M)
    ED.build_full_H_from_mpo()
    ED.full_diagonalization()
    # Note: energies sorted by chargesector (first 0), then ascending -> perfect for comparison
    print("Exact diag: E[:5] = ", ED.E[:5])
    print("Exact diag: (smalles E)[:10] = ", np.sort(ED.E)[:10])

    psi_ED = [ED.V.take_slice(i, 'ps*') for i in range(5)]
    print("charges : ", [psi.qtotal for psi in psi_ED])

    # first DMRG run
    psi0 = mps.MPS.from_product_state(M.lat.mps_sites(), [0] * L, bc=bc)
    dmrg_pars = {
        'verbose': 0,
        'N_sweeps_check': 1,
        'lanczos_params': {
            'reortho': False
        },
        'diag_method': 'lanczos',
        'combine': True
    }
    eng0 = dmrg.TwoSiteDMRGEngine(psi0, M, dmrg_pars)
    E0, psi0 = eng0.run()
    assert abs((E0 - ED.E[0]) / ED.E[0]) < eps
    ov = npc.inner(psi_ED[0], ED.mps_to_full(psi0), 'range', do_conj=True)
    assert abs(abs(ov) - 1.) < eps  # unique groundstate: finite size gap!
    # second DMRG run for first excited state
    dmrg_pars['verbose'] = 1.
    dmrg_pars['orthogonal_to'] = [psi0]
    psi1 = mps.MPS.from_product_state(M.lat.mps_sites(), [0] * L, bc=bc)
    eng1 = dmrg.TwoSiteDMRGEngine(psi1, M, dmrg_pars)
    E1, psi1 = eng1.run()
    assert abs((E1 - ED.E[1]) / ED.E[1]) < eps
    ov = npc.inner(psi_ED[1], ED.mps_to_full(psi1), 'range', do_conj=True)
    assert abs(abs(ov) - 1.) < eps  # unique groundstate: finite size gap!
    # and a third one to check with 2 eigenstates
    dmrg_pars['orthogonal_to'] = [psi0, psi1]
    # note: different intitial state necessary, otherwise H is 0
    psi2 = mps.MPS.from_singlets(psi0.sites[0], L, [(0, 1), (2, 3), (4, 5), (6, 7)], bc=bc)
    eng2 = dmrg.TwoSiteDMRGEngine(psi2, M, dmrg_pars)
    E2, psi2 = eng2.run()
    print(E2)
    assert abs((E2 - ED.E[2]) / ED.E[2]) < eps
    ov = npc.inner(psi_ED[2], ED.mps_to_full(psi2), 'range', do_conj=True)
    assert abs(abs(ov) - 1.) < eps  # unique groundstate: finite size gap!
Example #2
0
 def solve(self, model_params, psi):
     field_params1 = model_params.copy()
     field_params2 = model_params.copy()
     field_params1['h'] = 0.1
     field_params2['h'] = 0.01
     M = TFIChain(model_params)
     Mb1 = TFIChainField(field_params1)
     Mb2 = TFIChainField(field_params2)
     eng = dmrg.TwoSiteDMRGEngine(psi, Mb1, self.options)
     _, psi = eng.run()
     eng = dmrg.TwoSiteDMRGEngine(psi, Mb2, self.options)
     _, psi = eng.run()
     eng = dmrg.TwoSiteDMRGEngine(psi, M, self.options)
     return eng.run()
Example #3
0
def example_DMRG_tf_ising_infinite(g):
    print("infinite DMRG, transverse field Ising model")
    print("g={g:.2f}".format(g=g))
    model_params = dict(L=2, J=1., g=g, bc_MPS='infinite', conserve=None)
    M = TFIChain(model_params)
    product_state = ["up"] * M.lat.N_sites
    psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc=M.lat.bc_MPS)
    dmrg_params = {
        'mixer': True,  # setting this to True helps to escape local minima
        'trunc_params': {
            'chi_max': 30,
            'svd_min': 1.e-10
        },
        'max_E_err': 1.e-10,
    }
    # Sometimes, we want to call a 'DMRG engine' explicitly
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    E, psi = eng.run()  # equivalent to dmrg.run() up to the return parameters.
    print("E = {E:.13f}".format(E=E))
    print("final bond dimensions: ", psi.chi)
    mag_x = np.mean(psi.expectation_value("Sigmax"))
    mag_z = np.mean(psi.expectation_value("Sigmaz"))
    print("<sigma_x> = {mag_x:.5f}".format(mag_x=mag_x))
    print("<sigma_z> = {mag_z:.5f}".format(mag_z=mag_z))
    print("correlation length:", psi.correlation_length())
    # compare to exact result
    from tfi_exact import infinite_gs_energy
    E_exact = infinite_gs_energy(1., g)
    print("Analytic result: E (per site) = {E:.13f}".format(E=E_exact))
    print("relative error: ", abs((E - E_exact) / E_exact))
    return E, psi, M
Example #4
0
def test_dmrg_rerun(L=2):
    bc_MPS = 'infinite'
    model_params = dict(L=L,
                        J=1.,
                        g=1.5,
                        bc_MPS=bc_MPS,
                        conserve=None,
                        verbose=0)
    M = TFIChain(model_params)
    psi = mps.MPS.from_product_state(M.lat.mps_sites(), [0] * L, bc=bc_MPS)
    dmrg_pars = {
        'verbose': 5,
        'chi_list': {
            0: 5,
            5: 10
        },
        'N_sweeps_check': 4,
        'combine': True
    }
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_pars)
    E1, _ = eng.run()
    assert abs(E1 - -1.67192622) < 1.e-6
    model_params['g'] = 1.3
    M = TFIChain(model_params)
    del eng.options['chi_list']
    new_chi = 15
    eng.options['trunc_params']['chi_max'] = new_chi
    eng.init_env(M)
    E2, psi = eng.run()
    assert max(psi.chi) == new_chi
    assert abs(E2 - -1.50082324) < 1.e-6
Example #5
0
def test_dmrg_explicit_plus_hc(tol=1.e-13):
    model_params = dict(L=12, Jx=1., Jy=1., Jz=1.25, hz=5.125)
    dmrg_params = dict(N_sweeps_check=2, mixer=False)
    M1 = SpinChain(model_params)
    model_params['explicit_plus_hc'] = True
    M2 = SpinChain(model_params)
    assert M2.H_MPO.explicit_plus_hc
    psi1 = mps.MPS.from_product_state(M1.lat.mps_sites(), ['up', 'down'] * 6)
    E1, psi1 = dmrg.TwoSiteDMRGEngine(psi1, M1, dmrg_params).run()
    psi2 = mps.MPS.from_product_state(M2.lat.mps_sites(), ['up', 'down'] * 6)
    E2, psi2 = dmrg.TwoSiteDMRGEngine(psi2, M2, dmrg_params).run()
    print(E1, E2, abs(E1 - E2))
    assert abs(E1 - E2) < tol
    ov = abs(psi1.overlap(psi2))
    print("ov =", ov)
    assert abs(ov - 1) < tol
Example #6
0
def hubbard_dmrg(L,U,V,init="11",t=1.,mu=0,n_max=3,conserve="N",chi_max=100,bc="finite",extra_fill=0):
    """ Run DMRG for the Bose Hubbard model """
    # Setting the initial state
    where = int(L/3)
    if where % 2:
        where += 1
    if where > L:
        where = 1
    if init == "11":
        init_config = [1] * L
        init_config[where] += extra_fill
    if init == "20":
        init_config = [2,0] * int(L/2)
        init_config[where] += extra_fill
    if init == "02":
        init_config = [0,2] * int(L/2)
        init_config[where] += extra_fill
    filling = np.sum(init_config)/L
    t0 = datetime.datetime.now()
    model_params = dict(
        filling = filling,
        n_max = n_max,
        t = t,
        U = U,
        V = V,
        mu = mu,
        L=L,
        bc_MPS=bc,
        conserve = conserve,
        verbose=0)
    M = BoseHubbardChain(model_params)
    psi = MPS.from_product_state(M.lat.mps_sites(), init_config, bc=bc)
    dmrg_params = {
        'mixer': None,
        'trunc_params': {
            'chi_max': chi_max,
            'svd_min': 1.e-10
        },
        'max_E_err': 1.e-10,
        'verbose': 0,
        "norm_tol":1e-5
    }
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    eng.reset_stats()
    eng.trunc_params["chi_max"] = chi_max
    eng.run()
    E = np.sum(psi.expectation_value(M.H_bond[1:]))
    print("E = {E:.13f}".format(E=E))
    #print("final bond dimensions: ", psi.chi)
    time = datetime.datetime.now() - t0
    print(time)
    params = model_params
    params["chi_max"] = chi_max
    params["chis"] = psi.chi
    params["E"] = E
    params["time"] = time
    params["init_config"] = init_config
    params["init"] = init
    return psi, params
Example #7
0
def example_DMRG_tf_ising_infinite_S_xi_scaling(g):
    model_params = dict(L=2,
                        J=1.,
                        g=g,
                        bc_MPS='infinite',
                        conserve='best',
                        verbose=0)
    M = TFIChain(model_params)
    product_state = ["up"] * M.lat.N_sites
    psi = MPS.from_product_state(M.lat.mps_sites(),
                                 product_state,
                                 bc=M.lat.bc_MPS)
    dmrg_params = {
        'start_env': 10,
        'mixer': False,
        #  'mixer_params': {'amplitude': 1.e-3, 'decay': 5., 'disable_after': 50},
        'trunc_params': {
            'chi_max': 5,
            'svd_min': 1.e-10
        },
        'max_E_err': 1.e-9,
        'max_S_err': 1.e-6,
        'update_env': 0,
        'verbose': 0
    }

    chi_list = np.arange(7, 31, 2)
    s_list = []
    xi_list = []
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)

    for chi in chi_list:

        t0 = time.time()
        eng.reset_stats(
        )  # necessary if you for example have a fixed numer of sweeps, if you don't set this you option your simulation stops after initial number of sweeps!
        eng.trunc_params['chi_max'] = chi
        ##   DMRG Calculation    ##
        print("Start IDMRG CALCULATION")
        eng.run()
        eng.engine_params['mixer'] = None
        psi.canonical_form()

        ##   Calculating bond entropy and correlation length  ##
        s_list.append(np.mean(psi.entanglement_entropy()))
        xi_list.append(psi.correlation_length())

        print(chi,
              time.time() - t0,
              np.mean(psi.expectation_value(M.H_bond)),
              s_list[-1],
              xi_list[-1],
              flush=True)
        tenpy.tools.optimization.optimize(
            3)  # quite some speedup for small chi

        print("SETTING NEW BOND DIMENSION")

    return s_list, xi_list
Example #8
0
def test_dmrg_add_hc_to_MPO(tol=1.e-13):
    model_params = dict(L=6, Jx=1., Jy=1., Jz=1.25, hz=5.125)
    M1 = SpinChain(model_params)
    dmrg_params = dict(N_sweeps_check=2, mixer=False)
    psi = mps.MPS.from_product_state(M1.lat.mps_sites(), ['up', 'down'] * 3)

    model_params['add_hc_to_MPO'] = True
    M2 = SpinChain(model_params)
    psi = mps.MPS.from_product_state(M1.lat.mps_sites(), ['up', 'down'] * 3)
    E1, psi1 = dmrg.TwoSiteDMRGEngine(psi, M1, dmrg_params).run()
    psi2 = mps.MPS.from_product_state(M1.lat.mps_sites(), ['up', 'down'] * 3)
    E2, psi2 = dmrg.TwoSiteDMRGEngine(psi, M2, dmrg_params).run()
    print(E1, E2, abs(E1-E2))
    assert abs(E1 - E2) < tol
    ov = abs(psi1.overlap(psi2))
    print("ov =", ov)
    assert abs(ov - 1) < tol
Example #9
0
def run(model_params, phi_ext=np.linspace(0, 1.0, 7)):

    data = dict(phi_ext=phi_ext, QL=[], ent_spectrum=[])

    dmrg_params = {
        'mixer': True,  # setting this to True helps to escape local minima
        'mixer_params': {
            'amplitude': 1.e-5,
            'decay': 1.2,
            'disable_after': 30
        },
        'trunc_params': {
            'svd_min': 1.e-10,
        },
        'lanczos_params': {
            'N_min': 5,
            'N_max': 20
        },
        'chi_list': {
            0: 9,
            10: 49,
            20: 100
        },
        'max_E_err': 1.e-10,
        'max_S_err': 1.e-6,
        'max_sweeps': 150,
        'verbose': 1.,
    }

    prod_state = ['empty', 'full'] * (model_params['Lx'] * model_params['Ly'])

    eng = None

    for phi in phi_ext:

        print("=" * 100)
        print("phi_ext = ", phi)

        model_params['phi_ext'] = phi

        if eng is None:  # first time in the loop
            M = FermionicHaldaneModel(model_params)
            psi = MPS.from_product_state(M.lat.mps_sites(),
                                         prod_state,
                                         bc=M.lat.bc_MPS)
            eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
        else:
            del eng.engine_params['chi_list']
            M = FermionicHaldaneModel(model_params)
            eng.init_env(model=M)

        E, psi = eng.run()

        data['QL'].append(psi.average_charge(bond=0)[0])
        data['ent_spectrum'].append(
            psi.entanglement_spectrum(by_charge=True)[0])

    return data
Example #10
0
def setup_benchmark(mod_q=[1], legs=10, size=20, **kwargs):
    """Setup DMRG benchmark.

    Mapping of parameters:
        size -> chi
        legs -> L = number of sites
        mod_q -> conserve
    """
    L = legs  # number of sites: legs is abbreviated with `l`
    if len(mod_q) == 0:
        conserve = None
    elif mod_q == [2]:
        conserve = 'parity'
    elif mod_q == [1]:
        conserve = 'Sz'
    model_params = dict(L=L,
                        S=2.,
                        D=0.3,
                        bc_MPS='infinite',
                        conserve=conserve,
                        verbose=0)
    #  print("conserve =", repr(conserve))
    M = SpinChain(model_params)
    initial_state = (['up', 'down'] * L)[:L]
    psi = MPS.from_product_state(M.lat.mps_sites(),
                                 initial_state,
                                 bc='infinite')
    dmrg_params = {
        'trunc_params': {
            'chi_max': size,
            'svd_min': 1.e-45,
        },
        'lanczos_params': {
            'N_min': 10,
            'N_max': 10
        },
        #  'mixer': None,
        #  'N_sweeps_check': 1,
        #  'min_sweeps': 10,
        #  'max_sweeps': 100,
        #  'max_E_err': 1.e-13,
        'verbose': 0.,
    }
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    eng.verbose = 0.02
    for i in range(100):
        eng.sweep(meas_E_trunc=False)
        eng.sweep(optimize=False, meas_E_trunc=False)  # environment sweep
        if eng.verbose > 0.1:
            print(eng.psi.chi)
            print(eng.psi.entanglement_entropy())
    if eng.verbose > 0.1:
        print("set up dmrg for size", size)
    if eng.verbose > 0.01:
        print('initial chi', eng.psi.chi)
    eng.reset_stats()
    return eng
Example #11
0
def run(Jzs):
    L = 2
    model_params = dict(L=L,
                        Jx=1.,
                        Jy=1.,
                        Jz=Jzs[0],
                        bc_MPS='infinite',
                        conserve='Sz',
                        verbose=0)
    chi = 300
    dmrg_params = {
        'trunc_params': {
            'chi_max': chi,
            'svd_min': 1.e-10,
            'trunc_cut': None
        },
        'update_env': 20,
        'start_env': 20,
        'max_E_err': 0.0001,
        'max_S_err': 0.0001,
        'verbose': 1,
        'mixer': False
    }

    M = SpinChain(model_params)
    psi = MPS.from_product_state(M.lat.mps_sites(), (["up", "down"] * L)[:L],
                                 M.lat.bc_MPS)

    engine = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    np.set_printoptions(linewidth=120)
    corr_length = []
    for Jz in Jzs:
        print("-" * 80)
        print("Jz =", Jz)
        print("-" * 80)
        model_params['Jz'] = Jz
        M = SpinChain(model_params)
        engine.init_env(
            model=M)  # (re)initialize DMRG environment with new model
        # this uses the result from the previous DMRG as first initial guess
        engine.run()
        # psi is modified by engine.run() and now represents the ground state for the current `Jz`.
        corr_length.append(psi.correlation_length(tol_ev0=1.e-3))
        print("corr. length", corr_length[-1])
        print("<Sz>", psi.expectation_value('Sz'))
        dmrg_params[
            'start_env'] = 0  # (some of) the parameters are read out again
    corr_length = np.array(corr_length)
    results = {
        'model_params': model_params,
        'dmrg_params': dmrg_params,
        'Jzs': Jzs,
        'corr_length': corr_length,
        'eval_transfermatrix': np.exp(-1. / corr_length)
    }
    return results
Example #12
0
def benchmark_DMRG(max_chi=200, use_Sz=False):
    print("use_Sz = ", use_Sz)
    # S = 1 Heisenberg chain
    model_params = {
        # https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.spins.SpinModel.html#cfg-config-SpinModel
        'L': 100,
        'S': 1,
        'Jx': 1,
        'Jy': 1,
        'Jz': 1,
        'hz': 0.,
        'bc_MPS': 'finite',
        'conserve': 'Sz' if use_Sz else None,
    }
    M = SpinChain(model_params)
    psi = MPS.from_lat_product_state(
        M.lat, [['up'], ['down']])  # start from Neel state
    dmrg_params = {
        # https://tenpy.readthedocs.io/en/latest/reference/tenpy.algorithms.dmrg.TwoSiteDMRGEngine.html#cfg-config-TwoSiteDMRGEngine
        'trunc_params': {
            'chi_max': None,  # set by chi_list below
            'svd_min': 1.e-14,  # discard any singular values smaller than this
        },
        'chi_list': {
            # ramp-up the bond dimension with (sweep: max_chi) pairs
            0: 10,
            1: 20,
            2: 100,
            3: max_chi,  # after the 3rd sweep, use the full bond dimension
            # alternatively, directly set the `chi_max`.
        },
        'N_sweeps_check': 1,
        'min_sweeps': 5,
        'max_sweeps': 5,  # explicitly fix the number of sweeps
        'mixer': None,  # no subspace expansion
        'diag_method': 'lanczos',
        'lanczos_params': {
            # https://tenpy.readthedocs.io/en/latest/reference/tenpy.linalg.lanczos.LanczosGroundState.html#cfg-config-Lanczos
            'N_max':
            3,  # fix the number of Lanczos iterations: the number of `matvec` calls
            'N_min': 3,
            'N_cache': 20,  # keep the states during Lanczos in memory
            'reortho': False,
        },
    }
    optimization.set_level(3)  # disables a few consistency checks
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    t0_proc = time.process_time()
    t0_wall = time.time()
    eng.run()
    proc_time = time.process_time() - t0_proc
    wall_time = time.time() - t0_wall
    print("process time: {0:.1f}s, wallclock time: {1:.1f}s".format(
        proc_time, wall_time))
    return proc_time, wall_time
Example #13
0
def run_atomic(
    # model parameters
    chi=30,
    Jx=1.,
    Jy=1.,
    Jz=0.,
    L=3,
    S=.5,
    bc='periodic',
    bc_MPS='infinite',
    # dmrg parameters
    initial_psi=None,  # input psi
    initial='random',
    max_E_err=1.e-6,
    max_S_err=1.e-4,
    max_sweeps=200,
    N_sweeps_check=10,
    canonicalized=True,
    # control for the verbose output
    verbose=1,
):
    """ 
        The fundamental function for running DMRG
    """

    #######################
    # set the paramters for model initialization
    model_params = dict(
        conserve=None,
        Jx=Jx,
        Jy=Jy,
        Jz=Jz,
        L=L,
        S=S,
        verbose=verbose,
        bc=bc,
        bc_MPS=bc_MPS,
    )
    # initialize the model
    M = KitaevLadderModel(model_params)
    # providing a product state as the initial state
    # prod_state = ["up", "up"] * (2 * model_params['L'])
    # random generated initial state
    if initial_psi == None:
        prod_state = [choice(["up", "down"]) for i in range(4 * L)]
        if initial == 'up':
            prod_state = ["up" for i in range(4 * L)]
        if initial == 'down':
            prod_state = ["down" for i in range(4 * L)]
        psi = MPS.from_product_state(
            M.lat.mps_sites(),
            prod_state,
            bc=M.lat.bc_MPS,
        )
    else:
        psi = initial_psi.copy()
    #######################

    #######################
    # set the parameters for the dmrg routine
    dmrg_params = {
        'start_env': 10,
        #         'mixer': False,  # setting this to True helps to escape local minima
        'mixer': True,
        'mixer_params': {
            'amplitude': 1.e-4,
            'decay': 1.2,
            'disable_after': 50
        },
        'trunc_params': {
            'chi_max': 4,
            'svd_min': 1.e-10,
        },
        'max_E_err': max_E_err,
        'max_S_err': max_S_err,
        'max_sweeps': max_sweeps,
        'N_sweeps_check': N_sweeps_check,
        'verbose': verbose,
    }
    #######################

    if verbose:
        print("\n")
        print("=" * 80)
        print("=" * 30 + "START" + "=" * 30)
        print("=" * 80)
        print("Chi = ", chi, '\n')

    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    eng.reset_stats()
    eng.trunc_params['chi_max'] = chi
    info = eng.run()

    if canonicalized:
        psi.canonical_form()
        if verbose:
            print("Before the canonicalization:")
            print("Bond dim = ", psi.chi)

            print("Canonicalizing...")
            psi_before = psi.copy()

        if verbose:
            ov = psi.overlap(psi_before, charge_sector=0)
            print("The norm is: ", psi.norm)
            print("The overlap is: ", ov)
            print("After the canonicalization:")
            print("Bond dim = ", psi.chi)

        print("Computing properties")

    energy = info[0]

    if verbose:
        print("Optimizing")

    tenpy.tools.optimization.optimize(3)

    if verbose:
        print("Loop for chi=%d done." % chi)
        print("=" * 80)
        print("=" * 30 + " END " + "=" * 30)
        print("=" * 80)

    # the wave function, the ground-state energy, and the DMRG engine are all that we need
    result = dict(
        psi=psi.copy(),
        energy=energy,
        sweeps_stat=eng.sweep_stats.copy(),
        parameters=dict(
            # model parameters
            chi=chi,
            Jx=Jx,
            Jy=Jy,
            Jz=Jz,
            L=L,
            # dmrg parameters
            initial_psi=initial_psi,
            initial=initial,
            max_E_err=max_E_err,
            max_S_err=max_S_err,
            max_sweeps=max_sweeps,
        ))
    return result
Example #14
0
 def solve(self, model_params, psi):
     M = TFIChain(model_params)
     eng = dmrg.TwoSiteDMRGEngine(psi, M, self.options)
     return eng.run()
Example #15
0
def run(model_params, phi_ext=np.linspace(0, 2.0, 7)):

    data = dict(phi_ext=phi_ext, QL=[], ent_spectrum=[])

    dmrg_params = {
        'mixer': True,  # setting this to True helps to escape local minima
        'mixer_params': {
            'amplitude': 1.e-5,
            'decay': 1.2,
            'disable_after': 30
        },
        'trunc_params': {
            'svd_min': 1.e-10,
        },
        'lanczos_params': {
            'N_min': 5,
            'N_max': 20
        },
        'chi_list': {
            0: 9,
            10: 49,
            20: 100
        },
        'max_E_err': 1.e-10,
        'max_S_err': 1.e-6,
        'max_sweeps': 150,
        'verbose': 1.,
    }

    prod_state = [1]
    if 2 * model_params['Lx'] * model_params['Ly'] % 4 != 0:
        warnings.warn(
            "Total filling factor = 1/4 cannot be achieved with this unit cell geometry."
        )
    for i in range(1, 2 * model_params['Lx'] * model_params['Ly']):
        if i % 4 == 0:
            prod_state.append(1)
        else:
            prod_state.append(0)

    print(prod_state)

    eng = None

    for phi in phi_ext:

        print("=" * 100)
        print("phi_ext = ", phi)

        model_params['phi_ext'] = phi

        if eng is None:  # first time in the loop
            M = BosonicHaldaneModel(model_params)
            psi = MPS.from_product_state(M.lat.mps_sites(),
                                         prod_state,
                                         bc=M.lat.bc_MPS)
            eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
        else:
            del eng.engine_params['chi_list']
            M = BosonicHaldaneModel(model_params)
            eng.init_env(model=M)

        E, psi = eng.run()

        data['QL'].append(psi.average_charge(bond=0)[0])
        data['ent_spectrum'].append(
            psi.entanglement_spectrum(by_charge=True)[0])

    return data
Example #16
0
def run(gs):
    print("running for gs = ", gs)
    L = 2
    model_params = dict(L=L, J=1., g=gs[0], bc_MPS='infinite', conserve=None)
    chi = 100
    dmrg_params = {
        'trunc_params': {
            'chi_max': chi,
            'svd_min': 1.e-10,
            'trunc_cut': None
        },
        'update_env': 5,
        'start_env': 5,
        'max_E_err': 0.0001,
        'max_S_err': 0.0001,
        'max_sweeps':
        100,  # NOTE: this is not enough to fully converge at the critical point!
        'mixer': False
    }

    M = TFIChain(model_params)
    psi = MPS.from_product_state(M.lat.mps_sites(), (["up", "down"] * L)[:L],
                                 M.lat.bc_MPS)

    engine = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    np.set_printoptions(linewidth=120)

    corr_length = []
    fidelity = []
    Sz = []
    E = []
    S = []
    SxSx = []
    old_psi = None
    for g in gs:
        print("-" * 80)
        print("g =", g)
        print("-" * 80)
        model_params['g'] = g
        M = TFIChain(model_params)
        engine.init_env(
            model=M)  # (re)initialize DMRG environment with new model
        # this uses the result from the previous DMRG as first initial guess
        E0, psi = engine.run()
        E.append(E0)
        # psi is modified by engine.run() and now represents the ground state for the current `g`.
        S.append(psi.entanglement_entropy()[0])
        corr_length.append(psi.correlation_length(tol_ev0=1.e-3))
        print("corr. length", corr_length[-1])
        Sz.append(psi.expectation_value('Sigmaz'))
        print("<Sigmaz>", Sz[-1])
        SxSx.append(
            psi.correlation_function("Sigmax", "Sigmax", [0], 20)[0, :])
        print("<Sigmax_0 Sigmax_i>", SxSx[-1])
        if old_psi is not None:
            fidelity.append(np.abs(old_psi.overlap(psi)))
            print("fidelity", fidelity[-1])
        old_psi = psi.copy()
        dmrg_params[
            'start_env'] = 0  # (some of) the parameters are read out again
    results = {
        'model_params': model_params,
        'dmrg_params': dmrg_params,
        'gs': gs,
        'corr_length': np.array(corr_length),
        'fidelity': np.array(fidelity),
        'Sz': np.array(Sz),
        'E': np.array(E),
        'S': np.array(S),
        'SxSx': np.array(SxSx),
        'eval_transfermatrix': np.exp(-1. / np.array(corr_length)),
    }
    return results
Example #17
0
def calc_segment_groundstate(psi, model, dmrg_params):
    engine = dmrg.TwoSiteDMRGEngine(psi, model, dmrg_params)
    E, psi = engine.run()
    return psi