Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions guppylang-internals/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ dependencies = [
"hugr ~= 0.13.1",
]

[tool.uv.sources]
tket-exts = { git = "https://github.com/CQCL/tket2", subdirectory = "tket-exts", rev = "eed16e8" }
Comment thread
qartik marked this conversation as resolved.
Outdated

[project.optional-dependencies]
pytket = ["pytket>=1.34"]

Expand Down
10 changes: 10 additions & 0 deletions guppylang/src/guppylang/std/qsystem/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def random_int_bounded(self: "RNG", bound: int) -> int:
bound: The upper bound of the range, needs to less than 2^31.
"""

@hugr_op(external_op("RandomAdvance", [], ext=QSYSTEM_RANDOM_EXTENSION))
@no_type_check
def random_advance(self: "RNG", delta: int) -> None:
"""Advance or backtrack the RNG state by a given number of steps.

Args:
delta: Number of steps to move the RNG state forward (if positive)
or backward (if negative).
"""

@guppy
@no_type_check
def shuffle(self: "RNG", array: array[SHUFFLE_T, SHUFFLE_N]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ miette-py = { workspace = true }

# Uncomment these to test the latest dependency version during development
# hugr = { git = "https://github.com/CQCL/hugr", subdirectory = "hugr-py", rev = "50a2bac" }
# tket = { git = "https://github.com/CQCL/tket2", subdirectory = "tket-py", rev = "aca944c" }
selene-hugr-qis-compiler = { git = "https://github.com/CQCL/tket2", subdirectory = "qis-compiler", rev = "eed16e8" }
Comment thread
qartik marked this conversation as resolved.
Outdated

[build-system]
requires = ["hatchling"]
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/test_qsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ def test() -> tuple[int, float, int, int, angle, angle]:
validate(test.compile_function())


def test_random_advance(validate, run_int_fn): # type: ignore[no-untyped-def]
"""Validate behavior of random_advance from qsystem random extension."""

@guppy
def test() -> int:
rng = RNG(42)
rint_bnd1 = rng.random_int_bounded(100)
rng.random_advance(-1)
rint_bnd2 = rng.random_int_bounded(100)
same = rint_bnd1 == rint_bnd2
rng.discard()

return int(same)

validate(test.compile_function())
run_int_fn(test, 1)


def test_measure_leaked(validate): # type: ignore[no-untyped-def]
"""Compile the measure_leaked operation."""

Expand Down
48 changes: 15 additions & 33 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading