Ejemplo n.º 1
0
def test_trotter_hamiltonian_make_compatible_redundant():
    """Test ``make_compatible`` with redudant two-qubit terms."""
    h0 = X(2, trotter=True)
    target_matrix = h0.dense.matrix.numpy()
    target_matrix = np.kron(target_matrix, np.eye(2,
                                                  dtype=target_matrix.dtype))
    parts = [{(0, 1, 2): TFIM(3, numpy=True)}]
    h1 = TrotterHamiltonian(*parts)

    h0c = h1.make_compatible(h0)
    assert not h1.is_compatible(h0)
    assert h1.is_compatible(h0c)
    np.testing.assert_allclose(h0c.matrix, target_matrix)
Ejemplo n.º 2
0
def test_trotter_hamiltonian_make_compatible_repeating(nqubits):
    """Check ``make_compatible`` when first target is repeated in parts."""
    h0target = X(nqubits)
    h0 = X(nqubits, trotter=True)
    term = TFIM(2, numpy=True)
    parts = [{(0, i): term} for i in range(1, nqubits)]
    parts.extend(({(i, 0): term} for i in range(1, nqubits)))
    h1 = TrotterHamiltonian(*parts)

    h0c = h1.make_compatible(h0)
    assert not h1.is_compatible(h0)
    assert h1.is_compatible(h0c)
    np.testing.assert_allclose(h0c.matrix, h0target.matrix)
Ejemplo n.º 3
0
def test_trotter_hamiltonian_make_compatible_simple():
    """Test ``make_compatible`` on a simple 3-qubit example."""
    h0target = X(3)
    h0 = X(3, trotter=True)
    term1 = Y(1, numpy=True)
    term2 = TFIM(2, numpy=True)
    parts = [{(0, 1): term2, (1, 2): term2, (0, 2): term2, (2, ): term1}]
    h1 = TrotterHamiltonian(*parts)

    h0c = h1.make_compatible(h0)
    assert not h1.is_compatible(h0)
    assert h1.is_compatible(h0c)
    np.testing.assert_allclose(h0c.matrix, h0target.matrix)