量子电路分析工具。

qprof的Python项目详细描述


qprof代表quantumprofiler,旨在提供一个 描述量子电路的独特工具。在

目前,qprof能够理解由 qiskit和{a2}和can 仅在 gprof-兼容格式。在

安装

qprof是一个Python模块,可以使用pip进行安装。在

来自Gitlab

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

从PyPi

qprof现在在PyPi上可用!要下载并安装最新版本,只需 类型

^{pr2}$

默认情况下不安装库支持插件,以避免拉入 在您的项目中静默地大量依赖,如qiskit。为了安装插件 您可以在之后使用pip执行此操作:

pip install qprof_qiskit  # other libraries are supported

或者在安装qprof时使用适当的目标:

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

对于开发者

开发人员可能希望将qprof安装为可编辑项目。 为此,您需要克隆git存储库并在中安装库 带有-e选项的可编辑模式:

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

请注意,依赖项将以可编辑模式安装not。如果你想的话 所有在可编辑模式下的qprof堆栈,您需要克隆并安装所有内容 “手工”:

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

使用

插件组织

qprof库的组织如下:

  1. qprof库,包含与计算例程相关的所有代码 执行时间,调用图,导出
  2. 一个为使用的数据结构提供接口的qprof_interfaces插件 通过qprof与插件通信。在
  3. 几个qprof_XXX库,用于将库XXX改编为 qprof,实现qprof_interfaces的接口。在

{tt18是第一次自动发现的插件 并以类似字典的数据结构排列,其结构如下:

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

插件是延迟导入的,这意味着插件模块是在 首次访问字典密钥。在

分析

分析是用qprof.profile函数执行的。在

qprof.profile函数需要使用 支持的框架以及作为字典提供的“基本”门时间,以及 导出器,以字符串或BaseExporter的实例给出。在

分析示例:

# 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)

完整分析示例

示例要求

您应该在您的机器上安装dot工具,以及 gprof2dot可以安装的工具 使用pip install gprof2dot。在

分析代码

让我们将上一节的代码保存在一个文件中配置文件.py。在

您可以使用命令生成以下图形

python3 profile.py | gprof2dot | dot -Tpng -o profiling_result.png
docs/images/profile_result.png

局限性

  • qprof还无法分析递归例程调用。如果你的量子电路 包含对递归例程的调用,但意外情况除外。在

故障排除

“未知”例程显示在报告中

如果“未知”例程出现在报告中,请检查您命名的 你定义的所有程序都是正确的。在

如果问题仍然存在,请打开问题。在

使用gprofoutput格式的报告时间为false

当 处理时间安排。这意味着例程运行时间不到5毫秒 由于取0,将出现毫秒取整错误。在

为了避免这个问题,qprof.exporters.GprofExporter接受一个 可选参数default_time在其构造函数中。这个default_time 将用于sca减少所有执行时间,这样最长的例程将 在报告上花费正好default_time秒。在

默认情况下,default_time的值为10秒。为了改变它 您需要自己实例化导出器:

注意,给Nonedefault_time将禁用执行时间 缩放比例。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java这算是人工智能吗?   java@OnDelete(级联)不处理双向映射(hibernate)   java我怎样才能在基元类型(int)上修复这个等式   java如何初始化PrintWriter数组?   arraylist如何使用java添加敌人   java如何处理2019年的背景地理围栏?   java是否有一个XPath表达式可用于在CDATA区域中导航XML?   Kotlin(Android Studio)中的java选项卡式活动   安卓 java。lang.IllegalArgumentException:provider=网络   广播控制流和主流的java排序   java Apache Nifi无法启动Nifi实例   java我正在尝试将内容作为字符串放入ListView   java阻止mozilla会话还原   java在春季选择引用哪个bean?