Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
oracq documentation
oracq documentation

Manuals

  • Complete documentation
    • Installation and environment
    • Operations, registers, and the generation process
    • Source code structure
    • Oracles and operator representations
    • QRAM data structures: pointers, offsets, and random writes
    • Quantum data structures and the KP recommendation system
    • Conventions owned by algorithms: starting from one gate
    • Implementing QPDE/QODE: multiple input paradigms, replaceable oracles, and protocols
    • Automatically generating reversible quantum modules from ordinary math functions
    • QFVM input models and solver replacement
    • General QHAM automatic generation: PDE → HAM → QCL → QODE
    • QCNN line-by-line implementation walkthrough
    • Export and execution backends
    • Resource estimation (Toffoli+Clifford+T+QRAM)
    • Command line
    • Import path migration
    • Applicability boundaries and validation status
  • Algorithm catalog
    • Data Loading and Input Models
      • State Preparation
      • Alias Sampling Preparation
      • XOR Database
      • Adjacency Oracle
      • Select-Swap QROM
      • QROM Lookup
      • Block Encoding Algebra
      • Sparse Access
      • Sparse Matrix Block Encoding
      • PREPARE–SELECT Decomposition
      • Purification Access
      • Gibbs State Preparation
      • Double Factorization
      • Tensor Hypercontraction
    • Basic Query Algorithms
      • Deutsch–Jozsa
      • Bernstein–Vazirani
      • Simon Sampling
    • Query and Search
      • Grover Search
      • Amplitude Amplification
      • Oblivious Amplitude Amplification
      • Fixed-Point Search
      • Amplitude Estimation
      • Quantum Counting
    • Fourier and Arithmetic
      • Quantum Fourier Transform
      • Fourier Addition
      • Order Finding
      • Modular Multiplication
      • Fixed-Point Arithmetic
      • Boolean Networks
    • Estimation and Testing
      • Quantum Phase Estimation
      • Hadamard Test
      • Swap Test
      • Heinrich Quantum Summation
      • Heinrich Quantum Integration
    • Hamiltonian Evolution and QSVT
      • Trotter Product-Formula Simulation
      • Hamiltonian Simulation Protocol
      • QSP Phase Synthesis
      • QSVT Phase Sequence
      • QSVT Matrix Inversion
      • QSVT Hamiltonian Simulation
      • Qubitization Walk
      • Truncated Taylor Block Encoding
      • Eigenstate Filtering
    • Quantum Linear Systems
      • Costa Walk QLSS
      • CKS Chebyshev QLSS
      • VTAA-CKS QLSS
    • Differential Equations
      • QODE Problem and Protocol
      • Linear Combination of Hamiltonian Simulations
      • Schrödingerization
      • CBMD
      • Fokker–Planck Input Model
      • Carleman Linearization
    • Variational and Optimization
      • Hardware-Efficient Ansatz
      • VQE Pauli Measurements
      • QAOA for MaxCut
      • Decoded Quantum Interferometry
      • Jordan Quantum Gradient Estimation
    • Quantum Walks
      • Coined Cycle Walk
      • Szegedy Walk
      • MNRS Quantum Walk Search
    • Quantum Machine Learning
      • Quantum Principal Component Analysis
      • QCNN
      • Density Matrix Exponentiation
    • Quantum Error Correction
      • Repetition Codes
    • Applications and Infrastructure
      • Quantum Finite Volume Method, QFVM
      • General QHAM
      • Math Function Compilation
  • Specification reference
    • Language and algorithm library conventions
    • RIR: the modular register-level intermediate representation
    • QRAM memory definition (qram YAML)
    • Open declarations, capabilities, and binding
    • MIR 0.1: the pure mathematical function graph
    • General QHAM: derivation from PDEs to quantum-adapted linear systems
    • Replacing the QLSS inside QFVM: a review of input models, QRAM data structures, and output contracts
    • OriginIR-ext and PySparQ review
  • API Reference
    • oracq package overview
    • Infrastructure API
      • Toffoli / U3 / CZ lowering
      • OriginIR-ext backend
      • PySparQ backend
      • Quantikz circuit export
      • Strict netlist export
      • Module builder
      • Resource estimation
      • Register reference executor
      • RIR objects
      • Register layout
      • Binding and capability analysis
      • Math-function compilation entry
      • Python math-function frontend
      • MIR objects
      • Math-function lowering
      • Math kernel generation
      • Native implementation registry
      • QRAM pointer-style read/write
      • QRAM YAML memory format
      • Host readout
      • RIR serialization
      • Structural validation
    • Algorithms API
      • Modular multiplication and order finding
      • Oracle query algorithms
      • Reversible arithmetic
      • Phase, amplitude, and overlap estimation
      • Fourier transforms and arithmetic
      • Hamiltonian evolution
      • Quantum summation and integration
      • PREPARE-SELECT decomposition
      • qsp_pyqsp
      • QSVT standard transforms
      • Search and amplitude amplification
      • solve
      • Operator-level synthesis optimization of spectral circuits
      • State-preparation composition
      • Matrix transform sequences
      • Quantum walks
      • Block-encoding composition
      • Algorithm contracts and reports
      • Select-Swap QROM data loading
      • Density-matrix input models and Gibbs states
      • Graph-walk search
      • initial
      • Algorithm structure protocols
      • Chemistry low-rank decomposition block encodings
      • QODE assembly interface
      • Operator wrappers and basic composition
      • Oracle declarations and implementations
      • PDE models and adapters
      • Quantum data structures (qsample and sample-and-query)
      • QHAM
      • Sparse-access adapters
      • Spectral input/output primitives and operator-level optimization
      • DQI decoding quantum interference optimization
      • Quantum gradient estimation
      • Variational algorithm circuits
      • Repetition codes and error recovery
      • Quantum linear systems
      • VTAA-CKS variable-time linear-system solver
      • Quantum convolutional neural networks
      • Quantum building blocks of QCNNs
      • QPCA quantum principal component analysis
      • Quantum semidefinite programming framework
      • KP quantum recommendation system
      • Carleman linearization
      • Quantum Newton method
      • CBMD
      • LCHS
      • Legacy compatibility entry points
      • QODE assembly interface
      • Linear ODE input models
      • Schrödingerization
      • SDE/Fokker–Planck input models
      • solver
      • PDE models and adapters
      • solver
    • Domain Applications API
      • Reference workload catalog
      • Flow fields and QRAM data
      • Algorithm gallery
      • Legacy compatibility entry points
      • oracle_study
      • QFVM application
      • QFVM direct QMem data path
      • QHAM PDE examples
      • QHAM finite closure
      • PDE models and adapters
      • Spatial discretization and classical reference
      • QHAM derivation report
      • Structured finite-difference ports
      • Roe matrix-element generation
      • Roe classical math formulas

