Example #1
0
def test_diffusion_operator_empty():
    """
    Checks that the list of qubits to apply the grover
    diffusion operator to must be non-empty
    """
    with pytest.raises(AssertionError):
        diffusion_operator([])
Example #2
0
def test_amplify_init():
    """
    Test the usage of amplify without init
    """
    # Essentially Grover's to select 011 or 111
    desired = cz_gate + A_inv + diffusion_operator(
        qubits) + A + cz_gate + A_inv + diffusion_operator(qubits) + A
    created = amplify(A, A_inv, cz_gate, qubits, iters, init=False)

    compare_progs(desired, created)
Example #3
0
def test_amplify():
    """
    Test the generic usage of amplify
    """

    # Essentially Grover's to select 011 or 111
    desired = A + cz_gate + A_inv + diffusion_operator(
        qubits) + A + cz_gate + A_inv + diffusion_operator(qubits) + A
    created = amplify(A, A_inv, cz_gate, qubits, iters)

    compare_progs(desired, created)
Example #4
0
def test_diffusion_operator():
    """
    Checks that the diffusion operator outputs the correct operation
    """

    created = diffusion_operator([0, 1])
    desired = pq.Program()
    desired.inst(X(0))
    desired.inst(X(1))
    desired.inst(H(1))
    desired.inst(RZ(-3.141592653589793, 0))
    desired.inst(CNOT(0, 1))
    desired.inst(RZ(-3.141592653589793, 0))
    desired.inst(H(1))
    desired.inst(X(0))
    desired.inst(X(1))

    assert desired.out() == created.out()