Expand description
Ancilla-interference primitives: the SWAP test and the Hadamard test.
Both extract a number from the interference of an ancilla qubit prepared in
|+⟩, conditionally coupled to a work register, and measured in the X
basis. They are the canonical building blocks for overlap estimation and for
measuring expectation values of (controlled) unitaries.
swap_testestimates the squared state overlap|⟨ψ|φ⟩|²from the ancilla statisticsP(0) = (1 + |⟨ψ|φ⟩|²)/2(Buhrman et al., 2001).hadamard_testestimatesRe⟨ψ|U|ψ⟩(orIm⟨ψ|U|ψ⟩with the imaginary variant) fromP(0) = (1 ± value)/2.
Because this crate stores the full state vector, the ancilla measurement
probability is read off exactly (measure_prob) rather than sampled, so
the returned values are the analytic results, not shot estimates.
Functions§
- hadamard_
test - Estimate
⟨ψ|U|ψ⟩for a single-qubit stateψand single-qubit gateUvia the Hadamard test. - swap_
test - Estimate the squared overlap
|⟨ψ1|ψ2⟩|²of twok-qubit states via the SWAP test.