# Generic CNOT gate in qiskit from tensor product

I would like to use qiskit to verify for generalized CNOT gates that, e.g. for 4 qubits $$$$\text{cu(0,3)} = |0\rangle\langle 0|\otimes1\!\!1\otimes1\!\!1\otimes1\!\!1 + |1\rangle\langle 1|\otimes1\!\!1\otimes1\!\!1\otimes\sigma_x$$$$ with control on qubit 0 and target on qubit 3, and in particular showing that the matrix representation is the same. While I know that a way to do that in a qiskit circuit is

test_cu = QuantumCircuit(n*2, n)

test_cu.cx(0,3)

backend_un = Aer.get_backend('unitary_simulator')
unitary = execute(test_cu, backend_un).result().get_unitary()
array_to_latex(unitary, pretext="\\text{Circuit = } ")

test_cu.draw()


I don't have any idea on how to make the same from basic operators and using tensor product. I've read that Aqua provides methods for this purpose, but I have nit found anything satisfying on the topic, neither in the official documentation (section tutorial). Thanks in advance.

I believe you are looking for this Operator class in Aqua.
For example, in order to create the Operator cu03 from your question, you can use the Pauli gates from the operator_globals part of Qiskit, and ^ is used as the tensor product between the gates

from qiskit.aqua.operators.operator_globals import Zero, One, I, X, Z
from sympy import Matrix

op_00 = (0.5*(I+Z)) #the |0x0| state in Pauli representation
op_11 = (0.5*(I-Z)) #the |1x1| state in Pauli representation

cu_03 = (op_00^I^I^I)+(op_11^I^I^X)
Matrix(cu_03.to_matrix()) #prints nicely the matrix


Is this what you are looking for? If not please tell me :)

• Exactly, I was searching for an example like this. Thanks a lot! – Hub One Feb 11 at 14:16