Skip to content

Commit

Permalink
added debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Guggemos committed Apr 18, 2024
1 parent 3be1974 commit 0c4e0cb
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions scripts/translate_qasm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import base64

import pyzx as zx
Expand All @@ -10,8 +11,6 @@
import json


#matplotlib.use('TkAgg')

class QASMRunnerException(Exception):
"""Raised during parsing the QASM Input
Attributes:
Expand Down Expand Up @@ -43,7 +42,18 @@ def exit(data, warnings, errors):
data = []
try:
try:
qasm = base64.b64decode(sys.argv[1]).decode()
parser = argparse.ArgumentParser(
prog='qasm-runner',
description='This Program takes a base 64 encoded qasm string as input and outputs a photonic circuit',
epilog='Some epilog')
parser.add_argument('qasm') # positional argument
parser.add_argument('-d', '--debug', action=argparse.BooleanOptionalAction) # option that sets debug mode on
args = parser.parse_args()
qasm = base64.b64decode(args.qasm).decode()

if args.debug:
matplotlib.use('TkAgg')

except IndexError:
raise QASMRunnerException("Empty argument. Valid QASM2.0 is needed")

Expand Down Expand Up @@ -78,7 +88,8 @@ def exit(data, warnings, errors):
plt = zx.draw_matplotlib(graph_state)
f = io.BytesIO()
plt.savefig(f, format="svg")
plt.savefig("resource_state.svg", format="svg")
if args.debug:
plt.savefig("resource_state.svg", format="svg")
output["data"].append({
"name": "Resource State",
"mime_type": "image/svg+xml",
Expand All @@ -101,7 +112,8 @@ def exit(data, warnings, errors):
plt = zx.draw_matplotlib(o_graph_state)
f = io.BytesIO()
plt.savefig(f, format="svg")
plt.savefig("optimized_resource_state.svg", format="svg")
if args.debug:
plt.savefig("optimized_resource_state.svg", format="svg")
output["data"].append({
"name": "Optimized Resource State",
"mime_type": "image/svg+xml",
Expand All @@ -120,7 +132,8 @@ def exit(data, warnings, errors):
plt = zx.draw_matplotlib(zx_graph)
f = io.BytesIO()
plt.savefig(f, format="svg")
plt.savefig("m_pattern.svg", format="svg")
if args.debug:
plt.savefig("m_pattern.svg", format="svg")

output["data"].append({
"name": "Measurement Pattern",
Expand Down

0 comments on commit 0c4e0cb

Please sign in to comment.