Qiskit Aer
repository·main·Indexed 20 days ago
https://github.com/qiskit/qiskit-aerA high-performance quantum circuit simulator for Qiskit that supports realistic noise models and hardware-like execution via primitives. It provides SamplerV2 and EstimatorV2 for obtaining quasi-probability distributions and expectation values. Aer extends Qiskit's QuantumCircuit with simulation-specific methods for setting states (e.g., set_density_matrix) and saving data (e.g., save_statevector). Supports GPU acceleration via CUDA on Linux x86_64 and MPI for parallelizing statevector, density matrix, and unitary simulations.
What's inside qiskit-aer
- Qiskit Aer is a high-performance quantum computing simulator designed to run quantum circuits with or without realistic noise models. It offers multiple simulation methods and supports performance optimizations such as MPI (Message Passing Interface) and GPU acceleration to handle complex simulations efficiently.
Locate and understand Aer benchmark types
mainAer benchmarks are located in the
test/benchmarkdirectory. They are defined in*_benchmarks.pyfiles. The current suite includes:- Quantum Volume: Benchmarks testing different numbers of qubits and various noise models.
- Simple one-gate circuits: Benchmarks testing simple gate operations (e.g.,
U3,CX) across different qubit counts and noise models.
Access Aer-specific QuantumCircuit methods
mainAer extends the standard
qiskit.circuit.QuantumCircuitclass with simulation-specific methods for setting states and saving data. Crucially, these methods are only available after you have importedqiskit_aer. If you attempt to call them before importing the Aer package, they will not be found on theQuantumCircuitobject.import qiskit import qiskit_aer # Aer must be imported to patch QuantumCircuit qc = qiskit.QuantumCircuit(2) # Now Aer-specific methods like qc.save_statevector() are availableCustomize job-level parallel execution with executor and max_job_size
mainBy default, Qiskit Aer runs simulation jobs on a single-worker Python multiprocessing
ThreadPoolexecutor, relying on low-level OpenMP and CUDA for parallelization. To customize how multiple circuits are executed in parallel at the job level, you can provide a custom multiprocessing executor and control how circuits are grouped using theexecutorandmax_job_sizebackend options.executor: A multiprocessing executor (e.g.,concurrent.futures.ThreadPoolExecutor) used to submit chunks of circuits. Defaults toNone.max_job_size: Controls the number of circuits in each chunk.- If
max_job_size=1, every circuit is treated as an individual job. For 60 circuits, Aer submits 60 jobs. - If
max_job_size=2, circuits are grouped into pairs. For 60 circuits, Aer submits 30 jobs, each containing 2 circuits.
- If
import qiskit from concurrent.futures import ThreadPoolExecutor from qiskit_aer import AerSimulator from math import pi # Generate circuits circ = qiskit.QuantumCircuit(15, 15) circ.h(0) circ.cx(0, 1) circ.cx(1, 2) circ.p(pi/2, 2) circ.measure([0, 1, 2], [0, 1 ,2]) circ2 = qiskit.QuantumCircuit(15, 15) circ2.h(0) circ2.cx(0, 1) circ2.cx(1, 2) circ2.p(pi/2, 2) circ2.measure([0, 1, 2], [0, 1 ,2]) circ_list = [circ, circ2] qbackend = AerSimulator() # Set executor and max_job_size exc = ThreadPoolExecutor(max_workers=2) qbackend.set_options(executor=exc) qbackend.set_options(max_job_size=1) result = qbackend.run(circ_list).result()Distribute multiple shots across multiple nodes
mainWhen usingdevice='GPU', you can distribute multiple shots across multiple nodes by setting thebatched_shots_gpu=Trueoption. The results will be distributed back to each process.Install Qiskit Aer from source
mainInstalling from source allows you to use the latest development version. You should first follow the Qiskit source installation instructions.
To build from source:
- Clone the repository.
- Install development dependencies using
requirements-dev.txt. - Install the package using
pip install .or build a wheel using thebuildmodule.
Building with GPU support To enable GPU acceleration (CUDA) during a source build on Linux, set the
AER_THRUST_BACKEND=CUDAflag.Building with MPI support To enable MPI support for parallelizing
statevector,density_matrix, orunitarysimulations, ensure an MPI library (like OpenMPI) is installed on your system and set theAER_MPI=Trueflag during the build.# Clone and install dependencies git clone https://github.com/Qiskit/qiskit-aer cd qiskit-aer pip install -r requirements-dev.txt # Standard source install pip install . # Build wheel using build module pip install build python -I -m build --wheel # Build with GPU support (Linux only) python ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA # Build with MPI support python ./setup.py bdist_wheel -- -DAER_MPI=TrueRun Qiskit Aer with MPI parallelization
mainTo run Qiskit Aer using MPI parallelization across a cluster, use an MPI executor like
mpirunto submit your Python script. You do not need to manually manage MPI processes within your Python code, asMPI_Initis called internally by Qiskit Aer.To ensure consistent circuit generation and parameters across all parallel processes, you must set a consistent random seed using
qiskit.utils.algorithm_globals.random_seed.mpirun -np 4 python example.pyInterpret Aer benchmark output data
mainBenchmark results are displayed in tables organized by the number of qubits and the applied noise model.
Each row starting with
Num. qubits:represents a specific configuration. For every qubit count, the framework runs benchmarks against multiple noise models.Example Interpretation: If you see the following output:
-- Noise Model ----------------- ------------------------------------------------------------ Quantum Volume No Noise Mixed Unitary Noise Reset Noise Kraus Noise ================= ========== ===================== ============= ============= Num. qubits: 15 3.17±2s 2.38±2s 2.19±2s 9.76±2sThis indicates that for a Quantum Volume circuit with 15 qubits, the execution times were:
- No Noise: 3.17 ± 2 seconds
- Mixed Unitary Noise: 2.38 ± 2 seconds
- Reset Noise: 2.19 ± 2 seconds
- Kraus Noise: 9.76 ± 2 seconds
Num. qubits: 15 3.17±2s 2.38±2s 2.19±2s 9.76±2sConfigure distributed parallelization with multiple GPUs or nodes
mainQiskit Aer parallelizes simulations by distributing quantum states into chunks (sub-states of smaller qubit counts) to manage distributed memory space. To enable this distributed parallelization across multiple GPUs or nodes, you must configure specific backend options. While Aer may attempt to set these automatically if memory is insufficient, it is recommended to set them explicitly.
Required configuration options:
blocking_enable: Set toTrueto enable distributed parallelization. (Default isFalse).blocking_qubits: Sets the number of qubits per chunk. This value must be small enough so that the chunk fits within the smallest available memory space (e.g., a single GPU).
To ensure the chunk fits, satisfy the following inequality in bytes:
sizeof(complex) * 2^(blocking_qubits + 4) < size of the smallest memory spacesim = AerSimulator(method='statevector', device='GPU') circ = transpile(QuantumVolume(qubit, 10, seed = 0)) circ.measure_all() result = execute(circ, sim, shots=100, blocking_enable=True, blocking_qubits=23).result()Install and run Aer benchmarks using Airspeed Velocity
mainAer uses the Airspeed Velocity (ASV) framework to detect performance regressions. Note that benchmarks are only implemented for the Qiskit Addon, not for standalone mode.
To run benchmarks, you must first ensure all project build prerequisites are installed. Then, follow these steps:
- Install
asvvia pip:pip install asv - Navigate to the
testdirectory:cd test - Execute the benchmark suite using the configuration file corresponding to your operating system. Currently, only Linux and MacOS are supported.
# For Linux asv run --config asv.linux.conf.json # For MacOS asv run --config asv.macos.conf.json- Install
Install Qiskit Aer locally
mainTo install the standard version of Qiskit Aer, ensure you have Qiskit installed in your virtual environment first, then use
pipto installqiskit-aer.Installing GPU support To run GPU-supported simulators (
statevector,density matrix, andunitary) on Linux, you must have CUDA® 10.1 or newer installed. Instead of the standard package, installqiskit-aer-gpu, which will overwrite the standard installation and provide the additional GPU capabilities. Note thatqiskit-aer-gpuis only available on x86_64 Linux.# Standard installation pip install qiskit-aer # GPU supported installation (Linux x86_64 only, requires CUDA 10.1+) pip install qiskit-aer-gpuInstall GPU support for Aer
mainTo run GPU-supported simulators (
statevector,density matrix, andunitary) on Linux, you must have CUDA 11.2 or newer installed.Depending on your CUDA version, install the corresponding package. Note that installing these will overwrite your existing
qiskit-aerinstallation with the GPU-enabled version.Requirements:
- Linux x86_64 (Other platforms require building from source).
- NVIDIA GPU drivers and CUDA installed.
Installation commands:
- For CUDA 12:
pip install qiskit-aer-gpu
- For CUDA 11: ```bash pip install qiskit-aer-gpu-cu11