0
$\begingroup$

I have the below Oracle function.

Oracle function

Below are the marked states for this Oracle function.

Oracle function marked solutions

I wanted to implement Grover's algorithm on 4 qubits. I've been following the below Qiskit notebook: https://qiskit.org/textbook/ch-algorithms/grover.html

The part that's troubling me is the controlled Z gate and its implementation. Any help would be appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

Some modification of the following handles most of my Grover needs.

def grover_circuit(oracle: QuantumCircuit, repeat=1):
    size = oracle.num_qubits
    circuit = QuantumCircuit(size, size)
    circuit.h(range(size))
    for _ in range(repeat):
        circuit.barrier()
        circuit &= oracle
        circuit.barrier()
        circuit.h(range(size))
        circuit.x(range(size))
        circuit.h(size - 1)
        circuit.mct(range(size - 1), size - 1)
        circuit.h(size - 1)
        circuit.x(range(size))
        circuit.h(range(size))
    circuit.measure(range(size), range(size))
    return circuit

You will have to figure out on your own how many times you'll need to repeat.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.