6

I need to draw a quantum circuit in Clifford+T library and obtain automatically its transformation matrix. Is there any feature on Qiskit in this case?

glS
  • 24,708
  • 5
  • 34
  • 108
Moein sarvaghad
  • 179
  • 1
  • 8

3 Answers3

19

While you can get the unitary matrix representation of a circuit using the unitary simulator as shown in the other answers, there is a much easier way using the Operator class in the qiskit.quantum_info library.

import qiskit.quantum_info as qi

op = qi.Operator(circ)

If you want the numpy array of the operator, this can be obtained via the data attribute (array = op.data)

See the API Documentation and Operator tutorial for additional info on this class.

cjwood
  • 1,221
  • 8
  • 9
4

In qiskit, you can get the unitary transformation matrix from a quantum circuit by running the following:

from qiskit import *
#circuit already defined
backend = Aer.get_backend('unitary_simulator')
job = execute(circuit, backend)
result = job.result()
print(result.get_unitary(circ, decimals=3))

and the matrix will output. As you increase the number of qubits in your circuit, the size of the unitary matrix will increase exponentially.

Winona
  • 479
  • 3
  • 5
2

The other answer is great.

But here is a link that walk you through the process step-by-step: https://medium.com/mdr-inc/checking-the-unitary-matrix-of-the-quantum-circuit-on-qiskit-5968c6019a45

KAJ226
  • 13,822
  • 2
  • 10
  • 30