grover

Implements Grover's quantum search algorithm for finding a marked state with quadratic speedup.

18|3|Updated Aug 14, 2026
One-click install
npx skills add https://github.com/unitarylab/quantum-practices --skill grover-unitarylab
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: grover
Source: https://github.com/unitarylab/quantum-practices/tree/main/algorithms/primitives/grover
Command: npx skills add https://github.com/unitarylab/quantum-practices --skill grover-unitarylab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, unitarylab, and includes scripts (resource) components.

What problem does it solve? Searching an unstructured space of N items classically requires O(N) queries. This Skill guides you through understanding, implementing, running, and debugging Grover's quantum search algorithm, which finds a marked computational-basis state with only O(√N) oracle queries using the UnitaryLab GroverAlgorithm implementation. ## Core Features & Use Cases - Guided Implementation: Explains the full Grover pipeline—uniform superposition via H gates, phase oracle with kickback ancilla, diffuser reflection, and the automatically computed optimal iteration count. - Run and Debug Support: Documents the exact parameter schema (n, target as a binary string, backend, device), return fields, and common pitfalls such as integer targets, wrong string lengths, and over-iteration. - Theory-to-Code Mapping: Connects the mathematics (rotation in the 2D Grover plane, sin²((2k+1)θ) success probability) directly to code objects like _build_oracle and _get_optimal_iterations. - Use Case: A user asks to search for the bit string '101' in a 3-qubit space; the Skill produces a standalone GroverAlgorithm().run(n=3, target="101") example and explains how to verify Result == target. ## Quick Start Ask the assistant to run Grover's search for a specific target bit string, for example: run Grover search with n=3 and target '101' using the torch backend and show the amplified probability.

Frequently Asked Questions about grover

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Grover's search algorithm in Python?▼

Instantiate GroverAlgorithm from unitarylab_algorithms and call run() with n qubits and a binary-string target, for example run(n=3, target="101", backend="torch"). The result dictionary contains the most likely state under 'Result' and its probability under 'Amplified target-state probability'.

What is the difference between Grover search and amplitude amplification?▼

Grover search is the special case of amplitude amplification with uniform-superposition state preparation and exactly one marked target. Use general amplitude amplification when you need arbitrary state preparation, multiple good states, or a custom oracle predicate.

Why does Grover search fail when I pass the target as an integer?▼

The implementation expects target as a binary string of exactly n characters containing only '0' and '1', such as target="101" for n=3. Passing an integer like target=5 or a string of the wrong length produces subtle errors that run() does not explicitly guard against.

Can Grover's algorithm search for multiple marked states?▼

This implementation supports exactly one marked target state. Multiple marked states change the search angle to sin θ = √(M/N) and require the general amplitude-amplification framework rather than the standalone GroverAlgorithm class.

Why does the success probability drop with too many Grover iterations?▼

Each Grover iteration rotates the state by 2θ in the Grover plane, so iterating past the optimal count k ≈ π/(4√N) rotates beyond the target and reduces its probability. The implementation auto-computes the near-optimal count via _get_optimal_iterations(p).

How do I verify Grover search found the correct target?▼

Compare result['Result'] with your input target string, since the public status field is 'ok' for any normal completion. The Result is the argmax over statevector probabilities, not a finite-shot measurement sample.