I'm studying on this textbook but the library has changed meanwhile and running those instructions on my IBM quantum learning notebook will result in errors. What's the current way to draw the unitary matrix resulting from a circuit using the current AerSimulator?

from qiskit_aer import AerSimulator

1 Answer 1


You can get back the matrix by using the save_unitary() method on the circuit after creating your circuit. Here is an example :

import numpy as np

# Import Qiskit
from qiskit import QuantumCircuit, transpile
from qiskit_aer import Aer, AerSimulator

# Construct quantum circuit without measure
circ = QuantumCircuit(2)
circ.cx(0, 1)

# Transpile for simulator
simulator = Aer.get_backend('aer_simulator')
# Another option to create the simulator
# simulator = AerSimulator(method = 'unitary')
circ = transpile(circ, simulator)

# Run and get unitary
result = simulator.run(circ).result()
unitary = result.get_unitary(circ)
print("Circuit unitary:\n", np.asarray(unitary).round(5))

This prints :

Circuit unitary:
 [[ 0.70711+0.j  0.70711-0.j  0.     +0.j  0.     +0.j]
 [ 0.     +0.j  0.     +0.j  0.70711+0.j -0.70711+0.j]
 [ 0.     +0.j  0.     +0.j  0.70711+0.j  0.70711-0.j]
 [ 0.70711+0.j -0.70711+0.j  0.     +0.j  0.     +0.j]]

It isn't available yet in the documentation, but an upgraded version of the tutorials will be available, you can check the tuto in GitHub if you're interested in learning more details about how to use qiskit_aer simulators.

  • $\begingroup$ Thanks for the quick reply, it worked!!! $\endgroup$
    – Antonio
    Mar 25 at 11:21

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.