ProductBlogAlgorithmsAboutSign inSign up

Quick Example

Grover's Search: Quantum Circuit Example

Understand amplitude amplification with a two-qubit Grover learning example, inspect five framework variants, and compare its result with the ideal answer.

Grover's algorithm uses an oracle to mark solutions and an amplification step to make them more likely to be measured. This page explains the small teaching circuit available in the Run editor.

Quick Example: one marked item among four

Two qubits represent 00, 01, 10, and 11. This example deliberately marks 11 and applies one Grover iteration. The ideal result is both qubits equal to 1 with probability 100%.

  1. Prepare: apply a Hadamard to each qubit, assigning equal amplitude to all four candidates.
  2. Mark: a controlled-Z changes the sign of the 11 amplitude. This phase change alone does not change measurement probabilities.
  3. Amplify: the diffusion circuit converts that phase information into a larger marked-state amplitude.
  4. Measure: the implemented circuit prepares −|11⟩. The minus sign is a global phase, so measurement returns 11.
Two-qubit Grover circuitEach qubit starts at zero. Hadamard gates prepare a uniform state, a controlled Z marks eleven, and Hadamard, X, controlled Z, X, Hadamard implement diffusion. Both qubits are measured.q₀q₁HHHHXXXXHHMMPrepareOracle CZDiffusionMeasure
One oracle and one diffusion step. CZ connects the two filled dots; M measures each qubit. Scroll the circuit on a small screen.

Try the quick example

Open Run in Marqov →

Choose Examples → Grover's Search → framework. Click Run, select a browser destination, then click Run in browser. Selecting the framework in the example submenu loads its snippet; changing the editor's framework selector alone does not load a new example. The link opens the editor; it does not preselect or execute the example. Save existing editor work before replacing it.

What result should you expect?

In an ideal simulation, every shot should return 11. Finite-shot sampling alone does not cause variation when the ideal distribution has only one possible outcome. Noise or an implementation problem can introduce other outcomes; hardware results need their own noise assumptions and scientific checks.

One iteration is the right choice for this four-candidate, one-solution instance. A second iteration reduces ideal success to 25%. More iterations do not always improve the result.

Inspect and download the circuit

Inspect the same fixed circuit in five frameworks. Browser execution translates supported circuit definitions into OpenQASM; it does not run general Python. Outside Marqov, Qiskit, Cirq, and Marqov snippets need a separate simulator invocation. PennyLane invokes its QNode and stores sampled counts in result.

OpenQASM
// Grover's Search — find |11> among 4 items (2 qubits)
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];

// Initialize superposition
h q[0];
h q[1];

// Oracle: mark |11>
cz q[0],q[1];

// Diffusion operator
h q[0];
h q[1];
x q[0];
x q[1];
cz q[0],q[1];
x q[0];
x q[1];
h q[0];
h q[1];

measure q -> c;
Download OpenQASM circuit
Qiskit
# Grover's Search — find |11> among 4 items (2 qubits)
from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2)

# Initialize superposition
qc.h([0, 1])

# Oracle: mark |11>
qc.cz(0, 1)

# Diffusion operator
qc.h([0, 1])
qc.x([0, 1])
qc.cz(0, 1)
qc.x([0, 1])
qc.h([0, 1])

qc.measure([0, 1], [0, 1])
Download Qiskit circuit
Cirq
# Grover's Search — find |11> among 4 items (2 qubits)
import cirq

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([
    # Initialize superposition
    cirq.H(q0), cirq.H(q1),
    # Oracle: mark |11>
    cirq.CZ(q0, q1),
    # Diffusion operator
    cirq.H(q0), cirq.H(q1),
    cirq.X(q0), cirq.X(q1),
    cirq.CZ(q0, q1),
    cirq.X(q0), cirq.X(q1),
    cirq.H(q0), cirq.H(q1),
    # Measure
    cirq.measure(q0, q1, key="result"),
])
Download Cirq circuit
PennyLane
# Grover's Search — find |11> among 4 items (2 qubits)
import pennylane as qml

dev = qml.device("default.qubit", wires=2, shots=1000)

@qml.qnode(dev)
def grover():
    # Initialize superposition
    qml.Hadamard(wires=0)
    qml.Hadamard(wires=1)
    # Oracle: mark |11>
    qml.CZ(wires=[0, 1])
    # Diffusion operator
    qml.Hadamard(wires=0)
    qml.Hadamard(wires=1)
    qml.PauliX(wires=0)
    qml.PauliX(wires=1)
    qml.CZ(wires=[0, 1])
    qml.PauliX(wires=0)
    qml.PauliX(wires=1)
    qml.Hadamard(wires=0)
    qml.Hadamard(wires=1)
    return qml.counts()

result = grover()
Download PennyLane circuit
Marqov
# Grover's Search — find |11> among 4 items (2 qubits)
from marqov import Circuit

circuit = (
    Circuit()
    .h(0).h(1)             # Superposition
    .cz(0, 1)              # Oracle: mark |11>
    .h(0).h(1)             # Diffusion
    .x(0).x(1)
    .cz(0, 1)
    .x(0).x(1)
    .h(0).h(1)
)
Download Marqov circuit

Explore the research replication

The separate three-qubit research reference investigates eight phase oracles and compares saved measurement distributions with the paper's prediction. It has different circuits, expected results and evidence from this two-qubit learning example.

Read the three-qubit Grover research overview →

Scope and verification

This fixed oracle teaches amplitude amplification; it does not search an arbitrary uploaded list. The general algorithm's advantage concerns oracle-query complexity, while the cost of implementing that oracle still matters. This four-item circuit is not evidence of a practical speedup.

The five variants have independent ideal-answer checks and missing-oracle regression checks, and have been sampled in both browser simulator engines. Local native checks also passed for OpenQASM/Qiskit, Cirq, and PennyLane. Marqov native simulation and Qiskit conversion produced the correct state, but native sampling failed in versions 0.5.0 and 0.5.1 when floating-point rounding put a probability slightly above one. Independent checks now pass after a fresh PyPI installation of Marqov SDK 0.9.0 and its required QuantumFlow 1.0.2 dependency, with no dependency or source overrides. All five native samplers return 11: 1000. The defect does not occur in the two tested browser engines.

On October 15, 2026, the public website → editor → manual Grover selection → Browser (WASM) journey was verified with 1,000 shots: every result was 11, at $0.00. This check covers that browser path. Qualification of the managed runtime and hardware execution remains separate and is not established by these results.

Quick-example source: df5a80cd474144684bf69dbda237b28ce40cc48c. Example version: 3100235712b584bf1a8db9c86695d0f31745c82063297b7ce93f3219d731b4a1. This snapshot is source provenance, not an application-resolver version or a hosted execution certificate.

References

The references explain the algorithm and research context. The quick snippet originated in Marqov's internal example collection; no upstream code attribution was established.