def test_amplify_init():
    """
    Test the usage of amplify without init
    """
    # Essentially Grover's to select 011 or 111
    desired = cz_gate + triple_hadamard.dagger() + diffusion_program(
        qubits) + triple_hadamard + cz_gate + triple_hadamard.dagger(
        ) + diffusion_program(qubits) + triple_hadamard
    created = amplification_circuit(triple_hadamard, cz_gate, qubits, iters)

    prog_equality(desired, created)
Exemple #2
0
def test_amplify():
    """
    Test the generic usage of amplify
    """
    # Essentially Grover's to select 011 or 111
    desired = (
        triple_hadamard.dagger() + cz_gate + triple_hadamard.dagger() +
        diffusion_program(qubits) + triple_hadamard + cz_gate +
        triple_hadamard.dagger()
        # We take care to only add the instructions, and not redefine the gate.
        + diffusion_program(qubits).instructions + triple_hadamard)
    created = amplification_circuit(triple_hadamard, cz_gate, qubits, iters)
    assert desired == created
def test_amplify():
    """
    Test the generic usage of amplify
    """

    # Essentially Grover's to select 011 or 111
    desired = (triple_hadamard.dagger() + cz_gate + triple_hadamard.dagger() +
               diffusion_program(qubits) + triple_hadamard + cz_gate +
               triple_hadamard.dagger() + diffusion_program(qubits) +
               triple_hadamard)
    created = amplification_circuit(triple_hadamard, cz_gate, qubits, iters)

    assert desired == created
def test_diffusion_operator():
    """
    Checks that the diffusion operator outputs the correct operation
    """
    created = diffusion_program([0, 1])
    desired = pq.Program()
    for def_gate in created.defined_gates:
        desired.defgate(def_gate.name, def_gate.matrix)
    desired.inst(X(0))
    desired.inst(X(1))
    desired.inst(H(1))
    desired.inst(RZ(-np.pi, 0))
    # There should be only one defined gate -- the CNOT.
    desired.inst((created.defined_gates[0].name, 0, 1))
    desired.inst(RZ(-np.pi, 0))
    desired.inst(H(1))
    desired.inst(X(0))
    desired.inst(X(1))
    assert prog_equality(created, desired)