From 50fa4e31303f21ac2123cb4077cf9deaedcc611f Mon Sep 17 00:00:00 2001 From: Kartik Singhal Date: Wed, 27 Mar 2024 13:48:00 -0600 Subject: [PATCH] fix(phirgen): don't rely on `args` when `qubits` carries correct info (#155) --- pytket/phir/phirgen.py | 2 +- tests/test_phirgen.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pytket/phir/phirgen.py b/pytket/phir/phirgen.py index 0ab6cd4..de76eaa 100644 --- a/pytket/phir/phirgen.py +++ b/pytket/phir/phirgen.py @@ -187,7 +187,7 @@ def convert_gate(op: tk.Op, cmd: tk.Command) -> JsonDict | None: qop = { "qop": gate, "returns": [arg_to_bit(cmd.bits[0])], - "args": [arg_to_bit(cmd.args[0])], + "args": [arg_to_bit(cmd.qubits[0])], } case ("CX" | "CY" diff --git a/tests/test_phirgen.py b/tests/test_phirgen.py index 758f82a..6002a07 100644 --- a/tests/test_phirgen.py +++ b/tests/test_phirgen.py @@ -174,3 +174,17 @@ def test_reordering_classical_conditional() -> None: "condition": {"args": [["ctrl", 0], 1], "cop": "=="}, "true_branch": [{"angles": None, "args": [["q", 0]], "qop": "X"}], } + + +def test_conditional_measure() -> None: + """From https://github.com/CQCL/pytket-phir/issues/154 .""" + c = Circuit(2, 2) + c.H(0).H(1) + c.Measure(0, 0) + c.Measure(1, 1, condition_bits=[0], condition_value=1) + phir = json.loads(pytket_to_phir(c)) + assert phir["ops"][-1] == { + "block": "if", + "condition": {"cop": "==", "args": [["c", 0], 1]}, + "true_branch": [{"qop": "Measure", "returns": [["c", 1]], "args": [["q", 1]]}], + }