hadamard-test

Estimates expectation values and overlaps using Hadamard and swap tests.

30|2|Updated Apr 16, 2026
One-click install
npx skills add https://github.com/unitarylab/quantum-skills --skill hadamard-test
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hadamard-test
Source: https://github.com/unitarylab/quantum-skills/tree/main/algorithms/primitives/hadamard-test
Command: npx skills add https://github.com/unitarylab/quantum-skills --skill hadamard-test

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

The Hadamard Test Skill enables efficient estimation of the real and imaginary parts of the expectation ⟨ψ|U|ψ⟩ for a unitary U on a state |ψ⟩, and it also supports measuring overlaps via a swap test. It provides a reusable workflow for quantum algorithm debugging, verification, and phase information extraction.

Core Features & Use Cases

  • Three modes: 'expectation' (real/imag parts), 'swap_test' (overlap), and 'phase_estimation' (complex eigenphase).
  • Optional imaginary component extraction via S† on the ancilla, and support for preparing arbitrary target states.
  • Flexible backend simulation with shot-based noise and optional circuit diagram export for visualization.
  • Works with a GateSequence representation and a HadamardTestAlgorithm runner to integrate into larger quantum workflows.
  • Educational and prototyping friendly, suitable for learning, experimentation, and algorithm development.

Quick Start

Instantiate U and prepare_psi, then run HadamardTestAlgorithm with mode set to 'expectation' to obtain the Re/Im estimates.

Frequently Asked Questions about hadamard-test

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

FAQPage Schema
How do I estimate the real and imaginary parts of a quantum expectation value ⟨ψ|U|ψ⟩?

To estimate the expectation value ⟨ψ|U|ψ⟩, you can run a Hadamard test using a GateSequence representation for the unitary U and prepared state |ψ⟩. An optional S† gate on the ancilla qubit extracts the imaginary part of the expectation value.

Can I measure state overlap |⟨φ|ψ⟩|^2 without a full state tomography?

Yes, you can measure the state overlap |⟨φ|ψ⟩|^2 using the swap_test mode. This mode calculates the overlap between two arbitrary prepared quantum states by applying a controlled-SWAP operation, providing an efficient alternative to full state tomography.

How does phase estimation work with a Hadamard test circuit?

Phase estimation is supported through a dedicated mode that extracts the complex eigenphase of a unitary operator. It integrates with the HadamardTestAlgorithm runner by utilizing the GateSequence representation of the unitary to estimate the phase within a simulated quantum environment.

Do I need a specific quantum backend to run Hadamard test simulations?

You need a simulated backend that supports shot-based noise to run Hadamard test simulations. The workflow operates on a GateSequence representation for the unitary and prepared states, allowing for flexible prototyping and optional circuit diagram export for visualization.

What is the best way to verify a quantum algorithm's unitary operation during prototyping?

The best way to verify a unitary operation during prototyping is by estimating its expectation value using a Hadamard test. This approach allows you to debug and validate the GateSequence representation of your quantum circuit by measuring the real and imaginary parts with shot-based noise simulation.