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?
3 Answers
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
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.
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.