Skip to content

A Python library that converts Quantum circuit code to LaTeX quantikz circuit diagrams.

License

Notifications You must be signed in to change notification settings

madhavan-raja/py2quantikz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 give you

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]")

About

A Python library that converts Quantum circuit code to LaTeX quantikz circuit diagrams.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages