Skip to content

Commit

Permalink
feat(phirgen): add support for Sleep/Idle mop
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Mar 4, 2024
1 parent 2c15ecd commit fe34177
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: debug-statements

- repo: https://github.com/crate-ci/typos
rev: v1.18.2
rev: v1.19.0
hooks:
- id: typos

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"phir>=0.3.0",
"phir>=0.3.1",
"pytket>=1.21.0",
"wasmtime>=15.0.0",
]
Expand Down
13 changes: 12 additions & 1 deletion pytket/phir/phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,18 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> JsonDict | None:
out: JsonDict | None = None
match op: # non-quantum op
case tk.BarrierOp():
out = {"meta": "barrier", "args": [arg_to_bit(qbit) for qbit in cmd.qubits]}
if "sleep" in op.data:
dur = op.data.removeprefix("sleep(").removesuffix(")")
out = {
"mop": "Idle",
"args": [arg_to_bit(qbit) for qbit in cmd.qubits],
"duration": (dur, "s"),
}
else:
out = {
"meta": "barrier",
"args": [arg_to_bit(qbit) for qbit in cmd.qubits],
}

case tk.Conditional(): # where the condition is equality check
out = {
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build==1.0.3
build==1.1.1
mypy==1.8.0
networkx==2.8.8
phir==0.3.0
phir==0.3.1
pre-commit==3.6.2
pydata_sphinx_theme==0.15.2
pytest==8.0.2
Expand All @@ -10,5 +10,5 @@ pytket==1.25.0
ruff==0.2.2
setuptools_scm==8.0.4
sphinx==7.2.6
wasmtime==18.0.0
wasmtime==18.0.2
wheel==0.42.0
17 changes: 17 additions & 0 deletions tests/data/qasm/sleep.qasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OPENQASM 2.0;
include "hqslib1_dev.inc";

qreg q[1];
creg c[1];

rx(pi/2) q[0];

barrier q[0];
sleep(1) q[0];
barrier q[0];

rx(-pi/2) q[0];

barrier q[0];

measure q -> c;
7 changes: 7 additions & 0 deletions tests/test_phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ def test_global_phase() -> None:

phir = json.loads(pytket_to_phir(circ))
assert phir["ops"][-7]["true_branch"] == [{"mop": "Skip"}]


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"]}
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class QasmFile(Enum):
cond_barrier = auto()
arbitrary_qreg_names = auto()
group_ordering = auto()
sleep = auto()


class WatFile(Enum):
Expand Down

0 comments on commit fe34177

Please sign in to comment.