qiboteam / qibojit-benchmarks

Benchmark code for qibojit performance accessment
Apache License 2.0
2 stars 3 forks source link
benchmarks quantum-computing

Benchmarking quantum simulation

This repository contains benchmark scripts for quantum circuit simulation using Qibo and multiple simulation engines.

Installing prerequisites

In order to run the benchmarks, you need to install the required libraries.

In order to set up an environment with most of the libraries available in this repository, you can set up a conda environment:

    conda env create -f environment.yml

This recipe doesn't include the installation of CUDA Toolkit, CuPy, cuQuantum nor HybridQ, Qulacs-GPU, qsim GPU and TensorFlow Quantum.

Supported simulation backends

For more details check the documentation here.

Running the benchmarks

The script in benchmarks/main.py executes the benchmark code following the supported configuration flags (check python main.py -h):

$ python main.py -h

usage: main.py [-h] [--nqubits NQUBITS] [--backend BACKEND]
               [--platform PLATFORM] [--circuit CIRCUIT]
               [--circuit-options CIRCUIT_OPTIONS] [--nreps NREPS]
               [--nshots NSHOTS] [--transfer] [--precision PRECISION]
               [--memory MEMORY] [--threading THREADING] [--filename FILENAME]

optional arguments:
  -h, --help            show this help message and exit
  --nqubits NQUBITS     Number of qubits in the circuit.
  --backend BACKEND     Qibo backend to use for simulation.
  --platform PLATFORM   Qibo platform to use for simulation.
  --circuit CIRCUIT     Type of circuit to use. See README for the list of
                        available circuits.
  --circuit-options CIRCUIT_OPTIONS
                        String with options for circuit creation. It should
                        have the form 'arg1=value1,arg2=value2,...'. See
                        README for the list of arguments that are available
                        for each circuit.
  --nreps NREPS         Number of repetitions of the circuit execution. Dry
                        run is not included.
  --nshots NSHOTS       Number of measurement shots. If used the time required
                        to measure frequencies (no samples) is measured and
                        logged. If it is ``None`` no measurements are
                        performed.
  --transfer            If used the final state array is converted to numpy.
                        If the simulation device is GPU this requires a
                        transfer from GPU memory to CPU.
  --precision PRECISION
                        Numerical precision of the simulation. Choose between
                        'double' and 'single'.
  --memory MEMORY       Limit the GPU memory usage when using Tensorflow based
                        backends. The memory limit should be given in MB.
                        Tensorflow reserves the full available memory by
                        default.
  --threading THREADING
                        Switches the numba threading layer when using the
                        qibojit backend on CPU. See
                        https://numba.pydata.org/numba-
                        doc/latest/user/threading-layer.html#selecting-a-
                        named-threading-layer for a list of available
                        threading layers.
  --filename FILENAME   Directory of file to save the logs in json format. If
                        not given the logs will only be printed and not saved.

Before executing the code keep in mind the following:

The scripts/ folder contains example bash scripts that execute circuit benchmarks for different numbers of qubits. We refer to the README inside this folder for more details.

Comparing simulation libraries

In addition to the above main.py benchmark, we provide the compare.py benchmark for comparing the performance of different simulation libraries. The usage is similar to main.py with the --backend flag replaced by the --library flag which can be used to select one of the available quantum simulation libraries (check python compare.py -h).

$ python compare.py -h

usage: compare.py [-h] [--nqubits NQUBITS] [--library LIBRARY] [--library-options LIBRARY_OPTIONS] [--circuit CIRCUIT] [--circuit-options CIRCUIT_OPTIONS] [--precision PRECISION] [--nreps NREPS]
                  [--filename FILENAME]

optional arguments:
  -h, --help            show this help message and exit
  --nqubits NQUBITS     Number of qubits in the circuit.
  --library LIBRARY     Quantum simulation library to use in benchmark. See README for the list of available libraries.
  --library-options LIBRARY_OPTIONS
                        String with options for the library. It should have the form 'arg1=value1,arg2=value2,...'. Each library supports different options.
  --circuit CIRCUIT     Type of circuit to use. See README for the list of available circuits.
  --circuit-options CIRCUIT_OPTIONS
                        String with options for circuit creation. It should have the form 'arg1=value1,arg2=value2,...'. See README for the list of arguments that are available for each circuit.
  --precision PRECISION
                        Numerical precision of the simulation. Choose between 'double' and 'single'.
  --nreps NREPS         Number of repetitions of the circuit execution. Dry run is not included.
  --filename FILENAME   Directory of file to save the logs in json format. If not given the logs will only be printed and not saved.

Currently the available libraries (defined under benchmarks/libraries) are:

All the circuits described below are available for both main.py and compare.py.

Benchmark output

The benchmark script prints a summary of the circuit and user selected flags together with:

Note that if a GPU is used for simulation then transfer times measure the time required to copy the final state from the GPU memory to CPU.

If --filename is given the above logs are saved in json format in the given directory.

Implemented circuits

Here is a list of the available circuits for benchmarks. As described above the circuit should be selected using the --circuit flag and one of the following circuit names. Additional options can be passed using the --options flag. The options supported by each circuit are analyzed below. Note that some circuits require additional Python libraries to work as stated below.