Package: qprof
qprofstands forquantumprofiler and aims at providing a
unique tool to profile quantum circuits.For the moment,qprofis able to understand quantum circuits generated withqiskitandmyQLMand can
generate profiling results only in agprof-compatible format.Installationqprofbeing a Python module, it is installable withpip.From Gitlabgitclonehttps://gitlab.com/qcomputing/qprof/qprof.gitpipinstallqprof/From PyPiqprofis now available on PyPi! To download and install the last version, just
typepipinstallqprofPlugins for library support are not installed by default in order to avoid pulling
silently huge dependencies likeqiskitin your project. In order to install the plugins
you can either do it afterwards with pip:pipinstallqprof_qiskit# other libraries are supportedor use the appropriate target when installingqprof:pipinstallqprof[qiskit]pipinstallqprof[myqlm]pipinstallqprof[all_plugins]For developersDevelopers might want to installqprofas an editable project.
To do so you need to clone the git repository and install the library in
editable mode with the-eoption:gitclonehttps://gitlab.com/qcomputing/qprof/qprof.gitpipinstall-eqprof/Note that the dependencies willnotbe installed in editable mode. If you want
all theqprofstack in editable mode, you need to clone and install everything
“by hand”:gitclonehttps://gitlab.com/qcomputing/qprof/qprof.gitgitclonehttps://gitlab.com/qcomputing/qprof/qprof_interfaces.git# Plugins?
# git clone https://gitlab.com/qcomputing/qprof/qprof_qiskit.gitpipinstall-eqprof_interfaces/pipinstall-eqprof/# Plugins?
# pip install -e qprof_qiskit/UsagePlugin organisationTheqproflibrary is organised as follow:A mainqproflibrary containing all the code related to computing routine
execution time, call graph, exporting, …Aqprof_interfacesplugin providing interfaces for the data structures used
byqprofto communicate with the plugins.Severalqprof_XXXlibraries that are used to adapt a libraryXXXtoqprofby implementing the interfaces ofqprof_interfaces.Plugins are automatically discovered the first timeqprof.frameworksis imported
and are arranged in a dictionary-like data-structure with the following structure:frameworks={"interfaces":<module'qprof_interfaces'from'[path]'>,# always present"plugin1":<module'qprof_plugin1'from'[path]'>,# ..."pluginN":<module'qprof_pluginN'from'[path]'>,}Plugins are lazy-imported, meaning that the plugin module is imported at the
first access to the dictionary key.ProfilingThe profiling is performed with theqprof.profilefunction.Theqprof.profilefunction 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 ofBaseExporter.Example of profiling:# Import the qprof toolsfromqprofimportprofile# Import the framework tools to generate a quantum routinefromqiskit.aqua.algorithmsimportGroverfromqiskit.aqua.components.oraclesimportLogicalExpressionOracle# 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 handgate_times={"U1":0,"U2":89,"U3":178,"CX":930,"BARRIER":0}# Profile the resulting quantum routine and use the "gprof" exporterqprof_out=profile(circuit,gate_times,"gprof")# Print to stdout the analysis reportprint(qprof_out)Full profiling exampleRequirements for the exampleYou should have thedottool installed on your machine, along with thegprof2dottool that can be installed
withpip install gprof2dot.Profile the codeLet save the code of the previous section in a fileprofile.py.You can generate the following graph with the commandpython3profile.py|gprof2dot|dot-Tpng-oprofiling_result.pngLimitationsqprofis not able to analyse recursive routine calls yet. If your quantum circuit
contains calls to recursive routines, expect the unexpected.Troubleshooting“Unknown” routines shows up in reportsIf “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 usinggprofoutput format are falseThegprofoutput 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, theqprof.exporters.GprofExportertakes an
optional parameterdefault_timein its constructor. Thisdefault_timewill be used to scale all the execution times such that the longest routine will
take exactlydefault_timeseconds on the report.By default, the value ofdefault_timeis 10 seconds. In order to change it
you need to instantiate the exporter yourself:fromqprofimportprofilefromqprof.exportersimportGprofExporterroutine=# ...gate_times=# ...exporter=GprofExporter(default_time=100)# 100 seconds for default_timeresult=profile(routine,gate_times,exporter)Note that givingNonetodefault_timewill disable the execution time
scaling.Who is usingqprof?Here is a list of projects usingqprof.If you usedqprofin your project and would like to appear in this list,
please let me know (open an issue, send me a mail, anything you want).QatHS