Tutorials

  • Tutorials
    • Your first register program
    • Replacing an algorithm’s oracle
    • From a paper’s access model to implementation comparison
    • Search for an element and estimate the success probability
    • Supplying your own Hamiltonian decomposition
    • Swapping QODE methods for the same linear problem
    • Generating QHAM input from a PDE expression
    • Composing PDE inputs and solve instances
    • Composing linear ODE inputs and solve instances
    • Scientific computing workflows: input models, solvers, and reproduction
    • Running and modifying the algorithm gallery

Development

  • Development
    • Development and acceptance
    • Architecture paradigm and interface conventions
    • Framework survey notes (stage 1)
    • Writing documentation
    • Translation Glossary (Chinese → English)
    • Repository reorganization and the algorithm expansion panel
    • Algorithm research workflow improvements
    • Acceptance record for this version
    • Quantum algorithm implementation validation plan (review draft)
    • Validation coverage matrix
    • Quantum algorithm coverage workboard
Back to top
View this page

Grover Search¶

English · 简体中文

Category C3 · Module oracq.algorithms.common.search · Stage V1

Overview¶

Searches a space of \(2^{\text{width}}\) basis states for targets marked by a phase oracle: each Grover iteration rotates the state toward the marked subspace, and after a number of iterations the hit probability peaks. Implementation basis: the amplitude amplification/estimation framework of Brassard et al. (arXiv:quant-ph/0005055; see the Implementation basis section of the algorithm catalog); the iteration count is given by the caller — this entry point does not choose it automatically.

Interface and input model¶

grover(phase_oracle, width, *, iterations=1, preparation=None)

API entry point: grover

  • phase_oracle: a phase Operation marking the target basis states (FO, a phase-function oracle), with interface target and optionally work.

  • width: the target bit width of the search space.

  • iterations: a non-negative iteration count (default 1).

  • preparation: the initial state preparation (SP, must support adjoint calls); when omitted, uniform_state(width) is used. A width inconsistent with width raises ValidationError.

Returns a StateOracle: target holds the search result, and signal keeps the workspace of the phase query and the preparation. Module attributes:

Attribute

Meaning

algorithm

"grover"

iterations

echo of the iteration count

validation_stage

"paradigm"

