Qiskit 0.46 and 1.0 (IBM)
Quantum Information Science Kit (Qiskit) is an open-source SDK developed by International Business Machines (IBM) for operating quantum computers through circuits, pulses, and algorithms. It is available in Python.
The Qiskit ecosystem is composed of four so-called elements:
terra
: the foundation on which the rest of Qiskit liesaer
: provides high-performance simulator backendsignis
: provides code for users to easily generate circuits for specific experimentsaqua
: where algorithms for quantum computers are built
It is important to note that components like terra, which exist on Qiskit 0.46, have been deprecated in Qiskit 1.0.
Project Website
You can find the complete documentation on Qiskit on the IBM official Qiskit documentation website here: https://docs.quantum.ibm.com
License
Qiskit is released under the Apache License 2.0 specification.
Version
For ease of migration, LRZ supports the latest release versions: 0.46 and 1.0 with each requiring different setup approaches.
Supported HPC systems
SuperMUC-NG, Linux Clusters, Eviden Qaptiva
Installation
Following are instructions to install Qiskit on LRZ-supported HPC systems.
We recommend installing Qiskit in a Python virtual environment.
This allows you to separate Qiskit both from the main Python environment on your system and from other Python applications.
On SuperMUC-NG and Linux Cluster
Requirement
Qiskit is compatible with Python3; on SuperMUC-NG and the Linux Cluster it is necessary to load the corresponding module file.
The get the list of available Python modules type
module avail python
Then load the most updated Python module; usually, that is the default, so should be enough to run
module load python
Installing Qiskit
To install Qiskit, the following instructions are valid both for your local personal machine, LRZ flagship cluster SuperMUC-NG (SNG), and for the Linux Cluster. It is also important to pay attention to the version of Qiskit you intend to install because it is not easy to upgrade from Qiskit 0.46 to Qiskit 1.0. The best advice is to create a separate virtual environment for each installation to avoid conflicts.
WARNING: SNG requires access to internet to be provided by the user; to achieve this see LRZ documentation for possible methodologies.
# create the Python3 virtual environment python3 -m venv <path/to/virtual/environment> # Activate the virtual environment source <path/to/virtual/environment>/bin/activate # Install Qiskit from PyPi package manager pip3 install qiskit
This procedure will also install the terra
element, provided by the qiskit-terra
Python package.
Visualization
Additionally, Qiskit provides visualisation support, run the following if you intend to visualisation functionality or run Qiskit in Jupiter Notebooks; pay attention to the shell you are using:
# for bash users pip3 install qiskit[visualization]
If you use zsh
shell instead of bash
run the following
# for zsh users pip3 install 'qiskit[visualization]'
High-Performance Simulator Backends
In order to have access to high-performance simulator backends provided by the aer
element (see official documentation for a list),
the corresponding Python package has to be installed separately.
if you wish for the simulator to have access to GPU or MPI capabilities, you must build the package from the source, skip the following code box, and see the sections below.
pip3 install qiskit-aer
Acceleration on GPGPU
Such package provides simulators that can leverage on GPGPU to accelerate computation; depending on the CUDA Toolkit version available on the AI System you can install one of the following
Each of these two will overwrite your current qiskit-aer
package installation, giving you the same functionalities.
Parallelisation with MPI libraries
The qiskit-aer
can leverage also MPI libraries for accelerating the computation; in this case, the package has to be built from the source, see the official documentation for reference.
What follows is the procedure for SuperMUC-NG, which assumes you are still in the Python virtual environment created for qiskit
. Keep in mind that we are using the default-loaded modules for MPI and the mathematical library, see comments in the code below:
# default loaded # intel-mkl # intel-mpi # are already present, and need not to be loaded # load module files to satisfy dependencies module load cmake module load gcc # upgrade pip and install C++ Python bindings, # necessary to the build procedure python -m pip install --upgrade pip pip install pybind11 # clone qiskit-aer repo git clone https://github.com/Qiskit/qiskit-aer.git cd qiskit-aer # install required Python packages pip install -r requirements-dev.txt # build qiskit-aer with MPI support # we need to specify the CXX as gcc # since Intel compilers are not recognised # the C++ package manager used during build CXX=g++ python ./setup.py bdist_wheel -- -DAER_MPI=True # install Python wheel in virtual environment pip install --force-reinstall dist/qiskit_aer*.whl
On Eviden Qaptiva
On QLM/Qaptiva, there is a global installation of Qiskit 0.46 available in python3 and you don't need to install anything.
For Qiskit 1.0, we have made available a virtual environment globally. It can be activated with the command
source /opt/qiskit1.0-venv/bin/activate
Of course, should you require special packages, you can also install Qiskit 1.0 in your own virtual environment in userspace: https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0-installation
Example(s) for usage
2-qubits Bell-state
The following example simulates a 2-qubit Bell-state on SuperMUC-NG, using the Qasm simulator provided by the Aer element; the example is taken from the official documentation
import numpy as np # Import Qiskit from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister from qiskit import Aer, execute from qiskit.tools.visualization import plot_histogram, plot_state_city from qiskit.providers.aer import QasmSimulator # Construct quantum circuit circ = QuantumCircuit(2, 2) circ.h(0) circ.cx(0, 1) circ.measure([0,1], [0,1]) # Select the QasmSimulator from the Aer provider simulator = Aer.get_backend('qasm_simulator') # Execute and get counts result = execute(circ, simulator).result() counts = result.get_counts(circ) plot_histogram(counts, title='Bell-State counts', filename='bell-state-sim.png')
The following is a possible expected output
Testing Qiskit with Aer simulation supported by MPI
The following script measures the quantum volume; for it to run properly you have to install the `qiskit_algorithm` package in your Python virtual environment as follows
pip install qiskit-algorithms
from qiskit import * from qiskit.circuit.library import QuantumVolume from qiskit_aer import * from qiskit_algorithms.utils import algorithm_globals if __name__ == "__main__": consistent_seed_to_all_processes = 12345 algorithm_globals.random_seed = consistent_seed_to_all_processes qubits = 12 blockingQubits = qubits - 4 sim = AerSimulator(method="statevector", device="CPU", blocking_qubits=blockingQubits, blocking_enable=True) shots = 100 depth = 5 circuit = transpile( QuantumVolume(qubits, depth, seed=0), backend=sim, optimization_level=0 ) print(circuit) circuit.measure_all() job = sim.run(circuit, shots=shots) result = job.result() counts = result.get_counts() dic = result.to_dict() meta = dic["metadata"] myrank = meta["mpi_rank"] if (myrank == 0): print(f"This is my Rank: {myrank}") print(counts)