# What are the differences in using qasm, statevector, and unitary simulators in qiskit?

From my understanding statevector is a more simplistic using vector space, qasm is supposed to introduce noise like running it on an actual quantum computer. What types of problems would you use one simulator over another? I am not too familiar with unitary simulators as the class I took mostly covered qasm and statevector.

They all produce different types of result. Let's go one by one:

from qiskit import QuantumCircuit, Aer
from qiskit.visualization import array_to_latex


## Unitary Simulator

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.draw('mpl')


unitary_simulator = Aer.get_backend('unitary_simulator')
unitary_simulator_result = unitary_simulator.run(circuit).result()
unitary_simulator_result.data()

{'unitary': Operator([[ ...
}


The result is an Operator. It can be printed nicely like this:

array_to_latex(unitary_simulator_result.get_unitary())


$$\begin{bmatrix} \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}} & 0 & 0 \\ 0 & 0 & \tfrac{1}{\sqrt{2}} & -\tfrac{1}{\sqrt{2}} \\ 0 & 0 & \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}} \\ \tfrac{1}{\sqrt{2}} & -\tfrac{1}{\sqrt{2}} & 0 & 0 \\ \end{bmatrix}$$

It is useful, for example, when you want to set some unitary at arbitrary point of the execution:

circuit = QuantumCircuit(2)
circuit.set_unitary(random_unitary(4))
circuit.h(0)
circuit.cx(0, 1)
unitary_simulator_result = unitary_simulator.run(circuit).result()
unitary_simulator_result.get_unitary()


## Statevector Simulator

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)

statevector_simulator = Aer.get_backend('statevector_simulator')
statevector_simulator_result = statevector_simulator.run(circuit).result()
statevector_simulator_result.data()

{'statevector': Statevector([ ...
}


The result is a Statevector. It can be printed nicely like this:

array_to_latex(statevector_simulator_result.get_statevector())


$$\begin{bmatrix} \tfrac{1}{\sqrt{2}} & 0 & 0 & \tfrac{1}{\sqrt{2}} \\ \end{bmatrix}$$

It can be useful, for example, to make snapshots during different points of the execution:

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.save_statevector('breakpoint')
circuit.cx(0, 1)

statevector_simulator = Aer.get_backend('statevector_simulator')
statevector_simulator_result = statevector_simulator.run(circuit).result()
array_to_latex(statevector_simulator_result.data()['breakpoint'])


$$\begin{bmatrix} \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}} & 0 & 0 \\ \end{bmatrix}$$

## QASM Simulator

Needs measurments, as it simulates an idea (without noise, by default) quantum hardware.

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()  # <--
circuit.draw('mpl')


qasm_simulator = Aer.get_backend('qasm_simulator')
qasm_simulator_result = qasm_simulator.run(circuit).result()
qasm_simulator_result.data()

{'counts': {'0x3': 534, '0x0': 490}}


The result is a Python dict. It can be printed nicely like this:

plot_histogram(qasm_simulator_result.get_counts())


With this simulator, you can simulate a executions in shots and get the value of each of them:

memory_result = qasm_simulator.run(circuit, shots=10, memory=True).result()
memory_result.get_memory(circuit)

['00', '00', '11', '11', '00', '00', '11', '11', '00', '00']

1. Statevector Simulator - It gives the output of the circuit in the form of a statevector

2. Qasm Simulator - This backend simulates the execution of quantum circuits on a real noisy device.

3. Unitary Simulator - It gives the output of the circuit in the form of a unitary matrix.

You can use the Qiskit simulator tutorials to learn more and explore these simulators, as well as discover new ones.

Simply put: all three simulators are ideal, noise-free simulators on classical computers.

• Unitary simulator: you get a unitary matrix as result

• Statevector simulator: you get a statevector (2^qubit array) as result

• Qasm simulator: you get a measurement histogram or state dictionary as result

Qasm simulator might be the closet to a real and perfect quantum computer, which does not exist yet.