Qiskit: BasicAer

Qiskit has various providers which give you the access to various simulators or actual Quantum Computers. BasicAer is one of the providers that Qiskit provides to give access some of the basic simulators. All the simulators provided by BasicAer run on your local machine. In this chapter of the Qiskit Tutorial, you will learn about the BasicAer providers. Subsequent chapter will cover the various simulators in detail.

Importing BasicAer

BasicAer simulators are made available through the BasicAer module in Qiskit.

BasicAer provider can be imported directly from qiskit.

from qiskit import BasicAer

Simulators in BasicAer

BasicAer provides access to the following simulators-

  • QASM Simulator
  • Statevector Simulator
  • Unitary Simulator

The various simulators that BasicAer provides access to can be known by calling the backends() function in BasicAer module.

BasicAer.backends()

The output of this will be a list of available simulators-

[<QasmSimulatorPy('qasm_simulator')>,
 <StatevectorSimulatorPy('statevector_simulator')>,
 <UnitarySimulatorPy('unitary_simulator')>]

Note– The list consists of classes corresponding to the simulator along with a string that corresponds to that simulator. For example, QasmSimulatorPy is the class that corresponds to the QASM simulator and 'qasm_simulator' is the string that corresponds to the QASM Simulator. This string will be used for selecting a particular simulator as you will learn in the following section.

Selecting a Simulator

A particular simulator needs to be selected as the backend for running Quantum Programs. This can be done by calling the get_backend() function of the BasicAer module and passing it the string corresponding to the simulator.

Example

In the following example, QASM simulator is selected as the backend. This is done by passing the string corresponding to QASM Simulator- 'qasm_simulator' to the get_backend() function of BasicAer.

backend = BasicAer.get_backend('qasm_simulator')

Difference between BasicAer and Aer

BasicAer provides access to some of the basic simulators. These simulators are implemented in Python and therefore ideal only for learning purposes and not for high-performance use cases. Qiskit also provides another set of high-performance simulators known as Aer simulators. These simulators are implemented in C++ and are made available in the Aer module in Qiskit. Like BasicAer, Aer also runs simulations on local machine. You will be learning about Aer Simulators in later chapters.