# How to implement linear combination of two unitary gates in a quantum circuit?

I wanted to implement a non-unitary operation. I came to know that I can do it as a linear combination of unitaries from this paper (published version). Let us say I want to implement an operation like $$\alpha_1 A_1 + i \alpha_2 A_2$$ in a quantum circuit, where $$A_1$$ and $$A_2$$ and unitary operators. Coeffient $$\alpha$$ are real. How do you do that

• Please don't link directly to the PDF of the paper, but to the abstract page, so that people without access can see the title and abstract. Or even people with access can see it before deciding if they want to download the PDF. This is the abstract page. I've edited your question to link instead to the arXiv version of the paper, which is even better, as anyone can access it. Sep 15, 2020 at 9:38

The place where I came to know about this technique was here, which will give more details than I'm about to reproduce. In overview, you want to make a unitary $$B$$ such that $$B|0\rangle=(\sqrt{\alpha_1}|0\rangle+\sqrt{\alpha_2}|1\rangle)/\sqrt{\alpha_1+\alpha_2},$$ (I'm assuming the $$\alpha_i$$ are positive) and a second unitary $$U=|0\rangle\langle 0|\otimes A_1+|1\rangle\langle 1|\otimes A_2$$

A very crude way of implementing the operation would then be to start with $$|0\rangle|\psi\rangle,$$ where $$|\psi\rangle$$ is the state that you want to apply the superposition of unitaries. You apply $$B$$ to the first qubit, $$U$$ across both, then $$S$$ (phase gate) and $$B^\dagger$$ on the first qubit. Measure the first qubit, and if it is $$|0\rangle$$, you have succeeded.

If your amplitudes were negative, you can compensate for that by changing the phase rotation at the point where I applied $$S$$ in that sequence.

To see this, the evolution sequence is \begin{align*} |0\rangle|\psi\rangle &\xrightarrow{B} (\sqrt{\alpha_1}|0\rangle+\sqrt{\alpha_2}|1\rangle)|\psi\rangle/\sqrt{\alpha_1+\alpha_2} \\ &\xrightarrow{U} (\sqrt{\alpha_1}|0\rangle(A_1|\psi\rangle)+\sqrt{\alpha_2}|1\rangle(A_2|\psi\rangle))/\sqrt{\alpha_1+\alpha_2} \\ &\xrightarrow{S} (\sqrt{\alpha_1}|0\rangle(A_1|\psi\rangle)+\sqrt{\alpha_2}i|1\rangle(A_2|\psi\rangle))/\sqrt{\alpha_1+\alpha_2} \end{align*} This gets you up to just before applying $$B^\dagger$$ and measuring. This is equivalent to projecting the first qubit onto $$(\sqrt{\alpha_1}\langle 0|+\sqrt{\alpha_2}\langle 1|)/\sqrt{\alpha_1+\alpha_2}$$. This measuremnt result leaves the second qubit in $$\frac{\alpha_1A_1+i\alpha_2A_2}{\alpha_1+\alpha_2}|\psi\rangle,$$ which you can use to assess the success probability.

For such a small number of terms in superposition, this is likely to be highly successful. However, if the probability of success is low, then you can improve your changes by getting rid of the measurement and instead performing amplitude amplification (i.e. essentially Grover's search, searching for when that first qubit is $$|0\rangle$$).

• $B$ is just a (real) rotation matrix with $\cos^2(\theta)=\alpha_1/(\alpha_1+\alpha_2)$...what happens if $\alpha_1=-\alpha_2$? Sep 15, 2020 at 21:44
• I clearly made an implicit assumption that the $\alpha_i$ are positive. You correct for phases in the part where I applied $S$ (if you also apply $Z$, that adds a minus sign) Sep 16, 2020 at 6:37
• $U$ can be written as $A_1 \oplus A_2$ which makes it easier to see that it is unitary. Another form is $U=I \otimes (A_1 +A_2) + Z \otimes (A_1-A_2)$...unless I'm missing something that means if you measure $|0>$ then you've applied the sum of the two operators...otherwise you've applied the difference.... Sep 16, 2020 at 8:09
• The operator form is correct, but I don't follow your subsequent argument. Sep 16, 2020 at 9:31
• small correction to my last comment : replace $A_1 \pm A_2$ with $(A_1 \pm A_2)/2$. the last part is trying to determine $\psi$ after measuring $Z$ on the first qubit after applying $B^\dagger U B$ to $|0\psi>$. If the measurement is +1 then we know $\psi \to (\alpha_1 A_1 + \alpha_2A_2)\psi$ (overlooking some scaling...). What if the measurement is -1? I thought maybe $\psi \to (\alpha_1 A_1 - \alpha_2 A_2)\psi$...but my first attempt at showing that didn't work....still I feel there should be a simple relation between the two possible outcomes. Sep 16, 2020 at 21:11