1
$\begingroup$

I would like to use qiskit to verify for generalized CNOT gates that, e.g. for 4 qubits \begin{equation} \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 \end{equation} 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.

$\endgroup$

1 Answer 1

4
$\begingroup$

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 :)

$\endgroup$
1
  • 1
    $\begingroup$ Exactly, I was searching for an example like this. Thanks a lot! $\endgroup$
    – Hub One
    Commented Feb 11, 2021 at 14:16

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.