I am wondering if it is possible to generalize the Hadamard test for computing $\text{Re} \langle \phi | U | \psi \rangle$ (different states for left and right operands).
1 Answers
Yes, it is possible to adapt the Hadamard test to compute the real and imaginary parts of expectation values of the form $\langle \phi | U | \psi \rangle$, as shown in the figure below, where $|\psi \rangle \langle 0|$ corresponds to a unitary operation that prepares the state $|\psi \rangle$ starting from the fiducial state $|0\rangle$ and, as usual, the filled (empty) circle denotes a controlled-operation where the nontrivial action on the target-qubit(s) is triggered when the control-qubit is in state $|1\rangle$ ($|0\rangle$). As in the standard version of the Hadamard test, upon setting $b = 0$ ($b = 1$), the real (imaginary) part is given by $2P_0-1$, where $P_0$ is the probability of measuring the ancillary qubit in state $|0\rangle$. This is valid for an arbitrary number of qubits $n$ in the main register.
P.S.: As @gIS noted in a comment below before I made this update, this circuit does not compute $\textrm{Re}\langle\phi|U|\psi\rangle$ in the same sense that the SWAP test computes $|\langle\phi|\psi\rangle|^2$ or the original Hadamard test computes the real and imaginary parts of $\langle\psi|U|\psi\rangle$. Indeed, this adaptation of the Hadamard test does not take $|\psi\rangle$ and $|\phi\rangle$ as inputs, but rather encodes them via unitaries within the circuit itself. In fact, there cannot be a circuit taking $|\psi\rangle$ and $|\phi\rangle$ and giving as output the real part of $\langle\phi|U|\psi\rangle$, as that quantity would depend on the unphysical global phases of the ket states.
- 1,087
- 1
- 3
- 14
-
Thanks! What is the gate $S^\dagger$? The $b$ parameter is litterally an exponent providing the identity for $b=0$ and $S^\dagger$ for $b=1$, right? – francler Jan 25 '24 at 16:00
-
$S$ usually represents the square root of the Pauli $Z$ operator. Its unitary matrix is $\begin{equation}\begin{pmatrix}1 & 0 \ 0 & i \end{pmatrix}\end{equation}$ Therefore $S^\dagger$ is the conjugate of this $S$ gate namely $\begin{equation} S^\dagger = \begin{pmatrix}1 & 0 \ 0 & -i \end{pmatrix}\end{equation}$ – Callum Jan 25 '24 at 16:51
-
You use $S^\dagger$ for the imaginary part. If you want the real part use $(S^\dagger)^{0} = I$. – Callum Jan 25 '24 at 18:13
-
Thanks! Concerning the controlled operation with the empty circle, can this be achieved by putting an X on the ancilla and then the standard $|1\rangle$ controlled gate right after? Apart from this, do you have any reference about that test? – francler Jan 26 '24 at 07:56
-
The gate with the empty circle is a $|0\rangle$ controlled gate. Yes you could use $X$ gates on either side of the gate on the control qubit of a standard "filled circle" gate. Some quantum libraries like qiskit and pytket support $|0\rangle$ controlled gates directly. – Callum Jan 26 '24 at 09:16
-
I would note though that this circuit does not compute $\operatorname{Re}\langle\phi|U|\psi\rangle$ in the same sense that the SWAP test computes $|\langle \phi|\psi\rangle|^2$. Reason being that the circuit here does not take $|\psi\rangle$ and $|\phi\rangle$ as inputs, but rather encodes them via unitaries within the circuit itself. In fact, there cannot be a circuit taking $|\psi\rangle,|\phi\rangle$ and giving as output the real part of $\langle\phi|U|\psi\rangle$, as that quantity would depend on the unphysical global phases of the ket states – glS Jan 26 '24 at 09:40
-
This comment made by @gIS is actually very important. I will add it to my answer. – bm442 Jan 26 '24 at 11:10
