Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions python/quantum-pecos/src/pecos/slr/gen_codes/gen_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)

Expand All @@ -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()

Expand Down
Loading