Skip to content

Commit

Permalink
fix(phirgen): emit barrier instructions as well
Browse files Browse the repository at this point in the history
Should fix https://github.com/CQCL/phir/issues/53

Requires CQCL/phir#56

Also requires support for barrier instructions in pecos
  • Loading branch information
qartik committed Jan 30, 2024
1 parent 35ae2cb commit 88db813
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pytket/phir/phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> JsonDict | None:
out: JsonDict | None = None
match op: # non-quantum op
case tk.BarrierOp():
# TODO(kartik): confirm with Ciaran/spec
# https://github.com/CQCL/phir/blob/main/spec.md
logger.debug("Skipping Barrier instruction")
out = {"meta": "barrier", "args": [arg_to_bit(arg) for arg in cmd.args]}

case tk.Conditional(): # where the condition is equality check
out = {
Expand Down
15 changes: 11 additions & 4 deletions tests/test_parallelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def test_single_qubit_circuit_with_parallel() -> None:
# for example Ry gets converted to R1XY
# compare angles and args instead

ops = (3, 5, 7, 11, 13, 15)
ops = (3, 5, 7, 12, 14, 16)

assert phir_with_parallel_phirgen["ops"][9] == {
"meta": "barrier",
"args": [["q", 0]],
}

for i, qop in zip(ops, ("R1XY", "RZ", "R1XY", "R1XY", "RZ", "R1XY"), strict=True):
assert phir_with_parallel_phirgen["ops"][i]["qop"] == qop
Expand All @@ -108,18 +113,20 @@ def test_single_qubit_circuit_with_parallel() -> None:
def test_two_qubit_exec_order_preserved() -> None:
"""Test that the order of gating in preserved in a 2 qubit circuit."""
phir = get_phir_json(QasmFile.exec_order_two_qubits, rebase=True)

assert phir["ops"][16] == {"meta": "barrier", "args": [["q", 0], ["q", 1]]}
# for this test, verify that the RX gates are NOT parallelized
# in the following section of the qasm file (lines 11-13):
# rx(3.5*pi) q[0];
assert phir["ops"][18] == {
assert phir["ops"][19] == {
"qop": "R1XY",
"angles": [[3.5, 0.0], "pi"],
"args": [["q", 0]],
}
# rz(3.5*pi) q[1];
assert phir["ops"][20] == {"qop": "RZ", "angles": [[3.5], "pi"], "args": [["q", 1]]}
assert phir["ops"][21] == {"qop": "RZ", "angles": [[3.5], "pi"], "args": [["q", 1]]}
# rx(1.0*pi) q[1];
assert phir["ops"][24] == {
assert phir["ops"][25] == {
"qop": "R1XY",
"angles": [[1.0, 0.0], "pi"],
"args": [["q", 1]],
Expand Down

0 comments on commit 88db813

Please sign in to comment.