From 3921b745f58f2baeb5c8eab2a7b7a99429110c7c Mon Sep 17 00:00:00 2001 From: Praveen Jayakumar Date: Wed, 28 Jun 2023 09:07:44 -0400 Subject: [PATCH] QASM string parsing bug (#298) Co-authored-by: Praveen Jayakumar --- src/tequila/circuit/qasm.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index ef519dc0..65878f76 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -402,16 +402,21 @@ def get_angle(name: str) -> list: raise TequilaException("Invalid specification {}".format(name)) angle = angle.replace('pi', '') try: + sign = 1 + div = 1 + if angle.find('-') != -1: + angle = angle.replace('-', '') + sign = -1 + if angle.find('/') != -1: + div = float(angle[angle.index('/')+1:]) + angle = angle[:angle.index('/')] if angle.find('*') != -1: angle = angle.replace('*', '') - phase = float(angle) * pi - elif angle.find('/') != -1: - angle = angle.replace('/', '') - phase = pi / float(angle) + phase = sign * float(angle) * pi / div elif len(angle) == 0: - phase = pi + phase = sign * pi / div else: - phase = float(angle) + phase = sign * float(angle) / div except ValueError: raise TequilaException("Invalid specification {}".format(name)) angles.append(phase)