openqasm可视化工具

qasm2image的Python项目详细描述


qasm2image存储库提供了表示按照OpenQASM规范编写的量子电路的函数。

安装

依赖性

工具和所有依赖项都可以通过pip工具获得。请参阅下面的安装说明。

安装程序

pip3 install cffi
pip3 install qasm2image

用法

在python环境中

# Import the functionsfromqasm2imageimportqasm2svgfromqasm2imageimportqasm2png# Generate your QASM string (either read from a file or generate a circuit and ask for its QASM).qasm_str="..."# Define the basis used to represent the circuitbasis='u1,u2,u3,U,cx'# Compute the SVG representationsvg_str=qasm2svg(qasm_str,basis=basis,show_clbits=True)# Compute the PNG representationpng_bytes=qasm2png(qasm_str,basis=basis,show_clbits=True)# Types of the outputsasserttype(svg_str)isstrasserttype(png_bytes)isbytes# Write the result into fileswithopen('circuit.svg','w')assvg_file:svg_file.write(svg_str)# Don't forget to write in *binary* mode for PNGwithopen('circuit.png','wb')aspng_file:png_file.write(png_bytes)

在外壳环境中

提供了一个脚本,可以直接从命令行更改qasm代码。

$ qasm2image -h
usage: qasm2image [-h][-b BASIS][--hide-clbits][-s SCALE]
                  input_file output_file

Transform a quantum circuit in QASM format to an image format.

positional arguments:
  input_file            the QASM file implementing the circuit to transform
  output_file           the image file that will be generated by the tool

optional arguments:
  -h, --help            show this help message and exit
  -b BASIS, --basis BASIS
                        a comma-separated list of gate names which represent
                        the gate basis in which the circuit will be decomposed
  --hide-clbits         if present, classical bits will not be represented
  -s SCALE, --scale SCALE
                        scale of the PNG image. SVG output is not affected by
                        this parameter

许可证

此项目是在CeCILL-B许可证下分发的。包括整个许可证的副本 在仓库里。

为了使用此存储库中的工作,您必须引用(如许可证中所述):

  1. 作者:adrien suau(如果有任何疑问,请参见github页面或mail me)。
  2. CERFACS(欧洲科学中心)。

输出

qec.qasm

qec.png

相同的qasm代码,但是设置了hide-clbits选项:qasm2image --hide-clbitsqec.{qasm,png}

qec\_no\_clbits.png

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

推荐PyPI第三方库


热门话题
java什么类似于安卓中iOS的VOIP推送和呼叫工具包,用于呼叫   java广播接收器第二次不工作   从maven本地导入java   java如何在jdbc中执行oracle过程   java单击按钮时如何更改JButton上的图像?   java Univocity如何将3(n)行解析为一行(bean)   java消除了字符串中出现的所有特定模式   javascript为什么Js不能从我的web服务目录加载图像文件?   pdf如何在没有AdobeAcrobat的情况下在Java中自动创建字段   反思如何以编程方式创建java文件   AmazonWeb服务java。木卫一。IOException:尝试读取aws s3存储桶上的关闭流   java如何在kotlin中映射基于升序的数组列表和排序   java执行一个方法的时间片段出现   不使用'synchronized'关键字的java线程安全代码?   使用Java小程序在浏览器中滚动至顶部   避免“ZLIB输入流意外结束”的java计时要求