예제 #1
0
def generate_regular_mps_test(L,
                              system_index,
                              sys_site_op,
                              bath_site_op,
                              sys_couple_op,
                              bath_couple_op,
                              single_state=None,
                              seed=42,
                              rank=2):
    """
            See get_operators for an explanation for most of the parameters. Additionally generates a random MPS.
            Operators must be 2x2 Matrices
        :returns: Initial state for exact diagonalization, dimensions of the chain, exact diagonalization site operators,
                  exact diagonalization bond operators, TMP initial state, TMP site operators, TMP bond operators
    """
    assert L > 2
    assert sys_site_op.shape == bath_site_op.shape == sys_couple_op.shape == bath_couple_op.shape == (
        2, 2)
    dims = [2] * L
    if single_state is not None:
        exdiag_state = kron.generate_product_state(single_state, L)
        tm_state = mp.MPArray.from_array(exdiag_state.reshape(tuple([2] * L)),
                                         ndims=1)
    else:
        rng = np.random.RandomState(seed=seed)
        tm_state = mp.random_mpa(sites=L,
                                 ldim=2,
                                 rank=rank,
                                 randstate=rng,
                                 normalized=True)
        exdiag_state = tm_state.to_array().reshape(2**L)
    ed_site_ops, ed_bond_ops, tm_site_ops, tm_bond_ops = \
        get_operators(L, system_index, sys_site_op, bath_site_op, sys_couple_op, bath_couple_op)
    return exdiag_state, dims, ed_site_ops, ed_bond_ops, tm_state, tm_site_ops, tm_bond_ops
예제 #2
0
def test_regular_chain(L, sot, nof_steps, tau):
    """
        Pytest test for time evolution of a pure quantum state under a Hamiltonian of the form:
        sum_i^L H_{i} + sum_i^(L-1) H_{i, i+1}
        where the H_(i) are called site ops and the H_{i, i+1} are called bond ops. Those are constructed from
        pauli spin operators.
        The physical dimension of each site (site_dim) is constant d!
        Tests are performed for different chain lengths and different time discretizations
        The initial state is a superposition product state
    :param L: Chain L
    :param nof_steps: Number of time evolution steps
    :param tau: Timestep in each step of the time evolution
    :return:
    """
    # Test parameters
    psi_i = np.array([1.0, 1.0])
    psi_i /= np.linalg.norm(psi_i)
    site_dim = 2
    site_dims = [site_dim] * L
    site_op = pauli.Z
    bond_op = np.kron(pauli.Z, pauli.X)

    # Setup for exact diagonalization
    psi_0 = kron.generate_product_state(psi_i, L)
    exdiag_propagator = exdiag.ExDiagPropagator(psi_0, site_dims,
                                                repeat(site_op, L),
                                                repeat(bond_op, L - 1), tau)

    # Setup for tMPS evolution
    state_compress_kwargs = {'method': 'svd', 'relerr': 1e-10}
    op_compression_kwargs = {'method': 'svd', 'relerr': 1e-13}
    mps_psi_0 = np.copy(psi_0).reshape(*site_dims)
    mps = mp.MPArray.from_array(mps_psi_0, ndims=1)
    tmps_propagator = from_hamiltonian(
        mps,
        'mps',
        site_op,
        bond_op,
        tau=tau,
        state_compression_kwargs=state_compress_kwargs,
        op_compression_kwargs=op_compression_kwargs,
        second_order_trotter=sot)

    # Propagation loop
    normdist = []
    for step in range(nof_steps):
        exdiag_propagator.evolve()
        tmps_propagator.evolve()
        tmps_psi_t_array = mp.MPArray.to_array(tmps_propagator.psi_t).reshape(
            site_dim**L)
        normdist.append(
            np.linalg.norm(tmps_psi_t_array - exdiag_propagator.psi_t))
    max_normdist = np.max(np.array(normdist))
    if sot:
        assert np.max(max_normdist) < 1e-6
    else:
        assert np.max(max_normdist) < 1e-8