# Doing non-unitary operations on quantum computer

So I am trying to implement non-unitary operations on Qiskit.

There is an option to perform conditional operations in Qiskit.

Suppose I prepare a qubit state in superposition. $$|\psi\rangle=\sqrt{\frac{1}{2}}\left(|0\rangle+|1\rangle\right)$$

Then I measure it in computational basis. The output will be randomly 0 or 1.

I then give an instruction to apply bit flip if the output is 1 and do nothing if the output is 0. I can use the conditional if statement here.

Using this I guarantee that my output will always be $$|0\rangle$$ state no matter what. The entire operation can be represented by

$$O=\sqrt{2}|0\rangle\langle0|$$ matrix (which is non-unitary)

Is this kind of operation a basic example of doing non-unitary operation on a quantum computer which uses only unitary gates?

This is the diagram of the circuit.

• I thought on this and realized the matrix operation changes with respect to the input, such that the output is always |0>. There is no unique matrix which can define such an operation, hence calling it as non-unitary will be not correct I think. Jan 17 at 7:28

Yes, the operation you have just described (projecting a qubit onto the fiducial state $$|0\rangle$$) is indeed an example of a non-unitary operation. Even though all quantum gates are unitary, the measurement allows for the introduction of non-unitarity.

More generally, non-unitary operations are implemented on a gate-based quantum computer by adding ancillary qubits, which effectively allow to embed such non-unitary matrices in larger unitary ones, and then probabilistically selecting the desired quadrant of the larger matrix by measuring the ancillary qubit. For concreteness, you may find a general method to accomplish this in Appendix D of this paper by Lin et al..

Your example, however, leads to a deterministic non-unitary gate by applying a conditional bit-flip instruction based on the measurement outcome. This is an example of classical feedforward, whereby a mid-circuit measurement determines which quantum gate one implements subsequently. Although mid-circuit measurements are already available in some state-of-the-art platforms (e.g., Quantinuum and IBM), the delay resulting from performing the measurements in the quantum processor, deciding the next step on the conventional processor, and finally conveying this decision to the quantum processor may extend the execution time of the circuit beyond the limits set by the decoherence of the qubits. As a result, it is more common to apply non-unitary operations on quantum hardware via probabilistic post-selection, which basically means multiple repetitions of the circuit are executed, with only a few being successful.

• Hi, I had a doubt. What I can see with such an operation is that it transforms any qubit to the |0> state no matter what. If this is non-unitary operation, that means it can be written in a matrix form ? If it can be then what is the matrix representation of this operation ? Jan 18 at 8:04
• Yes, the projection onto the $|0\rangle$ state does have a matrix representation: $|0\rangle \langle0| = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}$. Jan 18 at 14:16

In case you want some software which performs block encodings of non unitary matrices:

As already mentioned, more general non unitary evolution can be implemented on quantum computers using block encodings. This paper describes a non unitary block encoding method for running non unitary matrices on a quantum computer. And here is their Github for the software described in that paper.

• Wow, thanks for sharing. Jan 21 at 7:18
• So basically they are also using the idea of Terashima and Ueda of expanding the hilbert space.arxiv.org/abs/quant-ph/0304061 Jan 21 at 7:23