예제 #1
0
def test_evolve_trotter_euclidean(num_sites, phys_dim, graph):
    psi = tf.complex(
        tf.random_normal([phys_dim] * num_sites, dtype=tf.float64),
        tf.random_normal([phys_dim] * num_sites, dtype=tf.float64))
    h = tf.complex(
        tf.random_normal((phys_dim**2, phys_dim**2), dtype=tf.float64),
        tf.random_normal((phys_dim**2, phys_dim**2), dtype=tf.float64))
    h = 0.5 * (h + tf.linalg.adjoint(h))
    h = tf.reshape(h, (phys_dim, phys_dim, phys_dim, phys_dim))
    H = [h] * (num_sites - 1)

    norm1 = wavefunctions.inner(psi, psi)
    en1 = sum(wavefunctions.expval(psi, H[i], i) for i in range(num_sites - 1))

    if graph:
        psi, t = wavefunctions.evolve_trotter_defun(psi,
                                                    H,
                                                    0.1,
                                                    10,
                                                    euclidean=True)
    else:
        psi, t = wavefunctions.evolve_trotter(psi, H, 0.1, 10, euclidean=True)

    norm2 = wavefunctions.inner(psi, psi)
    en2 = sum(wavefunctions.expval(psi, H[i], i) for i in range(num_sites - 1))

    np.testing.assert_allclose(t, 1.0)
    np.testing.assert_almost_equal(norm2, 1.0)
    assert en2.numpy() / norm2.numpy() < en1.numpy() / norm1.numpy()
def test_evolve_trotter(num_sites, phys_dim, graph):
    psi = tf.complex(
        tf.random.normal([phys_dim] * num_sites, dtype=tf.float64),
        tf.random.normal([phys_dim] * num_sites, dtype=tf.float64))
    h = tf.complex(
        tf.random.normal((phys_dim**2, phys_dim**2), dtype=tf.float64),
        tf.random.normal((phys_dim**2, phys_dim**2), dtype=tf.float64))
    h = 0.5 * (h + tf.linalg.adjoint(h))
    h = tf.reshape(h, (phys_dim, phys_dim, phys_dim, phys_dim))
    H = [h] * (num_sites - 1)

    norm1 = wavefunctions.inner(psi, psi)
    en1 = sum(wavefunctions.expval(psi, H[i], i) for i in range(num_sites - 1))

    if graph:
        psi, t = wavefunctions.evolve_trotter_defun(psi, H, 0.001, 10)
    else:
        psi, t = wavefunctions.evolve_trotter(psi, H, 0.001, 10)

    norm2 = wavefunctions.inner(psi, psi)
    en2 = sum(wavefunctions.expval(psi, H[i], i) for i in range(num_sites - 1))

    np.testing.assert_allclose(t, 0.01)
    np.testing.assert_almost_equal(norm1 / norm2, 1.0)
    np.testing.assert_almost_equal(en1 / en2, 1.0, decimal=2)