Hadamard test explained
Re\langle\psi|U|\psi\rangle
, where
is a quantum state and
is a
unitary gate acting on the space of
.
[1] The Hadamard test produces a random variable whose
image is in
and whose expected value is exactly
Re\langle\psi|U|\psi\rangle
. It is possible to modify the circuit to produce a random variable whose expected value is
Im\langle\psi|U|\psi\rangle
by applying an
gate after the first Hadamard gate.
Description of the circuit
To perform the Hadamard test we first calculate the state
}\left(\left|0\right\rangle +\left|1\right\rangle \right)\otimes\left|\psi\right\rangle . We then apply the unitary operator on
conditioned on the first
qubit to obtain the state
}\left(\left|0\right\rangle \otimes\left|\psi\right\rangle +\left|1\right\rangle \otimes U\left|\psi\right\rangle \right). We then apply the Hadamard gate to the first qubit, yielding
\left(\left|0\right\rangle ⊗ (I+U)\left|\psi\right\rangle+\left|1\right\rangle ⊗ (I-U)\left|\psi\right\rangle\right)
.
Measuring the first qubit, the result is
with probability
\langle\psi|(I+U\dagger)(I+U)|\psi\rangle
, in which case we output
. The result is
with probability
\langle\psi|(I-U\dagger)(I-U)|\psi\rangle
, in which case we output
. The expected value of the output will then be the difference between the two probabilities, which is
\langle\psi|(U\dagger+U)|\psi\rangle=Re\langle\psi|U|\psi\rangle
To obtain a random variable whose expectation is
Im\langle\psi|U|\psi\rangle
follow exactly the same procedure but start with
}\left(\left|0\right\rangle -i\left|1\right\rangle \right)\otimes\left|\psi\right\rangle .
[2] The Hadamard test has many applications in quantum algorithms such as the Aharonov-Jones-Landau algorithm. Via a very simple modification it can be used to compute inner product between two states
and
:
[3] instead of starting from a state
it suffice to start from the ground state
, and perform two controlled operations on the ancilla qubit. Controlled on the ancilla register being
, we apply the unitary that produces
in the second register, and controlled on the ancilla register being in the state
, we create
in the second register. The expected value of the measurements of the ancilla qubits leads to an estimate of
\langle\phi1|\phi2\rangle
. The number of samples needed to estimate the expected value with absolute error
is
, because of a
Chernoff bound. This value can be improved to
using amplitude estimation techniques.
References
,
Notes and References
- Dorit Aharonov Vaughan Jones, Zeph Landau . A Polynomial Quantum Algorithm for Approximating the Jones Polynomial . Algorithmica . 55 . 3 . 395–421 . 2009 . 10.1007/s00453-008-9168-0 . quant-ph/0511096 . 7058660 .
- Book: quantumalgorithms.org - Hadamard test . Open Publishing . 27 February 2022.
- Book: quantumalgorithms.org - Modified hadamard test . Open Publishing . 27 February 2022.