Exemplo n.º 1
0
 def test_realistic(self):
     seed_rand(42)
     ham = MPO_ham_heis(20)
     dmrg = DMRG2(ham, bond_dims=[2, 4])
     dmrg.solve()
     rho_ab = dmrg.state.ptr(range(6, 14))
     xf = approx_spectral_function(rho_ab, lambda x: x,
                                   tol=0.1, verbosity=2)
     assert_allclose(1.0, xf, rtol=0.6, atol=0.001)
Exemplo n.º 2
0
def construct_lanczos_tridiag_MPO(A,
                                  K,
                                  v0=None,
                                  initial_bond_dim=None,
                                  beta_tol=1e-6,
                                  max_bond=None,
                                  seed=False,
                                  v0_opts=None,
                                  k_min=10):
    """
    """
    if initial_bond_dim is None:
        initial_bond_dim = 8
    if max_bond is None:
        max_bond = 8

    if v0 is None:
        if seed:
            # needs to be truly random so MPI processes don't overlap
            qu.seed_rand(random.SystemRandom().randint(0, 2**32 - 1))

        V = MPO_rand(A.nsites,
                     initial_bond_dim,
                     phys_dim=A.phys_dim(),
                     dtype=A.dtype)
    else:  # normalize
        V = v0 / (v0.H @ v0)**0.5
    Vm1 = MPO_zeros_like(V)

    alpha = np.zeros(K + 1)
    beta = np.zeros(K + 2)

    bsz = A.phys_dim()**A.nsites
    beta[1] = bsz  # == sqrt(prod(A.shape))

    compress_kws = {'max_bond': max_bond, 'method': 'svd'}

    for j in range(1, K + 1):

        Vt = A.apply(V, compress=True, **compress_kws)
        Vt.add_MPO(-beta[j] * Vm1, inplace=True, compress=True, **compress_kws)
        alpha[j] = (V.H @ Vt).real
        Vt.add_MPO(-alpha[j] * V, inplace=True, compress=True, **compress_kws)
        beta[j + 1] = (Vt.H @ Vt)**0.5

        # check for convergence
        if abs(beta[j + 1]) < beta_tol:
            yield alpha[1:j + 1], beta[2:j + 2], beta[1]**2 / bsz
            break

        Vm1 = V.copy()
        V = Vt / beta[j + 1]

        if j >= k_min:
            yield (np.copy(alpha[1:j + 1]), np.copy(beta[2:j + 2]),
                   np.copy(beta[1])**2 / bsz)
Exemplo n.º 3
0
def construct_lanczos_tridiag_PTPTLazyMPS(A,
                                          K,
                                          v0=None,
                                          initial_bond_dim=None,
                                          beta_tol=1e-6,
                                          max_bond=None,
                                          v0_opts=None,
                                          k_min=10,
                                          seed=False):
    """
    """
    if initial_bond_dim is None:
        initial_bond_dim = 16
    if max_bond is None:
        max_bond = 16

    if v0 is None:
        if seed:
            # needs to be truly random so MPI processes don't overlap
            qu.seed_rand(random.SystemRandom().randint(0, 2**32 - 1))

        V = A.rand_state(bond_dim=initial_bond_dim)
    else:  # normalize
        V = v0 / (v0.H @ v0)**0.5
    Vm1 = EEMPS_zeros_like(V)

    alpha = np.zeros(K + 1)
    beta = np.zeros(K + 2)

    beta[1] = A.phys_dim()**((len(A.sysa) + len(A.sysb)) / 2)

    compress_kws = {'max_bond': max_bond, 'method': 'svd'}

    for j in range(1, K + 1):
        Vt = A.apply(V)
        Vt -= beta[j] * Vm1
        Vt.compress_all(**compress_kws)
        alpha[j] = (V.H @ Vt).real
        Vt -= alpha[j] * V
        beta[j + 1] = ((Vt.H @ Vt)**0.5).real
        Vt.compress_all(**compress_kws)

        # check for convergence
        if abs(beta[j + 1]) < beta_tol:
            yield alpha[1:j + 1], beta[2:j + 2], beta[1]**2
            break

        Vm1 = V.copy()
        V = Vt / beta[j + 1]

        if j >= k_min:
            yield (np.copy(alpha[1:j + 1]), np.copy(beta[2:j + 2]),
                   np.copy(beta[1])**2)
Exemplo n.º 4
0
 def test_multisubsystem(self):
     qu.seed_rand(42)
     dims = [2, 2, 2]
     IIX = qu.ikron(qu.rand_herm(2), dims, 2)
     dcmp = qu.pauli_decomp(IIX, mode='c')
     for p, x in dcmp.items():
         if x == 0j:
             assert (p[0] != 'I') or (p[1] != 'I')
         else:
             assert p[0] == p[1] == 'I'
     K = qu.rand_iso(3 * 4, 4).reshape(3, 4, 4)
     KIIXK = qu.kraus_op(IIX, K, dims=dims, where=[0, 2])
     dcmp = qu.pauli_decomp(KIIXK, mode='c')
     for p, x in dcmp.items():
         if x == 0j:
             assert p[1] != 'I'
         else:
             assert p[1] == 'I'