Skip to content

Commit

Permalink
fix(phirgen): don't rely on args when qubits carries correct info (
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik authored Mar 27, 2024
1 parent 7489191 commit 50fa4e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytket/phir/phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]}],
}

0 comments on commit 50fa4e3

Please sign in to comment.