1
$\begingroup$

I am trying to implement a general 2-qubit gate in an n-qubit system (not using qiskit or cirq). Example: Consider 4 qubits. Assume we want to act a CX on qubit 2 as control and qubit 3 as target. The right implementation would be $I \otimes CX \otimes I$ (most significant qubit is left-most). For two neighboring qubits it will always be a tensor product. How would you implement a CX gate if we wanted to act it, let's say, on qubit 1 as control and qubit 3 as target? I'm assuming it's playing around with the projectors, but I was hoping there is a systematic way of doing it, especially since I need to do this for an n-qubit system.

$\endgroup$
4
  • 1
    $\begingroup$ Depends on what you want precisely. For example one way is to insert SWAPs and use the tensor product rule you described. Another way is to view your quantum circuit as a tensor with multiple legs and perform tensor contraction with the gate legs. $\endgroup$ Commented Dec 27, 2021 at 18:58
  • $\begingroup$ Are you asking about how to show the matrix representation? $\endgroup$
    – Ron Cohen
    Commented Dec 28, 2021 at 15:38
  • $\begingroup$ @RonCohen yes. How would you represent a matrix operator including an arbitrary 2-qubit gate (4-by-4 matrix) acting on any 2 qubits in an n-qubit system? $\endgroup$
    – gquant
    Commented Dec 28, 2021 at 17:17
  • $\begingroup$ @gquant it is legal to write things like $X_3\otimes X_1$ , it is also common to represent CNOT act from Q0 to Q1 as $ CNOT_0_1 $ so you can write in your example $I_1 \otimes I_3 \otimes CNOT_0_2$. is this helpful? $\endgroup$
    – Ron Cohen
    Commented Dec 29, 2021 at 6:55

1 Answer 1

1
$\begingroup$

I think there are two layers to that question.

Physically, this would probably be implemented with swaps or post-interpretation. In other words, in your example qubits 1 or 3 would be swapped with 2, so that it now C-x can be performed on the neighoring qubits, and afterwards the swap would be undone. Swap can be implemented either physically (for ex. in ion-trap machines) or via 3 C-x gates. Alternatively, depending on the rest of the circuit, compiler would just run your algorithm interpreting qubits 1 and 2 as 1 and 3, and assign proper labels during measurement.

Mathematically, you can look at it from a matrix perspective. To C-x qubits 1 and 3 in a 4-qubit system, your unitary would look something like this (assuming 0-indexing):

$ \begin{matrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &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king which of the states get mapped to which other ones (for ex. $0000\rightarrow0000$, $1100\rightarrow1101$, $1101\rightarrow1100$ etc.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.