Skip to content

Commit

Permalink
wip: A stub to not forget the idea / PLY reading
Browse files Browse the repository at this point in the history
  • Loading branch information
rscircus committed Aug 22, 2024
1 parent 920ee2f commit f1f4288
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cirq-core/cirq/contrib/qasm_import/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import sympy
from ply import yacc

from cirq import ops, Circuit, NamedQubit, CX
from cirq import ops, Circuit, NamedQubit, CX, R
from cirq.circuits.qasm_output import QasmUGate
from cirq.contrib.qasm_import._lexer import QasmLexer
from cirq.contrib.qasm_import.exception import QasmException
Expand Down Expand Up @@ -303,8 +303,12 @@ def p_circuit_reg(self, p):
def p_circuit_gate_or_measurement_or_if(self, p):
"""circuit : circuit gate_op
| circuit measurement
| circuit if"""
self.circuit.append(p[2])
| circuit if
| circuit new_reg"""
if isinstance(p[2], list):
self.circuit.append(p[2])
else:
self.circuit.append([p[2]])
p[0] = self.circuit

def p_circuit_empty(self, p):
Expand All @@ -325,8 +329,22 @@ def p_new_reg(self, p):
self.qregs[name] = length
else:
self.cregs[name] = length
print("Calling qrags to create a qubit")
p[0] = (name, length)

# reset

# TODO: Model this kind of after measurement
def p_reset(self, p):
"""new_reg : RESET ID '[' NATURAL_NUMBER ']' ';'"""
name, idx = p[2], p[4]
if name not in self.qregs.keys():
raise QasmException(f"{name} is undefined at line {p.lineno(2)}")
if idx < 0 or idx >= self.qregs[name]:
raise QasmException(f"Illegal qubit index {idx} for register {name} at line {p.lineno(4)}")
p[0] = (name, idx)


# gate operations
# gate_op : ID qargs
# | ID ( params ) qargs
Expand Down

0 comments on commit f1f4288

Please sign in to comment.