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许可证下分发的。包括整个许可证的副本 在仓库里。
为了使用此存储库中的工作,您必须引用(如许可证中所述):
- 作者:adrien suau(如果有任何疑问,请参见github页面或mail me)。
- CERFACS(欧洲科学中心)。