Combining with Oracles
Amplitude amplification is most powerful when you supply your own oracle — a quantum circuit that recognizes a "good" answer by flipping a phase — and then wrap it with the standard diffuser. This separation of concerns is what makes the framework reusable: you write the problem-specific oracle once, and the amplification machinery does the rest.
Anatomy of one amplification round
A single amplification iteration for an -qubit uniform superposition consists of two steps applied in sequence after the initial superposition is created:
-
Oracle : phase-flips every basis state that satisfies the target predicate , leaving all other states unchanged:
-
Diffuser : reflects amplitudes about their mean, which boosts the amplitude of the phase-flipped state and suppresses the rest:
The composition rotates the state toward the marked item by per iteration, where and is the number of marked states out of .
Designing a custom oracle
The oracle for a specific target must flip the phase of and leave everything else unchanged. Because the CZ gate phase-flips , any single-basis-state oracle can be built by conjugating CZ with gates that map to :
The gates on the qubits that are in flip those qubits to , making look like . The CZ then applies the phase. The final gates restore the labels.
Example: oracle for on two qubits
For the target (qubit 0 is , qubit 1 is ), only qubit 0 needs to be flipped before CZ can act:
Verification: , while any other basis state is unaffected (for example, ).
Putting it together: one Grover iteration on two qubits
For ( qubits) and a single marked state (), the success probability starts at and , so . After one iteration the state is rotated by from its starting angle of , placing it at — exactly on the marked state. The success probability becomes : the measurement finds with certainty.
The full two-qubit circuit is:
Try it
The starter code provides the uniform superposition and the standard two-qubit diffuser. Your task is to add the custom oracle that marks in the space provided. The grader checks the output distribution, which should put all probability on .
Sign in on the full site to ask questions and join the discussion.