# Quantum circuit with one unknown gate

You are given a quantum circuit with around 4-5 gates connected. The catch is that you know all the gates and the connection except one gate. For as many times as you want you can check what the output state would be for any input of your choice. How would you find the unknown gate?

I am thinking of writing gates in terms of the unitary matrices and then applying the unitary matrices on the input state . We can assume the unitary Matrix of unknown gate and then do inverse to calculate. But isn't that difficult to do with multi qubit gate? Is there a way to determine the unknown gate?

• Is the unknown gate a 1-qubit, 2-qubit or n-qubit gate? Feb 4 at 13:21
• Depending on the circuit, for simplicity let's assume a 2 qubit gate Feb 4 at 13:38

In the following, I assume that the circuit uses $$n$$ qubits. Therefore, the state vector representing the global state has $$2^n$$ elements (complex numbers). If you are not given the output state, the unknown gate can be any gate and you will not be able to find it. Instead, if you are given the output state $$|\psi'\rangle$$, you can at least reduce the set of candidate gates that will produce the given output state. For a 2-qubit gate, you have 16 complex numbers to find (the elements of a $$4 \times 4$$ matrix). You can compute the vector representing the global state (say, $$|\psi\rangle$$) produced by the circuit until the layer that contains the gate you want to find. The remaining part of the circuit corresponds to a unitary $$U$$ that is function of the 16 unknown complex numbers. You have to solve $$U|\psi\rangle = |\psi'\rangle$$ to find such values. If the number of unknown complex numbers is larger (because the unknown gate operates on $$2 qubits), a sub-optimal solution could be searched using a soft computing approach (e.g., genetic algorithm).

• Can you please elaborate a bit? Specifically from the global state part Feb 4 at 15:40
• I edited the answer to make it more clear. Feb 4 at 16:42
• You have writen ...elements of 2x2 matrix..., however, two-qubit gate is described by 4x4 matrix, right? Feb 4 at 21:44
• Yes, sorry I wrote that in a hurry, I corrected. Feb 4 at 21:53

I would multiply all matrices describing gates while the unknown is a general matrix with each it's element being and unknown variable. Then I would put all basis states on the input and read the output. In the end, I would solve system of equations I gained with this approach. Note that this can be computationally extensive as number of elements of the unknown matrix increases exponentially in number of qubits.

• So if our unknown gate is of n qubit gate, then its unitary matrix will be of the size 2^n * 2^n.Am i correct? Feb 4 at 13:57
• Also is there any other approach to such questions ? Feb 4 at 13:57
• $2^n\times 2^n$ complex numbers Feb 4 at 14:40

Cancel out the known gates by surrounding the circuit with their inverses, then apply any process tomography method.

• I think that the question is more about theoretical approach than how to do this on real quantum processor. Feb 4 at 21:48
• @MartinVesely The answer still applies if it's being done in theory. Cancel out the gates you know and you've reduced the problem to finding the single unknown unitary. Assuming you're in the context of, like, a simulator where you can apply the unknown gate to states and get the final state vector as a result, apply it to an entangled state and read out the matrix using the state channel duality. In other words, do what you'd normally do for process tomography after cancelling the surrounding gates, even in a simulator. Feb 4 at 22:15
• Craig, I want to solve the problem on qiskit. How can I do that? Also can you please tell me more about tomography. Feb 5 at 7:05

The effect of a circuit can be explained by matrix-vector multiplications.

If you start with a state $$\vec{q}$$ and if the gates in your figure are represented by the matrices $$A$$, $$B$$, and $$U$$ (where $$U$$ is the unknown), then the output will be given by $$\vec{q_f} = ABU\vec{q}$$.

The $$AB$$ factor can be replaced by a single matrix called $$C$$, and with symbolic computation (a.k.a computer algebra) you can combine $$U$$ and $$C$$ too.

Let's try this, assuming that your "controlled note" get is just what others usually call "controlled not" or CNOT. Then we have:

$$A = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix},\tag{1}$$

$$B = \begin{bmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix},\tag{2}$$

$$U = \begin{bmatrix} a & b & c & d \\ e & f & g & h \\ i & j & k & l \\ m & n & o & p \end{bmatrix},\tag{3}$$

$$\vec{q} = \begin{bmatrix} 0 \\ 1 \\ 0 \\ 0 \end{bmatrix},\tag{4}$$

and

$$\vec{q}_f = \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}.\tag{5}$$

This would mean that we have:

$$\tag{6} \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} a & b & c & d \\ e & f & g & h \\ i & j & k & l \\ m & n & o & p \end{bmatrix}\begin{bmatrix} 0 \\ 1 \\ 0 \\ 0 \end{bmatrix},$$ $$\tag{7} \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} a & b & c & d \\ e & f & g & h \\ i & j & k & l \\ m & n & o & p \end{bmatrix}\begin{bmatrix} 0 \\ 1 \\ 0 \\ 0 \end{bmatrix},$$

$$\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} f \\ b \\ j \\ n \end{bmatrix}.\tag{8}$$

You now have found 4 out of 16 unknown variables. You can do the same for the other 3 scenarios to get the other 4x3 = 12 unkown variables. You can use this matrix-vector multplier to make the computations easier.

• this got flagged as a duplicate answer of quantumcomputing.stackexchange.com/a/30033/55. Did you perhaps mistakenly post it in two places? If you think the answer should be identical to that to the other post, perhaps this question should be closed as duplicate of the other one?
– glS
Feb 4 at 18:03