Simon's algorithm is a quantum query algorithm that solves Simon's problem with exponential speedup over classical probabilistic algorithms. It finds a hidden bitstring
-
Classical Complexity:
$O(2^{n/2})$ queries (Birthday Paradox bound). -
Quantum Complexity:
$O(n)$ queries + classical linear algebra.
This algorithm is historically significant as it inspired Peter Shor to develop his factoring algorithm.
The algorithm consists of a quantum part to gather linear equations and a classical part to solve them.
-
Initialize:
$n$ qubits in$|0\rangle$ (input) and$n$ qubits in$|0\rangle$ (output). -
Superposition: Apply Hadamard gates (
$H$ ) to the first$n$ qubits. -
Oracle: Apply
$U_f$ which maps$|x\rangle |0\rangle \to |x\rangle |f(x)\rangle$ . -
Interference: Apply Hadamard gates to the first
$n$ qubits. -
Measure: Measure the first
$n$ qubits to obtain a string$y$ .- The interference ensures that only strings
$y$ satisfying$y \cdot s = 0 \pmod 2$ are measured.
- The interference ensures that only strings
Repeat the quantum part until
The module src.algorithms.simon provides the implementation.
Helper function to generate a Simon oracle for a secret string
- Parameters:
s: The secret bitstring (e.g.,"110").
Constructs the quantum circuit part of the algorithm.
-
Returns: A
qiskit.QuantumCircuitthat performs the query and returns$y$ .
Performs the classical post-processing to retrieve
from src.algorithms.simon import build_simon_oracle, create_simon_circuit, solve_simon, run_simulation
# 1. Define secret
secret = "101"
# 2. Build and run
oracle = build_simon_oracle(secret)
qc = create_simon_circuit(oracle)
counts = run_simulation(qc)
# 3. Solve
found_s = solve_simon(counts, len(secret))
print(f"Secret: {found_s}")- Module:
src/algorithms/simon.py - Test Suite:
tests/test_simon.py