From 6e0c2bce37b207bcfac5bbb9217c3a7bab00da20 Mon Sep 17 00:00:00 2001 From: Kartik Singhal Date: Tue, 7 Nov 2023 10:09:37 -0600 Subject: [PATCH] fix(phirgen): ensure multi-qubit gates have correct arg count --- pytket/phir/phirgen.py | 43 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/pytket/phir/phirgen.py b/pytket/phir/phirgen.py index a96e365..c033e60 100644 --- a/pytket/phir/phirgen.py +++ b/pytket/phir/phirgen.py @@ -72,19 +72,52 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> dict[str, Any]: raise angles = (op.params, "pi") if op.params else None qop: dict[str, Any] - match op.type: - case tk.OpType.Measure: + match gate: + case "Measure": qop = { - "qop": "Measure", + "qop": gate, "returns": [arg_to_bit(cmd.bits[0])], "args": [arg_to_bit(cmd.args[0])], } - case _: # a regular quantum gate + case "R2XXYYZZ": # three-qubit gate + qop = { + "qop": gate, + "angles": angles, + "args": [ + [ + arg_to_bit(cmd.qubits[0]), + arg_to_bit(cmd.qubits[1]), + arg_to_bit(cmd.qubits[2]), + ] + ], + } + + case ( + "CX" + | "CY" + | "CZ" + | "RXX" + | "RYY" + | "RZZ" + | "SXX" + | "SXXdg" + | "SYY" + | "SYYdg" + | "SZZ" + | "SZZdg" + | "SWAP" + ): # two-qubit gates qop = { + "qop": gate, "angles": angles, + "args": [[arg_to_bit(cmd.qubits[0]), arg_to_bit(cmd.qubits[1])]], + } + case _: # single-qubit gates + qop = { "qop": gate, - "args": [arg_to_bit(qbit) for qbit in cmd.qubits], + "angles": angles, + "args": [arg_to_bit(cmd.qubits[0])], } return qop