Skip to content

Commit

Permalink
fix(phirgen): str->float for duration, bool->int for cop rhs
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Mar 8, 2024
1 parent 5d8ac2e commit c38f3ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions pytket/phir/phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> JsonDict | None:
out = {
"mop": "Idle",
"args": [arg_to_bit(qbit) for qbit in cmd.qubits],
"duration": (dur, "s"),
"duration": (float(dur), "s"),
}
case "order" | "group":
raise NotImplementedError(op.data)
Expand Down Expand Up @@ -299,7 +299,9 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> JsonDict | None:
if len(cmd.bits) != len(op.values):
logger.error("LHS and RHS lengths mismatch for classical assignment")
raise ValueError
out = assign_cop([arg_to_bit(bit) for bit in cmd.bits], op.values)
out = assign_cop(
[arg_to_bit(bit) for bit in cmd.bits], list(map(int, op.values))
)

case tk.CopyBitsOp():
if len(cmd.bits) != len(cmd.args) // 2:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_sleep_idle() -> None:
"""Ensure sleep from qasm gets converted to PHIR Idle Mop."""
circ = get_qasm_as_circuit(QasmFile.sleep)
phir = json.loads(pytket_to_phir(circ))
assert phir["ops"][7] == {"mop": "Idle", "args": [["q", 0]], "duration": ["1", "s"]}
assert phir["ops"][7] == {"mop": "Idle", "args": [["q", 0]], "duration": [1.0, "s"]}


def test_multiple_sleep() -> None:
Expand All @@ -148,5 +148,5 @@ def test_multiple_sleep() -> None:
"""
circ = circuit_from_qasm_str(qasm)
phir = json.loads(pytket_to_phir(circ))
assert phir["ops"][2] == {"mop": "Idle", "args": [["q", 0]], "duration": ["1", "s"]}
assert phir["ops"][4] == {"mop": "Idle", "args": [["q", 1]], "duration": ["2", "s"]}
assert phir["ops"][2] == {"mop": "Idle", "args": [["q", 0]], "duration": [1.0, "s"]}
assert phir["ops"][4] == {"mop": "Idle", "args": [["q", 1]], "duration": [2.0, "s"]}

0 comments on commit c38f3ea

Please sign in to comment.