How to calculate inner product of quantum states with other method than swap test? [duplicate]

In connection to this question, I am wondering how to calculate value $$\langle \psi|\phi \rangle$$ for arbitrary quantum states $$|\psi\rangle$$ and $$|\phi\rangle$$.

A swap test is able to return only $$|\langle \psi|\phi \rangle|^2$$ which means that sign of the product is forgotten in case the inner product is real. Moreover, information about real and imaginary parts is lost in case of complex result.

Do you know about any more general method how to calculate the inner product than swap test?

• A method for finding $\langle\psi|\phi\rangle$ would let us observe the global phase which is unobservable. To see this set $|\psi\rangle = |0\rangle$ and $|\phi\rangle=e^{i\theta}|0\rangle$. Therefore, no such method exists. May 28 '21 at 18:14
• There are methods to estimate the inner product see quantumcomputing.stackexchange.com/q/6339/11793 which shows how to get the real part. You can use a similar trick to estimate the imaginary part of the inner product, thus giving you an estimate of the whole thing. Though you would need to be able to prepare the states and run the circuit over and over again. May 28 '21 at 18:31
• @Condo That only works if you are given a state that already incorporates $|\psi\rangle$ and $|\phi\rangle$ with a fixed phase relationship. If all you have is two separate states, your quoted method won't work. May 28 '21 at 18:41
• I don't know what you mean by "fixed phase relationship", but I'm thinking about $|\psi\rangle$ and $|\phi\rangle$ as elements of a projective Hilbert space i.e. where $\lambda|\psi\rangle$ and $|\psi\rangle$ for $\lambda\in \mathbb{C}$ are the same physical state. May 28 '21 at 18:53
• I'm thinking of the two states as elements of different Hilbert spaces. If you're given two different qubits (or whatever) with unknown physical states, the method to which you linked will not work. That's because we cannot have a procedure that takes $|0,\phi,\psi\rangle$ to $|0,\psi,a\rangle+|1,\phi,b\rangle$. May 28 '21 at 19:09

I doubt that this is possible. Given a state $$|\phi\rangle$$, we have no method for distinguishing it from $$e^{i\varphi}|\phi\rangle$$ for any phase $$\varphi$$. This means that we have no way of distinguishing between $$\langle\psi|\phi\rangle\qquad \mathrm{vs.}\qquad e^{i\varphi}\langle\psi|\phi\rangle.$$ Specifically, we can choose $$\varphi$$ such that $$e^{i\varphi}\langle\psi|\phi\rangle=|\langle\psi|\phi\rangle|.$$ We thus should be precluded from measuring anything other than this absolute value.
To get around this constraint, we would need to set up a superposition of $$|\phi\rangle$$ and $$|\psi\rangle$$ like $$|\Psi\rangle\propto |\psi\rangle+|\phi\rangle.$$ Only then could we get around the global phase problem. I would be interested in seeing a circuit that can take $$|0\rangle|\psi\rangle|\phi\rangle\to|\Psi\rangle|a\rangle|b\rangle$$ for any generalized ancilla $$|0\rangle$$ and final states $$|a\rangle$$ and $$|b\rangle$$. If I had to guess, I would say that it is impossible to perform this transformation with a fixed relative phase in $$|\Psi\rangle$$. We might be happy saying that $$|0\rangle|\psi\rangle|\phi\rangle\to\frac{|\psi\rangle+|\phi\rangle}{\mathcal{N}}|a\rangle|b\rangle$$ for some normalization constant $$\mathcal{N}$$, but then we would need to also be happy with the transformation $$|0\rangle|\psi\rangle e^{i\varphi}|\phi\rangle\to\frac{|\psi\rangle+e^{i\varphi}|\phi\rangle}{\mathcal{N}}|a\rangle|b\rangle,$$ but that is nonsensical for the same deterministic transformation, because the initial states $$|0\rangle|\psi\rangle |\phi\rangle$$ and $$|0\rangle|\psi\rangle e^{i\varphi}|\phi\rangle$$ are indistinguishable.