Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Hadamard test

An ancilla-interference circuit for estimating a real or imaginary component of an overlap involving a unitary.

Edition released Coverage: Overview · Technical
On this page

Definition and significance

The Hadamard test estimates quantities such as <psi|U|psi> through one control qubit. It is a reference calculation used inside algorithms, not a visitor assessment. Its name should be explained to avoid confusing a scientific circuit name with a quiz.

Mechanism and mathematical treatment

Prepare the ancilla in |+>, apply controlled-U to the target |psi>, and measure ancilla X. The joint state is (|0>|psi>+|1>U|psi>)/sqrt(2), so <X_anc>=Re<psi|U|psi>. Measuring ancilla Y gives the imaginary part with the corresponding stated phase convention.

Fully worked reference example

Let target |1> and U=diag(1,exp(i pi/3)). The overlap is exp(i pi/3)=1/2+i sqrt(3)/2. Ancilla X has expectation 1/2, hence probabilities 3/4 and 1/4. Ancilla Y has expectation sqrt(3)/2, hence probabilities (2+sqrt(3))/4 and (2-sqrt(3))/4.

Limitations and common misconceptions

Controlled-U can be more expensive than U. Estimating a tiny overlap can require many samples. The circuit supplies one expectation component, not a complete state description.

Scientific relationships

Ancilla interference can estimate selected overlaps and unitary expectations, though direct Pauli measurements can be simpler.

The former estimates a state overlap through exchange; the latter estimates a unitary overlap through coherent control.

A nontrivial complex unitary expectation

Let the target be |psi>=sqrt(3)|0>/2+i|1>/2, whose Bloch vector is (0,sqrt(3)/2,1/2). Choose U=RY(pi/2)RZ(pi/3), with the rightmost gate applied first and R_P(t)=exp(-itP/2). Multiplying the two matrices gives U=(sqrt(6)/4)I-i[(sqrt(2)/4)X+(sqrt(6)/4)Y+(sqrt(2)/4)Z]. Substituting the three Bloch components therefore yields z=<psi|U|psi>=sqrt(6)/4-i sqrt(2)/2. This overlap is neither real nor a phase of unit modulus.

After the controlled operation, tracing out the target gives the ancilla state rho_a=[[1,z conjugate],[z,1]]/2. Its X and Y expectations are respectively sqrt(6)/4 and -sqrt(2)/2, while Z has expectation zero. Consequently the X-positive probability is 1/2+sqrt(6)/8, approximately 0.806186. The Y-positive probability is 1/2-sqrt(2)/4, approximately 0.146447. The negative imaginary component is observable through the chosen Y convention; changing a basis-rotation sign would reverse its reported sign.

Because |z| squared is 7/8, the ancilla purity is (1+|z| squared)/2=15/16. The complete two-register state remains pure, but the ancilla is mixed because the target states in its two branches are not proportional. This provides an internal consistency check: a unitary expectation can have magnitude below one without any physical noise. Branch distinguishability alone reduces the interference visibility.

Basis changes and independent estimator costs

The conceptual procedure for the real component is to prepare the ancilla in |+>, apply controlled-U, apply H to the ancilla, and measure Z. To obtain the imaginary component with the convention above, apply S dagger followed by H before Z measurement. The reported random variable is +1 for bit zero and -1 for bit one. Its average estimates the selected quadrature, so outcome coding belongs to the mathematical specification as well as the software implementation.

For N_X independent real-part shots, the estimator variance is [1-(sqrt(6)/4) squared]/N_X=5/(8N_X). The imaginary-part variance from N_Y fresh shots is [1-(-sqrt(2)/2) squared]/N_Y=1/(2N_Y). With 1,000 shots for each component, the sum of the two variances is 0.001125. This is the mean squared complex error of the unbiased pair of estimators, not a guarantee that every measured complex point lies inside the unit disk. Statistical fluctuations can place an estimate slightly outside that physical region.

Each shot consumes another target preparation and another controlled-U. If the target preparation has cost C_A and controlled-U has cost C_cU, the leading circuit work for N_X+N_Y shots is their sum multiplied by C_A+C_cU, plus ancilla preparation and readout. Merely having a cheap circuit for U does not establish an equal cost for its controlled form. Approximate controlled-gate synthesis introduces a systematic overlap error that does not shrink when the number of shots increases.

Choosing a simpler observable representation

For this particular U, the real part is the known scalar sqrt(6)/4 for every target state. Measuring it through interference is unnecessary once the decomposition is known. The imaginary part is a linear combination of the target's X, Y, and Z expectations, with coefficients -sqrt(2)/4, -sqrt(6)/4, and -sqrt(2)/4. Direct single-qubit Pauli measurements therefore supply an alternative requiring no controlled target operation. Which route is cheaper depends on preparation cost, grouping, coefficients, and available controls.

The same algebra works for a mixed target rho: the ancilla coherence becomes Tr(rho U). A maximally mixed target consequently returns the normalized trace Tr(U)/d in dimension d. That quantity summarizes a unitary without specifying all of its matrix entries. Conversely, a pure-state overlap between independently prepared A|0> and B|0> can be expressed as <0|A dagger B|0>, provided coherent circuits for both preparations and the required controlled composition are available. Copies of the two states alone do not automatically supply those circuit interfaces.

A scalar phase in U must be retained. Replacing U by exp(i alpha)U rotates both estimated quadratures. This is useful when deliberately selecting a quadrature, but it makes an otherwise harmless isolated-unitary phase convention consequential. An overlap protocol should therefore specify the entire controlled operation, rather than only an equivalence class of uncontrolled channels.

Sources

  • A. Barenco et al. · · Research paper · Publication status unspecified · arXiv · DOI 10.1103/PhysRevA.52.3457
    Verification scope

    Selected source text checked ·

    Source anchors gate-decomposition conventions. New worked instances are independent mathematical constructions, not reported experiments.

  • Peter W. Shor · · Research paper · Publication status unspecified · arXiv · DOI 10.1137/S0097539795293172
    Verification scope

    Selected source text checked ·

    Polynomial-time ideal-circuit result; new small numerical instances are original illustrations.