Skip to content

Commit

Permalink
QASM string parsing bug (#298)
Browse files Browse the repository at this point in the history
Co-authored-by: Praveen Jayakumar <[email protected]>
  • Loading branch information
Praveen91299 and Praveen Jayakumar authored Jun 28, 2023
1 parent fb49a8a commit 3921b74
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/tequila/circuit/qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3921b74

Please sign in to comment.