RNG and Shot-Dependent Examples¶
These examples exercise Guppy features that are specifically aimed at Quantinuum hardware-oriented workflows.
The RNG and shot-dependent functions used here are only available on Quantinuum hardware targets, so these examples are not intended as portable Guppy programs for arbitrary QIR backends. Note that not all RNG methods are currently supported; see Support matrix.
Quantum RNG example¶
Source file: guppy_examples/quantinuum-hardware-only/rng-quantum-rng-1.py
from typing import no_type_check
from guppylang import guppy, qubit
from guppylang.std.builtins import result
from guppylang.std.qsystem.random import RNG
from guppylang.std.quantum import h, measure
@guppy
@no_type_check
def main() -> None:
q0 = qubit()
q1 = qubit()
h(q1)
h(q1)
r = RNG(11)
if r.random_int() == 5:
h(q1)
r.discard()
result("0", measure(q0))
result("1", measure(q1))
Bounded quantum RNG example¶
Source file: guppy_examples/quantinuum-hardware-only/rng-quantum-rng-2.py
from typing import no_type_check
from guppylang import guppy, qubit
from guppylang.std.builtins import result
from guppylang.std.qsystem.random import RNG
from guppylang.std.quantum import h, measure
@guppy
@no_type_check
def main() -> None:
q0 = qubit()
q1 = qubit()
h(q1)
h(q1)
r = RNG(11)
if r.random_int_bounded(100) == 5:
h(q1)
r.discard()
result("0", measure(q0))
result("1", measure(q1))
Shot-dependent example¶
Source file: guppy_examples/quantinuum-hardware-only/rng-quantum-jobid-1.py
from typing import no_type_check
from guppylang import guppy, qubit
from guppylang.std.builtins import result
from guppylang.std.qsystem.utils import get_current_shot
from guppylang.std.quantum import h, measure
@guppy
@no_type_check
def main() -> None:
q0 = qubit()
q1 = qubit()
h(q1)
h(q1)
if get_current_shot() == 5:
h(q1)
result("0", measure(q0))
result("1", measure(q1))