6

What is a Hadamard test? I have seen this term at many places in video lectures and on various weblinks. A detailed answer on this would be a great help. This is what Wikipedia says, but I really could not understand anything.

Edit
I have some knowledge of quantum computing. I know about different gates, quantum states, etc. I saw this term while trying to understand the Pennylane VQLS tutorial. I am greatly struggling with quantum computing because in my study of quantum computing, suddenly some term comes up that I have not seen in general tutorials or video lectures available online.

FDGod
  • 2,901
  • 2
  • 6
  • 31
Manu
  • 247
  • 2
  • 13

2 Answers2

13

In many quantum algorithms, we need to compute the expectation value $\langle\psi|U|\psi\rangle$, where $U$ is an $n$-qubit unitary operator and $|\psi\rangle$ is an $n$-qubit state. The Hadamard test is a quantum algorithmic primitive used to compute this expectation value using one ancilla qubit and some controlled operations[1],[2].

And since $U$ is generally not Hermitian, the expectation value can be a complex number. The Hadamard test is able to measure the real and imaginary parts in two separate measurements.

In Hadamard test we use the following circuit for estimating the real part of $\langle\psi|U|\psi\rangle$

enter image description here

You can easily verify that the probability of measuring the ancilla qubit to be in state $|0\rangle$ equals $\frac{1}{2}(1+\mathrm{Re}[\langle\psi|U|\psi\rangle])$

Similarly, we use the following circuit for estimating the imaginary part

enter image description here

where $S$ is the phase gate. $$S = \begin{pmatrix}1 & 0 \\ 0 & i \end{pmatrix}$$ The probability of measuring the ancilla qubit to be in state $|0\rangle$ equals $\frac{1}{2}(1+\mathrm{Im}[\langle\psi|U|\psi\rangle])$

To compute the expectation value with absolute error $\epsilon$ we need to repeat this procedure $\mathcal{O}(1/\epsilon^2)$ times.

Hadamard test is part of many algorithms. For example:

  • If $|\psi\rangle$ equals the basis state $j$, Hadamard test can be use to get the diagonal element $u_{jj}$ for the matrix $U$. This technique used in Aharonov–Jones–Landau algorithm to compute the Jones polynomial of the plat closure of a braid[3].
  • We can use Hadamard test to compute the trace of the matrix $U$ by choosing $|\psi\rangle$ to be the maximally mixed state. This technique used by Shor and Jordan to compute the Jones polynomial of the trace closure of a braid in the DQC1 model of computation[4].
  • If $|\psi\rangle=|\phi_1\rangle|\phi_2\rangle$, and $U$ is the $n$-qubit SWAP gate, the probability of measuring the ancilla qubit to be in state |0⟩ equals $\frac{1}{2} + \frac{1}{2}|\langle\phi_1|\phi_2\rangle|^2$. So, we can use this circuit to estimate the overlap of two the quantum states $|\phi_1\rangle$ and $|\phi_2\rangle$. This is known as the swap test. It is commonly used in quantum machine learning[5].

enter image description here

  • Hadamard test is also used to approximate tensor network contraction[6], to extract information about the gradient of the objective function in variational algorithms[7], ...etc.

[1] Childs. Lecture Notes on Quantum Algorithms.

[2] Lin. Lecture Notes on Quantum Algorithms for Scientific Computation.

[3] Aharonov, Jones and Landau. A Polynomial Quantum Algorithm for Approximating the Jones Polynomial

[4] Shor and Jordan. Estimating Jones polynomials is a complete problem for one clean qubit

[5] https://en.wikipedia.org/wiki/Swap_test

[6] Arad and Landau. Quantum computation and the evaluation of tensor networks.

[7] Harrow and Napp. Low-depth gradient measurements can improve convergence in variational hybrid quantum-classical algorithms

Egretta.Thula
  • 11,986
  • 1
  • 13
  • 34
-2

Like others said, not sure what answer you are expecting. Hadamard gate is a single qubit quantum gate. In simple terms, this gate maps the initial state of |0> to an equal superposition of $|0\rangle$ and $|1\rangle$. It maps $|1\rangle$ also to an equal superposition of $|0\rangle$ and $|1\rangle$ but with a different relative phase. $H|0\rangle$ and $H|1\rangle$ both have magnitude $1$ based on the formula and are orthogonal to each other. Based on that criteria, you run the test, and it will make more sense now, hopefully.

FDGod
  • 2,901
  • 2
  • 6
  • 31