@guppy
decorator¶
- @guppylang.decorator.guppy¶
A dummy class with the same interface as @guppy that does nothing when used to decorate functions.
We use this during sphinx builds as a mock for the decorator, to ensure that Guppy functions are recognised as regular functions and included in docs.
- class guppylang.decorator._Guppy[source]¶
Class for the @guppy decorator.
- comptime(f: Callable[[P], T]) GuppyFunctionDefinition[P, T] [source]¶
- constant(name: str, ty: str, value: Value) T [source]¶
Adds a constant to a module, backed by a hugr.val.Value.
- custom(compiler: CustomInoutCallCompiler | None = None, checker: CustomCallChecker | None = None, higher_order_value: bool = True, name: str = '', signature: FunctionType | None = None) Callable[[Callable[[P], T]], GuppyFunctionDefinition[P, T]] [source]¶
- declare(f: Callable[[P], T]) GuppyFunctionDefinition[P, T] [source]¶
- hugr_op(op: Callable[[FunctionType, Sequence[TypeArg | ConstArg], CompilerContext], DataflowOp], checker: CustomCallChecker | None = None, higher_order_value: bool = True, name: str = '', signature: FunctionType | None = None) Callable[[Callable[[P], T]], GuppyFunctionDefinition[P, T]] [source]¶
- load_pytket(name: str, input_circuit: Any, *, use_arrays: bool = True) GuppyFunctionDefinition[..., Any] [source]¶
Adds a pytket circuit function definition with implicit signature.
- overload(*funcs: Any) Callable[[Callable[[P], T]], GuppyFunctionDefinition[P, T]] [source]¶
Collects multiple function definitions into one overloaded function.
Consider the following example:
@guppy.declare def variant1(x: int, y: int) -> int: ... @guppy.declare def variant2(x: float) -> int: ... @guppy.overload(variant1, variant2) def combined(): ...
Now, combined may be called with either one float or two int arguments, delegating to the implementation with the matching signature:
combined(4.2) # Calls `variant1` combined(42, 43) # Calls `variant2`
Note that the compiler will pick the first implementation with matching signature and ignore all following ones, even if they would also match. For example, if we added a third variant
@guppy.declare def variant3(x: int) -> int: ... @guppy.overload(variant1, variant2, variant3) def combined_new(): ...
then a call combined_new(42) will still select the variant1 implementation 42 is a valid argument for variant1 and variant1 comes before variant3 in the @guppy.overload annotation.
- pytket(input_circuit: Any) Callable[[Callable[[P], T]], GuppyFunctionDefinition[P, T]] [source]¶
Adds a pytket circuit function definition with explicit signature.
- @guppylang.decorator.custom_guppy_decorator[source]¶
Decorator to mark user-defined decorators that wrap builtin guppy decorators.
Example:
@custom_guppy_decorator def my_guppy(f): # Some custom logic here ... return guppy(f) @my_guppy def main() -> int: ...
If the custom_guppy_decorator were missing, then the @my_guppy annotation would not produce a valid guppy definition.