Write code that reads like the problem you’re solving. Guppy’s syntax is clear, concise, and flexible enough to capture complex quantum and classical logic without unnecessary boilerplate.
Guppy’s type system catches costly mistakes before they happen — including quantum-specific hazards.
If you can read Python, you can read Guppy. Its design is inspired by Python’s readability and simplicity, making it easy to learn. Guppy also lives inside Python, allowing seamless inter-op.
from guppylang import guppy
from guppylang.std.quantum import qubit, toffoli, s, measure
from guppylang.std.quantum.functional import h
@guppy
def repeat_until_success(q: qubit, attempts: int) -> bool:
"""
Repeat-until-success circuit for Rz(acos(3/5))
from Nielsen and Chuang, Fig. 4.17.
"""
for i in range(attempts):
a, b = h(qubit()), h(qubit())
toffoli(a, b, q)
s(q)
toffoli(a, b, q)
if not (measure(h(a)) | measure(h(b))):
result("rus_attempts", i)
return True
return False
repeat_until_success.check() # type check
Everything you'd expect from a modern programming language.
Arbitrary Control Flow
Full quantum measurement-dependent control flow: write if-else conditions, for and while loops, all in Python style.
Strongly Typed
The guppylang compiler uses a powerful but unobtrusive type system to provide helpful error messages.
Linear Qubits
Qubits have a linear type, following an intuitive ownership model that prevents no-cloning errors and memory leaks.
Metaprogramming
Generate and transform Guppy code at compile time to automate patterns, optimise circuits, and reduce repetition.
Classical Compute
Perform classical calculations and data manipulation alongside quantum operations seamlessly.
Data Structures
Work with arrays, tuples, and user-defined types in both classical and quantum contexts.
First-class Functions
Define functions to write structured quantum software, and pass them just like any other value.
Legacy Support
Easily integrate with existing quantum toolchains like pytket — bridging the gap with legacy circuit-building tools.
Some novel use cases with guppy.
Magic State Distillation
Crucial protocols for Quantum Error Correction like magic state distillation require complex measurement dependent logic - Guppy expresses these naturally.
Open NotebookPost-selection
Exit a shot when an error is detected without running any more operations.
Open NotebookN-qubit Graph States
Use Python metaprogramming and Guppy polymorphism to write scalable and type safe state preparation.
Open Notebook