Skip to content

Commit

Permalink
feat: add get_current_shot() to qsystem module
Browse files Browse the repository at this point in the history
Closes: #798
  • Loading branch information
qartik committed Feb 12, 2025
1 parent 08dcae8 commit 7b92273
Show file tree
Hide file tree
Showing 7 changed files with 702 additions and 641 deletions.
7 changes: 3 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ To setup the environment manually you will need:

- Just: [just.systems](https://just.systems/)
- uv `>=0.4.27`: [docs.astral.sh](https://docs.astral.sh/uv/getting-started/installation/)
* If you have an older manually installed `uv` version you can upgrade it
with `uv self update`, or by following the instructions in your package
manager.
- If you have an older manually installed `uv` version you can upgrade it with `uv self update`,
or by following the instructions in your package manager.

The extended test suite has additional requirements. These are **optional**; tests that require them will be skipped if they are not installed.

Expand Down Expand Up @@ -108,7 +107,7 @@ PRs should be made against the `main` branch, and should pass all CI checks befo

The general format of a contribution title should be:

```
```text
<type>(<scope>)!: <description>
```

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ More examples and tutorials are available [here][examples].

[examples]: ./examples/


## Install

Guppy can be installed via `pip`. Requires Python >= 3.10.
Expand All @@ -49,13 +48,12 @@ Guppy can be installed via `pip`. Requires Python >= 3.10.
pip install guppylang
```


## Development

See [DEVELOPMENT.md](https://github.com/CQCL/guppylang/blob/main/DEVELOPMENT.md) for instructions on setting up the development environment.

## License

This project is licensed under Apache License, Version 2.0 ([LICENCE][] or http://www.apache.org/licenses/LICENSE-2.0).
This project is licensed under Apache License, Version 2.0 ([LICENCE][] or <http://www.apache.org/licenses/LICENSE-2.0>).

[LICENCE]: ./LICENCE
4 changes: 3 additions & 1 deletion guppylang/std/_internal/compiler/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from hugr import ext as he
from hugr import tys as ht
from hugr.std.float import FLOAT_T
from tket2_exts import futures, qsystem, quantum, result, rotation
from tket2_exts import futures, qsystem, quantum, result, rotation, utils

from guppylang.definition.custom import CustomInoutCallCompiler
from guppylang.definition.value import CallReturnWires
Expand All @@ -19,6 +19,7 @@

FUTURES_EXTENSION = futures()
QSYSTEM_EXTENSION = qsystem()
QSYSTEM_UTILS_EXTENSION = utils()
QUANTUM_EXTENSION = quantum()
RESULT_EXTENSION = result()
ROTATION_EXTENSION = rotation()
Expand All @@ -29,6 +30,7 @@
TKET2_EXTENSIONS = [
FUTURES_EXTENSION,
QSYSTEM_EXTENSION,
QSYSTEM_UTILS_EXTENSION,
QUANTUM_EXTENSION,
RESULT_EXTENSION,
ROTATION_EXTENSION,
Expand Down
10 changes: 9 additions & 1 deletion guppylang/std/qsystem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from guppylang.std import angles
from guppylang.std._internal.compiler.quantum import (
QSYSTEM_EXTENSION,
QSYSTEM_UTILS_EXTENSION,
InoutMeasureCompiler,
)
from guppylang.std._internal.util import quantum_op
from guppylang.std._internal.util import external_op, quantum_op
from guppylang.std.angles import angle
from guppylang.std.builtins import owned
from guppylang.std.quantum import qubit
Expand Down Expand Up @@ -73,6 +74,13 @@ def reset(q: qubit) -> None: ...
def qfree(q: qubit @ owned) -> None: ...


@guppy.hugr_op(
external_op("GetCurrentShot", [], ext=QSYSTEM_UTILS_EXTENSION), module=qsystem
)
@no_type_check
def get_current_shot() -> int: ...


# ------------------------------------------------------
# --------- Internal definitions -----------------------
# ------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ execute-llvm = { workspace = true }

# Uncomment these to test the latest dependency version during development
# hugr = { git = "https://github.com/CQCL/hugr", subdirectory = "hugr-py", rev = "e40b6c7" }
# tket2-exts = { git = "https://github.com/CQCL/tket2", subdirectory = "tket2-exts", rev = "eb7cc63"}
tket2-exts = { git = "https://github.com/CQCL/tket2", subdirectory = "tket2-exts", branch = "767-hseries-get_current_shot"}
# tket2 = { git = "https://github.com/CQCL/tket2", subdirectory = "tket2-py", rev = "eb7cc63"}


Expand Down Expand Up @@ -117,4 +117,4 @@ exclude_also = [


[tool.pytest.ini_options]
addopts = "--benchmark-skip" # bencharks run explicitly with `just bench`
addopts = "--benchmark-skip" # bencharks run explicitly with `just bench`
8 changes: 5 additions & 3 deletions tests/integration/test_qsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from guppylang.std.angles import angle

from guppylang.std.builtins import owned
from guppylang.std.qsystem import get_current_shot
from guppylang.std.quantum import qubit
from guppylang.std.qsystem.functional import (
phased_x,
Expand All @@ -18,7 +19,7 @@
)


def compile_qsystem_guppy(fn) -> ModulePointer:
def compile_qsystem_guppy(fn) -> ModulePointer: # type: ignore[no-untyped-def]
"""A decorator that combines @guppy with HUGR compilation.
Modified version of `tests.util.compile_guppy` that loads the qsytem module.
Expand All @@ -29,17 +30,18 @@ def compile_qsystem_guppy(fn) -> ModulePointer:
), "`@compile_qsystem_guppy` does not support extra arguments."

module = GuppyModule("module")
module.load(angle, qubit)
module.load(angle, qubit, get_current_shot) # type: ignore[arg-type]
module.load_all(qsystem_functional)
guppylang.decorator.guppy(module)(fn)
return module.compile()


def test_qsystem(validate):
def test_qsystem(validate): # type: ignore[no-untyped-def]
"""Compile various operations from the qsystem extension."""

@compile_qsystem_guppy
def test(q1: qubit @ owned, q2: qubit @ owned, a1: angle) -> bool:
shot = get_current_shot()
q1 = phased_x(q1, a1, a1)
q1, q2 = zz_phase(q1, q2, a1)
q1 = rz(q1, a1)
Expand Down
Loading

0 comments on commit 7b92273

Please sign in to comment.