diff --git a/python/quantum-pecos/src/pecos/slr/gen_codes/gen_qasm.py b/python/quantum-pecos/src/pecos/slr/gen_codes/gen_qasm.py index 33f147246..69540c93a 100644 --- a/python/quantum-pecos/src/pecos/slr/gen_codes/gen_qasm.py +++ b/python/quantum-pecos/src/pecos/slr/gen_codes/gen_qasm.py @@ -247,38 +247,42 @@ def process_qgate(self, op): ) case "Prep": - op_str = self.qgate_qasm(op, "reset") + op_str = self.qgate_sq_qasm(op, "reset") case "T": - op_str = self.qgate_qasm(op, "rz(pi/4)") + op_str = self.qgate_sq_qasm(op, "rz(pi/4)") case "Tdg": - op_str = self.qgate_qasm(op, "rz(-pi/4)") + op_str = self.qgate_sq_qasm(op, "rz(-pi/4)") case "SX": - op_str = self.qgate_qasm(op, "rx(pi/2)") + op_str = self.qgate_sq_qasm(op, "rx(pi/2)") case "SY": - op_str = self.qgate_qasm(op, "ry(pi/2)") + op_str = self.qgate_sq_qasm(op, "ry(pi/2)") case "SZ": - op_str = self.qgate_qasm(op, "rz(pi/2)") + op_str = self.qgate_sq_qasm(op, "rz(pi/2)") case "SXdg": - op_str = self.qgate_qasm(op, "rx(-pi/2)") + op_str = self.qgate_sq_qasm(op, "rx(-pi/2)") case "SYdg": - op_str = self.qgate_qasm(op, "ry(-pi/2)") + op_str = self.qgate_sq_qasm(op, "ry(-pi/2)") case "SZdg": - op_str = self.qgate_qasm(op, "rz(-pi/2)") + op_str = self.qgate_sq_qasm(op, "rz(-pi/2)") case _: - op_str = self.qgate_qasm(op) + op_str = self.qgate_sq_qasm(op) return op_str - def qgate_qasm(self, op, repr_str: str | None = None): + def qgate_sq_qasm(self, op, repr_str: str | None = None): + if op.qsize != 1: + msg = "qgate_qasm only supports single qubit gates" + raise Exception(msg) + if repr_str is None: repr_str = op.sym.lower() @@ -288,20 +292,8 @@ def qgate_qasm(self, op, repr_str: str | None = None): str_list = [] - # TODO: Make sure this all works for different sized multi-qubit gates!!!!!!!!!!!!!!! <<<<<<<<<< - - if op.qsize > 1: - if not isinstance(op.qargs[0], tuple) and len(op.qargs) > 1: - op.qargs = (op.qargs,) - for q in op.qargs: if isinstance(q, QReg): - # Broadcasting across a qubit register is inconsistent with the current Permute - # strategy, so "unroll" broadcast operations to make them act on individual qubits. - # See, for example, https://github.com/PECOS-packages/PECOS/issues/95. - if op.qsize != 1: - msg = "Only single-qubit gates can be broadcast across a qubit register" - raise Exception(msg) lines = [f"{repr_str} {qubit};" for qubit in q] str_list.extend(lines) @@ -318,6 +310,10 @@ def qgate_qasm(self, op, repr_str: str | None = None): return "\n".join(str_list) def qgate_tq_qasm(self, op, repr_str: str | None = None): + if op.qsize != 2: + msg = "qgate_tq_qasm only supports single qubit gates" + raise Exception(msg) + if repr_str is None: repr_str = op.sym.lower()