Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
/qasm2imagePublic archive

A Python module to visualise quantum circuit

License

NotificationsYou must be signed in to change notification settings

nelimee/qasm2image

Repository files navigation

The qasm2image repository provides functions to represent quantum circuits written following theOpenQASM specification.

Installation

Dependencies

The tool and all the dependencies are available via the PIP tool. See the installation instructions below.

Installation procedure

pip3 install cffipip3 install qasm2image

Usage

In a Python environnement

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

In a shell environnement

A script is provided to change QASM code directly from the command line.

$ qasm2image -husage: qasm2image [-h] [-b BASIS] [--hide-clbits] [-s SCALE]                  input_file output_fileTransform a quantum circuitin 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 tooloptional arguments:  -h, --help            show thishelp message andexit  -b BASIS, --basis BASIS                        a comma-separated list of gate names which represent                        the gate basisin which the circuit will be decomposed  --hide-clbitsif present, classical bits will not be represented  -s SCALE, --scale SCALE                        scale of the PNG image. SVG output is not affected by                        this parameter

License

This project is distributed under theCeCILL-B license. A copy of the whole license is includedin the repository.

In order to use the work in this repository you have a strong obligation to cite (as stated in the license):

  1. The author of the work: Adrien Suau (see on my GitHub page ormail me if any doubt).

  2. The CERFACS (Centre Européen de Recherche et de Formation Avancée en Calcul Scientifique).

Output

adder.png

qft.png

inverseqft1.png

inverseqft2.png

qec.pngThe same QASM code, but with thehide-clbits option set:qasm2image --hide-clbits qec.{qasm,png}.qec_no_clbits.png

teleportv2.png

About

A Python module to visualise quantum circuit

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp