# How to transform e.g., a 4 by 4 unitary matrix into a quantum circuit

I am new to Quantum Computing. I would really appreciate if some one could offer me some ideas, suggestions and/or useful references to solve the following problem about realizing an arbitrary operator by a quantum circuit.

If I start with a general two-qubit operator $$\hat{U}$$ (which corresponds to a 4 by 4 unitary matrix $$U$$ in the computational basis), what is the strategy to (1) decompose $$U$$ into the basic gates, such as the $$CNOT$$ gate, the Hadamard gate $$H$$, and the single-qubit rotational gates ($$R_x$$, $$R_y$$ and $$R_z$$); (2) design the corresponding quantum circuit to realize this two-qubit operator $$\hat{U}$$ (either with ancillary qubits or not)?

In other words, what is the strategy (1) to convert the following unitary matrix (two-qubit operator $$\hat{U}$$ in the computational basis $$\{ |00\rangle, \ |01\rangle, \ |10\rangle, \ |10\rangle \}$$) \begin{align} U= \begin{pmatrix} a & b & c & d \\ b^{\ast} & f & g & h \\ c^{\ast} & g^{\ast} & i & j \\ d^{\ast} & h^{\ast} & j^{\ast} & k \end{pmatrix} \ , \end{align} into the basic gates (e.g., $$CNOT$$, $$H$$, $$R_x$$, $$R_y$$ and $$R_z$$ gates); and (2) to realize the unitary matrix $$U$$ in a quantum circuit?

Thank you!

A universal method to decompose 2-qubit unitaries into primitive gates is sometimes referred to as "Krauss-Cirac decomposition". Here are several sources:

For gates on multiple qubits, this question offers several more sources.

• @ Mariia Mykhailova Thank you for your comments and suggestions. I will read these papers to solve the toy problem described in the question. I do have further questions. Are there other options for solving this problem, such as the Cosine-Sine Decomposition and the Gray code. Are they applicable? – Marxmas Dec 19 '19 at 2:32
• @ Mariia Mykhailova I ask so because of the following reason. Eventually, I would like to generalize the 4 by 4 problem to, e.g., 8 by 8 matrix problem. Therefore, I am looking for functional algorithms (it would be better if they go with examples) that are more general, robust and hopefully efficient as well. I was wondering if you would recommend some useful references as well for solving the more general problems, e.g., decomposing the 8 by 8 matrix. – Marxmas Dec 19 '19 at 2:33
• I've added a link to a question that has more resources on decomposing multi-qubit gates. – Mariia Mykhailova Dec 19 '19 at 17:47

Every 2x2 unitary matrix can be decomposed to a matrix product of four matrices expresing rotations and phase shifts.

Every controlled operator (i.e. two qubit gate) can be decomposed to product of three single qubit gates acting on target qubit and two CNOT gates. Single qubit gates can be again decomposed to rotations and phase shifts are mentioned above.

In case your 4x4 matrix can be writen as Kronecker product of two 2x2 matrices, you can again apply decomposition from the first paragraph.

Based on these theorems, you can rewrite any two qubit operators in terms of CNOTs and single qubits rotations and phase shifts. All these gates are available on a quantum computer.

Please see details how to do so in Elementary gates for quantum computing.