Related entry points in the same module:

  • phase_from_database(database): adapts a single-output-bit XorDatabase (QRAM lookup) into a phase oracle — load, Z on work, unload; the product is annotated phase_oracle.

  • grover_iterate(preparation, marked): returns the iteration operator \(Q=A(2|0\rangle\langle 0|-I)A^\dagger S_{\mathrm{good}}\) (marks come from phase_marks), used by amplitude estimation to assemble QPE.

Implementation notes¶

A single iteration is: phase oracle → \(A^\dagger\) → positive reflection about the all-zero state (reflect_zero, positive=True) → \(A\); the reflection about the initial state covers both target and the preparation workspace (per the docstring). Register layout: the leading segment of signal is the phase oracle’s work (phase_work bits) and the trailing segment is the preparation’s work; when the phase oracle has no work, the leading segment has width 0. The iteration count is stored as repeat(iterations) and is not expanded during generation or text serialization.

The product is wrapped as a StateOracle and can be composed further as a state oracle (for example as the input of amplify_success). Applicability boundary: the phase oracle’s work must restore itself after its call (the reflections cover only target and the preparation workspace); too many iterations overshoot the peak and lower the hit probability, the same iteration-count constraint as in amplitude amplification.

Validation approach¶

Category C3 (acceptance criterion in docs/development/validation-plan.md §2: the output distribution equals the closed-form expectation). The three layers of evidence match the search.py row of docs/development/validation-coverage.md:

  • Structure: construction and attribute assertions in tests/core/test_algorithm_expansion.py:AlgorithmExpansionTests (non-negative iteration count, consistent preparation width, and similar checks are validated at generation time).

  • Numerical: the module row registers AlgorithmExpansionTests.test_amplification_of_known_quarter_probability (a direct witness of the same iteration principle, see amplitude amplification); the full circuit of grover() has no standalone numerical entry — its iteration operator grover_iterate is witnessed indirectly via QAE’s test_amplitude_estimation_half_probability (the estimation.py row), and the uniform-initial-state special case is demonstrated by the grover entry of the gallery (grover(phase_marks(2, [3]), 2), reading out target=3, signal=0).

  • Binding: the module row registers “—“.

Known gaps and planned stages¶

No known gaps (the search.py row lists “—” in the gap column), stage V1.

Related links¶

  • Source: src/oracq/algorithms/common/search.py

  • Tutorial: Search for an element and estimate the success probability

  • API reference: Search and amplitude amplification

  • Same-group pages: amplitude amplification, amplitude estimation, quantum counting

  • Validation matrix: Validation coverage matrix

Numerical validation¶

Experiment design: two instances with \(n=3\) (\(N=8\)) sweep the iteration count \(k\) on the four backend paths (reference, rir-pysparq, adapter-pysparq, originir-ext); the marked probability and the per-basis-state distribution are compared against the closed-form two-level expressions \(\sin^2((2k+1)\theta)/t\) and \(\cos^2((2k+1)\theta)/(N-t)\). Instance 1: phase_marks(3, (5,)), \(t=1\), \(\theta=\arcsin(1/\sqrt 8)\), \(k=0\ldots4\) (including the oscillating decay after passing the optimal iteration count); instance 2: phase_from_database(gate_database) marking \(\{5,6\}\), \(t=2\), \(\theta=\pi/6\), amplified exactly to 1 at \(k=1\).

Case

Scale

Paths

Metric

Value

grover-phase-marks-n3-t1

N=8, t=1, k=0..4

4 paths

max success-rate error / max distribution error

2.3e-15 / 2.3e-15

grover-xor-database-n3-t2

N=8, t=2, k=0..3

4 paths

max success-rate error / max distribution error

1.4e-15 / 7.2e-16

The theoretical success rates of instance 1 over the iteration counts are 0.125, 0.78125, 0.9453125, 0.330078125, and 0.012207031 (\(k=2\) optimal, \(k\ge3\) overshooting and falling back), reproduced pointwise on all four paths.

Reproduction command:

PYTHONPATH=src /home/agony/projects/qcfd-dev/quantum-cfd-software/.venv/bin/python tests/verification/verify_search_walks.py

Artifacts: out/verification/search_walks.json (cases grover-phase-marks-n3-t1 and grover-xor-database-n3-t2, with per-iteration values).

Next
Amplitude Amplification
Previous
Query and Search
Copyright © 2026, oracq developers
Made with Sphinx and @pradyunsg's Furo
On this page
  • Grover Search
    • Overview
    • Interface and input model
    • Implementation notes
    • Validation approach
    • Known gaps and planned stages
    • Related links
    • Numerical validation