Definitions

class guppylang.defs.GuppyDefinition(wrapped: Definition)[source]

A general Guppy definition.

compile(debug_mode: bool = False) Package[source]

Compile a Guppy definition to HUGR.

check() None[source]

Type-check a Guppy definition.

class guppylang.defs.GuppyFunctionDefinition(wrapped: Definition)[source]

Bases: GuppyDefinition, GuppyCompilableProgram, Generic[P, Out]

A Guppy function definition.

__call__(*args: P, **kwargs: P) Out[source]

Call self as a function.

compile(debug_mode: bool = False) Package[source]

Compiles an execution entrypoint function definition to a HUGR package

Equivalent to GuppyDefinition.compile_entrypoint().

Parameters:

debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_function(debug_mode: bool = False) Package[source]

Compile a Guppy function definition to HUGR.

Parameters:

debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

The compiled package object.

Return type:

Package

compile_entrypoint(debug_mode: bool = False) Package[source]

Compiles an execution entrypoint function definition to a HUGR package

Parameters:

debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

check() None

Type-check a Guppy definition.

with_minimal_opt() OptimizerInstance[P, Out][source]

Configure the function to use minimal optimization when compiling.

Equivalent to with_opt_level(OptimizationLevel.Minimal).

with_opt_level(level: OptimizationLevel) OptimizerInstance[P, Out][source]

Configure the optimization level used when compiling this function.

emulator(n_qubits: int | None = None, builder: EmulatorBuilder | None = None, libs: list[Package] | None = None, platform: Literal['helios', 'sol'] = 'helios', debug_mode: bool = False) EmulatorInstance[source]

Compile this function for emulation with the selene-sim emulator.

Compiles the function to a HUGR package and builds it using the provided EmulatorBuilder configuration or a default one.

See guppylang.emulator for more details on the emulator.

Parameters:
  • n_qubits – The number of qubits to allocate for the function. If it is not provided, the function has to declare the expected number of qubits it needs with the decorator @expected_qubits.

  • builder – An optional EmulatorBuilder to use for building the emulator instance. If not provided, the default EmulatorBuilder will be used.

  • libs – An optional list of additional HUGR packages to link with the compiled function. This can be used to provide additional library functions that the function being compiled depends on.

  • platform – The quantum platform to target. Defaults to "helios". Set to "sol" to target the Sol QIS. Ignored if an explicit builder is provided (use builder.with_platform() in that case).

  • debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

An EmulatorInstance that can be used to run the function in an emulator.

Raises:

EmulatorBuildError – If debug mode is enabled without minimal optimization.

class guppylang.defs.GuppyTypeVarDefinition(wrapped: Definition, _ty_var: TypeVar)[source]

Bases: GuppyDefinition

Definition of a Guppy type variable.

compile(debug_mode: bool = False) Package

Compile a Guppy definition to HUGR.

check() None

Type-check a Guppy definition.

__eq__(other: object) bool[source]

Return self==value.

__getattr__(name: str) Any[source]
class guppylang.defs.GuppyEnumDefinition(wrapped: Definition)[source]

Bases: GuppyDefinition

A Guppy enum definition.

__getattr__(name: str) Any[source]
class guppylang.defs.GuppyCompilableProgram(*args, **kwargs)[source]

Bases: Protocol

A guppy definition for a program that can be compiled or emulated.

compile(debug_mode: bool = False) Package[source]

Compile an execution entrypoint to a HUGR package.

Alias for compile_entrypoint().

Parameters:

debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_entrypoint(debug_mode: bool = False) Package[source]

Compile an execution entrypoint to a HUGR package.

Parameters:

debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_function(debug_mode: bool = False) Package[source]

Compile the function definition to a HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the function has arguments.

emulator(n_qubits: int | None = None, builder: EmulatorBuilder | None = None, libs: list[Package] | None = None, platform: Literal['helios', 'sol'] = 'helios', debug_mode: bool = False) EmulatorInstance[source]

Compile this function for emulation with the selene-sim emulator.

Compiles the function to a HUGR package and builds it using the provided EmulatorBuilder configuration or a default one.

See guppylang.emulator for more details on the emulator.

Parameters:
  • n_qubits – The number of qubits to allocate for the function. If it is not provided, the function has to declare the expected number of qubits it needs with the decorator @expected_qubits.

  • builder – An optional EmulatorBuilder to use for building the emulator instance. If not provided, the default EmulatorBuilder will be used.

  • libs – An optional list of additional HUGR packages to link with the compiled function. This can be used to provide additional library functions that the function being compiled depends on.

  • platform – The quantum platform to target. Defaults to "helios". Set to "sol" to target the Sol QIS. Ignored if an explicit builder is provided (use builder.with_platform() in that case).

  • debug_mode – Whether to add debug information to the compiled package. This may be useful for debugging, but will increase the size of the HUGR package.

Returns:

An EmulatorInstance that can be used to run the function in an emulator.

Raises:

EmulatorBuildError – If debug mode is enabled without minimal optimization.

exception guppylang.defs.EntrypointArgsError(span: ToSpan | None, args: collections.abc.Sequence[str])[source]
exception guppylang.defs.UnsupportedEntrypointArgError(span: ToSpan | None, reason: str)[source]