Skip to main content

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

Installation

Dependencies

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

Installation procedure

pip3 install cffi
pip3 install qasm2image

Usage

In a Python environnement

# Import the functions
from qasm2image import qasm2svg
from qasm2image import qasm2png
# 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 circuit
basis = 'u1,u2,u3,U,cx'
# Compute the SVG representation
svg_str = qasm2svg(qasm_str, basis=basis, show_clbits=True)
# Compute the PNG representation
png_bytes = qasm2png(qasm_str, basis=basis, show_clbits=True)
# Types of the outputs
assert type(svg_str) is str
assert type(png_bytes) is bytes
# Write the result into files
with open('circuit.svg', 'w') as svg_file:
    svg_file.write(svg_str)
# Don't forget to write in *binary* mode for PNG
with open('circuit.png', 'wb') as png_file:
    png_file.write(png_bytes)

In a shell environnement

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

$ 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

License

This project is distributed under the CeCILL-B license. A copy of the whole license is included in 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 or mail me if any doubt).

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

Output

adder.qasm

adder.png

qft.qasm

qft.png

inverseqft1.qasm

inverseqft1.png

inverseqft2.qasm

inverseqft2.png

qec.qasm

qec.png

The same QASM code, but with the hide-clbits option set: qasm2image --hide-clbits qec.{qasm,png}.

qec\_no\_clbits.png

teleportv2.qasm

teleportv2.png

Metadata

Release files for qasm2image 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qasm2image 0.8.0
File Size Uploaded
qasm2image-0.8.0.tar.gz 27.5 kB Details

Release files / qasm2image-0.8.0.tar.gz

Download URL qasm2image-0.8.0.tar.gz
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
582c2aad99c0bd6e073dc2ad2225d07bc4c04017d7acfe19afa5bd69e79a85e7
BLAKE2b-256 checksum
How to use checksums
982cb83d975c729ce084d97cdedec5df5f2cecf1f61d122d56bd0d3c5d134b36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

0.8.0 This release

1 release file

0.7.0

2 release files

0.6.0

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page