Documentation
¶
Overview ¶
Package grover implements Grover's quantum search algorithm.
The algorithm amplifies the probability of marked states using an oracle and a diffusion operator. For N states with M solutions, the optimal number of iterations is approximately π/4 * √(N/M).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// NumQubits is the number of search qubits.
NumQubits int
// Oracle marks the target states.
Oracle Oracle
// NumIters is the number of Grover iterations.
// 0 means optimal: floor(π/4 * √(2^n / M)).
NumIters int
// NumSolutions is the number of marked states (M). Default: 1.
NumSolutions int
// Shots is the number of measurement shots. Default: 1024.
Shots int
}
Config specifies the Grover search parameters.
type Oracle ¶
Oracle marks target states by flipping their phase. It receives a builder and the working qubit indices.
func BooleanOracle ¶
BooleanOracle creates an oracle from a classical boolean function. The function f takes a bit pattern (as int) and returns true for marked states.
This implementation enumerates all 2^numQubits inputs to find the satisfying assignments, then delegates to PhaseOracle which applies a phase flip to each marked state. This is suitable for simulation but not for hardware, where the oracle would need to be compiled into a reversible circuit.
func PhaseOracle ¶
PhaseOracle creates an oracle that marks specific target states by index. Each target is an integer representing a computational basis state.