Skip to main content

qprof

qprof stands for quantum profiler and aims at providing a unique tool to profile quantum circuits.

For the moment, qprof is able to understand quantum circuits generated with qiskit and myQLM and can generate profiling results in JSON and a gprof compatible format.

Installation

qprof being a Python module, it is installable with pip.

From Gitlab

git clone https://gitlab.com/qcomputing/qprof/qprof.git
pip install qprof/

From PyPi

qprof is now available on PyPi! To download and install the last version, just type

pip install qprof

Plugins for library support are not installed by default in order to avoid pulling silently huge dependencies like qiskit in your project. In order to install the plugins you can either do it afterwards with pip:

pip install qprof_qiskit  # other libraries are supported too

or use the appropriate target when installing qprof:

pip install qprof[qiskit]
pip install qprof[myqlm]
pip install qprof[all_plugins]

For developers

Developers might want to install qprof as an editable project. To do so you need to clone the git repository and install the library in editable mode with the -e option:

git clone https://gitlab.com/qcomputing/qprof/qprof.git
pip install -e qprof/

Note that the dependencies will not be installed in editable mode. If you want all the qprof stack in editable mode, you need to clone and install everything "by hand":

git clone https://gitlab.com/qcomputing/qprof/qprof.git
# Plugins?
# git clone https://gitlab.com/qcomputing/qprof/qprof_qiskit.git
# git clone https://gitlab.com/qcomputing/qprof/qprof_myqlm.git
pip install -e qprof/
# Plugins?
# pip install -e qprof_qiskit/
# pip install -e qprof_myqlm/

Usage

Plugin organisation

The qprof library is organised as follows:

  1. A main qprof library containing all the code related to computing routine execution time, call graph, exporting, ...
  2. A qprof.plugins.frameworks.interfaces plugin providing interfaces for the data structures used by qprof to communicate with the other plugins. This interfaces plugins is included in the main qprof package.
  3. Several qprof_XXX libraries that are used to adapt a library XXX to qprof by implementing the interfaces of qprof.plugins.frameworks.interfaces in qprof.plugins.frameworks.XXX.

Plugins are automatically discovered the first time qprof is imported and are arranged in a dictionary-like data-structure with the following structure:

frameworks = {
    "interfaces": <module 'qprof.plugins.frameworks.interfaces' from '[path]'>, # always present
    "plugin1": <module 'qprof.plugins.frameworks.plugin1' from '[path]'>,
    # ...
    "pluginN": <module 'qprof.plugins.frameworks.pluginN' from '[path]'>,
}

Plugins are lazy-imported, meaning that the plugin module is imported at the first access to the dictionary key.

Profiling

The profiling is performed with the qprof.profile function.

The qprof.profile function needs a quantum routine implemented with one of the supported frameworks along with the "base" gate times, provided as a dictionary, and an exporter, given either as a string or as an instance of BaseExporter.

Example of profiling:

# Import the qprof tools
from qprof import profile

# Import the framework tools to generate a quantum routine
from qiskit.aqua.algorithms import Grover
from qiskit.aqua.components.oracles import LogicalExpressionOracle


# Generate the routine to benchmark.
input_3sat = """
c example DIMACS-CNF 3-SAT
p cnf 3 5
-1 -2 -3 0
1 -2 3 0
1 2 -3 0
1 -2 -3 0
-1 2 3 0
"""

oracle = LogicalExpressionOracle(input_3sat)
grover = Grover(oracle)
circuit = grover.construct_circuit()

# Hard-coded gate times retrieved by hand
gate_times = {"U1": 0, "U2": 89, "U3": 178, "CX": 930, "BARRIER": 0}

# Profile the resulting quantum routine and use the "gprof" exporter
qprof_out = profile(circuit, gate_times, "gprof")

# Print to stdout the analysis report
print(qprof_out)

Full profiling example

Requirements for the example

You should have the dot tool installed on your machine, along with the gprof2dot tool that can be installed with pip install gprof2dot.

Profile the code

Let save the code of the previous section in a file profile.py.

You can generate the following graph with the command

python3 profile.py | gprof2dot -n 0 -e 0 | dot -Tpng -o profiling_result.png

image

Limitations

  • qprof is not able to analyse recursive routine calls yet. If your quantum circuit contains calls to recursive routines, expect the unexpected.

  • The call-graph analysis is done as if all the quantum gates were executed sequentially. Parallel execution support is a work in progress in the parallel_support branch. The main issue that still needs to be solved is the output format.

Troubleshooting

Unknown routines shows up in reports

If Unknown routines are showing up in the reports, check that you named correctly all the routines you defined.

If the problem is still present, open an issue.

Reported times using gprof output format are false

The gprof output format has a very limited precision of 10 milli-seconds when dealing with timings. This means that routines running in less than 5 milli-seconds will, due to rounding error, appear as taking 0 milli-seconds.

In order to circumvent this issue, the qprof.exporters.GprofExporter takes an optional parameter default_time in its constructor. This default_time will be used to scale all the execution times such that the longest routine will take exactly default_time seconds on the report.

By default, the value of default_time is 10 seconds. In order to change it you need to instantiate the exporter yourself:

from qprof import profile
from qprof.exporters import GprofExporter

routine = # ...
gate_times = # ...
exporter = GprofExporter(default_time=100) # 100 seconds for default_time

result = profile(routine, gate_times, exporter)

Note that giving None to default_time will disable the execution time scaling.

Who is using qprof?

Here is a list of projects using qprof.

If you used qprof in your project and would like to appear in this list, please let me know (open an issue, send me a mail, anything you want).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qprof-1.4.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qprof-1.4.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file qprof-1.4.1.tar.gz.

File metadata

  • Download URL: qprof-1.4.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qprof-1.4.1.tar.gz
Algorithm Hash digest
SHA256 01d9532ee09b827241c0aaf05607f17bf42f9cae123889c320361b46af4913d0
MD5 09e3b2a4d2681f60267e3a57efbf2d5b
BLAKE2b-256 20e9eb3c373821c6b21bcec634333da9fb631b1b9cc1aeb8f862ad6e3af1057e

See more details on using hashes here.

File details

Details for the file qprof-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: qprof-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qprof-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ab3af19f9e30e5a696cc662ee85f57b7a13c331e3340545b83b851a9e5d33cc
MD5 7315e74bb9bd88f3e7fa5e90a4dcdee9
BLAKE2b-256 c2d2d0b67f81683bfe11d130fc62c3ec9da1864163e5a60bf1af06a68a869679

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page