Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions guppylang/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ classifiers = [

dependencies = [
"guppylang-internals ~= 0.24.0",
"selene-sim~=0.2.3",
"selene-hugr-qis-compiler~=0.2.8",
"numpy~=2.0",
"selene-hugr-qis-compiler~=0.2.8",
"selene-sim~=0.2.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just sorting

"tqdm>=4.67.1",
"types-tqdm>=4.67.0.20250809",
]
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ 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 = "e704c19" }

[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
Loading