Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(phirgen): don't rely on args when qubits carries correct info #155

Merged
Merged
Show file tree
Hide file tree
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
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]]}],
}