Exemple #1
0
def calc_phase_diagram():
    """
    Calculating the phase diagram of transverse field Ising model in $h$ and $J$ grid.
    $h$ and $J$ both range from -100 to 100. The result is saved in an npz file.
    :return: None.
    """
    logspace = list(np.logspace(-2, 2, 20))
    minus_logspace = list(-np.logspace(-2, 2, 20)[::-1])
    j_grid = minus_logspace + [0] + logspace
    h_grid = minus_logspace + [0] + logspace
    mz_result = np.zeros((len(j_grid), len(h_grid)))
    mx_result = np.zeros((len(j_grid), len(h_grid)))
    for j_idx, j in enumerate(j_grid):
        for h_idx, h in enumerate(h_grid):
            param_str = "j = %g, h = %g" % (j, h)
            logging.info("Start: " + param_str)
            mpo_list = build_mpo_list(construct_single_mpo(j, h), SITE_NUM)
            mps = MatrixProductState(mpo_list, error_threshold=ERROR_THRESHOLD)
            energies = mps.search_ground_state()
            mz = mps.expectation(construct_mz_mpo_list(SITE_NUM))
            mx = mps.expectation(construct_mx_mpo_list(SITE_NUM))
            mz_result[j_idx][h_idx] = mz
            mx_result[j_idx][h_idx] = mx
            logging.info("End %s. Energy: %g, M_z: %g, M_x: %g" %
                         (param_str, energies[-1], mz, mx))
    np.savez(
        "ising_phase_diagram",
        mz_result=mz_result,
        mx_result=mx_result,
        j_grid=j_grid,
        h_grid=h_grid,
    )
Exemple #2
0
def calc_mx_vs_h():
    """
    Calculate the relation between $M_x$ and $h$ when $J$ is fixed to 1 and $h$ varies from 0 to 2
    to study the phase transition. Energies are also calculated as a reference.
    The result is saved in an npz file.
    :return: None
    """
    h_list = np.linspace(0, 2, 20)
    energy_list = []
    mx_list = []
    for h in h_list:
        logging.info("Start: h = %g" % h)
        mpo_list = build_mpo_list(construct_single_mpo(j=1, h=h), SITE_NUM)
        mps = MatrixProductState(mpo_list, error_threshold=ERROR_THRESHOLD)
        energies = mps.search_ground_state()
        mx = mps.expectation(construct_mx_mpo_list(SITE_NUM))
        average_energy = energies[-1] / SITE_NUM
        energy_list.append(average_energy)
        mx_list.append(mx)
        logging.info("End h = %g. Energy: %g, M_x: %g" %
                     (h, average_energy, mx))
    np.savez("ising_mx_vs_h",
             h_list=h_list,
             energy_list=energy_list,
             mx_list=mx_list)
def test_search():
    mpo_list = build_mpo_list(construct_single_mpo(), SITE_NUM)
    mps = MatrixProductState(mpo_list, max_bond_dimension=MAX_BOND_DIMENSION)
    # use threshold as criterion for compression
    # mps = MatrixProductState(mpo_list, error_threshold=ERROR_THRESHOLD)
    energies = mps.search_ground_state()

    assert pytest.approx(energies[-1], -10, abs=0.1)
Exemple #4
0
def construct_mx_mpo_list(site_num):
    """
    Construct the $M_x$ MPO list needed for calculating the expectation value of $M_x$ for a MPS
    :param site_num: number of sites
    :return: $M_x$ mpo list
    """
    mpo_list = build_mpo_list(np.float64([[S1, S0], [Sx, S1]]),
                              site_num,
                              regularize=True)
    return mpo_list
Exemple #5
0
    mpo_block3 = [Sm, S0, S0, S0, S0]
    mpo_block4 = [Sz, S0, S0, S0, S0]
    mpo_block5 = [-h * Sz, J / 2 * Sm, J / 2 * Sp, Jz * Sz, S1]

    # MPO shape: 5, 5, 2, 2
    mpo = np.float64(
        [mpo_block1, mpo_block2, mpo_block3, mpo_block4, mpo_block5])
    # prohibit writing just in case
    mpo.flags.writeable = False

    return mpo


# number of sites
SITE_NUM = 20

# only one of the following 2 parameters are needed

# maximum bond order in MPS
MAX_BOND_ORDER = 16

# the threshold for error when compressing MPS
ERROR_THRESHOLD = 1e-7

if __name__ == "__main__":
    mpo_list = build_mpo_list(construct_single_mpo(), SITE_NUM)
    mps = MatrixProductState(mpo_list, max_bond_order=MAX_BOND_ORDER)
    # use threshold as criterion for compression
    # mps = MatrixProductState(mpo_list, error_threshold=ERROR_THRESHOLD)
    print(mps.search_ground_state())