Skip to main content

qulacs-visualizer

CI Build and Deploy Documentation PyPI version MIT

qulacs-visualizer is a quantum circuit drawing library for qulacs. This library only supports Python. Not available in C/C++.

qulacs-visualizer supports the following methods.

Quick Install

Install using pip from PyPI:

pip install qulacsvis

Example

For more information, see the documentation. The documentation describes the other options available.

Text-Based Drawing

In text-based mode, draws the circuit as ASCII art. This mode is the default behavior.

from qulacs import QuantumCircuit
from qulacsvis import circuit_drawer

# Build a quantum circuit
circuit = QuantumCircuit(3)
circuit.add_X_gate(0)
circuit.add_Y_gate(1)
circuit.add_Z_gate(2)
circuit.add_dense_matrix_gate(
    [0, 1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]
)
circuit.add_CNOT_gate(2, 0)
circuit.add_X_gate(2)

# Draw a quantum circuit
circuit_drawer(circuit)
   ___     ___     ___
  | X |   |DeM|   |CX |
--|   |---|   |---|   |----------
  |___|   |   |   |___|
   ___    |   |     |
  | Y |   |   |     |
--|   |---|   |-----|------------
  |___|   |___|     |
   ___              |      ___
  | Z |             |     | X |
--|   |-------------●-----|   |--
  |___|                   |___|

Matplotlib Drawing

To use another drawing method, you can specify it by setting a value to the output_method argument of the circuit_drawer() function. For matplotlib drawing, set output_method="mpl".

import matplotlib.pyplot as plt

circuit_drawer(circuit, "mpl")
plt.show()

circuit_matplotlib_drawing.png

LaTeX Drawing

For LaTeX drawing, set output_method="latex".

circuit_drawer(circuit, "latex")

circuit_latex_drawing.png

If you want to output LaTeX code, set output_method="latex_source".

print(circuit_drawer(circuit, "latex_source"))
\documentclass[border={-2pt 5pt 5pt -7pt}]{standalone}
\usepackage[braket, qm]{qcircuit}
\usepackage{graphicx}

\begin{document}
    \Qcircuit @C=1.0em @R=0.7em @!R{ \\
        \nghost{ q_{0} : } & \lstick{ q_{0} : } & \gate{X} & \multigate{1}{DeM} & \targ & \qw & \qw\\
        \nghost{ q_{1} : } & \lstick{ q_{1} : } & \gate{Y} & \ghost{DeM} & \qw & \qw & \qw\\
        \nghost{ q_{2} : } & \lstick{ q_{2} : } & \gate{Z} & \qw & \ctrl{-2} & \gate{X} & \qw\\
    }
\end{document}

Requirement

If you want to use LaTeX Drawing, you need to have a local environment where you can run LaTeX (pdflatex). You will also need the qcircuit package. TeX Live and MiKTeX have the qcircuit package installed by default.

Save image to file

You can save the images you draw with matplotlib and LaTeX to a file.

# matplotlib
circuit_drawer(circuit, "mpl", filename="output.png")

# latex
circuit_drawer(circuit, "latex", filename="output.png")

License

MIT License

Contributors

We use qqcd for text-based drawing, a drawing library developed by @mf-22. Thank you.

Metadata

Release files for qulacsvis 0.7.7

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

Source distribution (sdist)

Source distribution for qulacsvis 0.7.7
File Size Uploaded Provenance Actions
qulacsvis-0.7.7.tar.gz 22.5 kB Without provenance Details for qulacsvis-0.7.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qulacsvis 0.7.7
File Interpreter ABI Platform Actions
qulacsvis-0.7.7-py3-none-any.whl Python 3 none any Details for qulacsvis-0.7.7-py3-none-any.whl

Total release size: 48.1 kB

Release files / qulacsvis-0.7.7.tar.gz

Download URL qulacsvis-0.7.7.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
20f24c77a9d205caccb34b14e25d674ce83dfde546689ab2f45c3d77cab8b3c5
BLAKE2b-256 checksum
How to use checksums
9e1a25c3d056705dd2aafbfd4bdfc8c716d6d7c24cead7cb11f0264ff4ad87eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.2 CPython/3.12.16 Linux/6.8.0-1073-azure

Release files / qulacsvis-0.7.7-py3-none-any.whl

Download URL qulacsvis-0.7.7-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1654b62189f49d973ed4dadb99e3b45efce5887cc333d769be23203ce1a484a
BLAKE2b-256 checksum
How to use checksums
532d1dd6cc9885326817b6cfb0e5c0f4e40a618aceeefef6538d7e29d15de0b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.2 CPython/3.12.16 Linux/6.8.0-1073-azure

Security for qulacsvis 0.7.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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