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

Uploaded Source

Supported by

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