Skip to content

Commit

Permalink
Added script to convert circuit file into tikz file
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdwetering committed Feb 3, 2019
1 parent b3b7105 commit e052b33
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions scripts/circ2tikz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import sys
sys.path.append('.')
import pyzx as zx

def to_tikz(source, target):
circ = zx.Circuit.load(source)
print("Converting circuit with {:d} gates to TikZ".format(len(circ.gates)))
g = circ.to_graph()
zx.simplify.id_simp(g,quiet=True)
tikz = zx.drawing.to_tikz(g)
print("Output file: ", os.path.abspath(target))
f = open(target, 'w')
f.write(tikz)
f.close()

helpstring = """usage: circ2tikz source [dest]
Script for converting circuits into tikz files.
Arguments:
source: File containing circuit
dest: Desired output location for TikZ file
The default value for dest is to put a .tikz file of the same name in the folder of source.
"""

if __name__ == '__main__':
arguments = sys.argv[1:]
if not arguments:
print(helpstring)
elif len(arguments) == 1:
source = arguments[0]
if not os.path.exists(source):
print("File '{}' does not exist".format(source))
else:
basename = os.path.splitext(source)[0]
target = basename+".tikz"
to_tikz(source, target)
else:
source = arguments[0]
target = arguments[1]
to_tikz(source, target)

0 comments on commit e052b33

Please sign in to comment.