Skip to main content

Converts Quantum Circuit Code to quantikz Diagrams

Project description

py2quantikz

A library to convert Quantum code to LaTeX quantikz circuit diagrams.

Installation

Install using pip:

pip install py2quantikz

Usage

Initialize a circuit using QuantumCircuit() and pass in the number of qubits in the system.

Use the apply() method of QuantumCircuit to pass in a GateApplication or a list of GateApplication to it.

Get the circuit diagram code with the quantikz() method of QuantumCircuit.

from py2quantikz.py2quantikz import QuantumCircuit, GateApplication as ga
import py2quantikz.gates as qg

circuit = QuantumCircuit(4)

circuit.apply([ga(qg.H, 0), ga(qg.H, 2)])
circuit.apply([ga(qg.X, 1, 0), ga(qg.X, 3, 2)])
circuit.apply([ga(qg.M, 0), ga(qg.M, 2)])

quantikz_repr = circuit.quantikz()
print(quantikz_repr)

This will result in

Q_0 & \gate{H} & \ctrl{1} & \meter{} & \\
Q_1 &          & \gate{X} &          & \\
Q_2 & \gate{H} & \ctrl{1} & \meter{} & \\
Q_3 &          & \gate{X} &          & \\

The quantikz() method accepts a separation parameter sep, which is used to separate the individual circuit elements.

circuit.quantikz(sep="&[0.5em]")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2quantikz-0.0.3.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file py2quantikz-0.0.3.tar.gz.

File metadata

  • Download URL: py2quantikz-0.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for py2quantikz-0.0.3.tar.gz
Algorithm Hash digest
SHA256 82f94412a3be0a19b5974db6f10fc53f7b016a6a63e0f0b92bf1751bacbf29b9
MD5 680713ee789609fb5cb9d7b581c8a2d9
BLAKE2b-256 80148984936b19041310b214e6ac718aa68463c2d37985dd5c9e6c45c68df57a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page