Definitions

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

A general Guppy definition.

compile() 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: ~typing.~P, **kwargs: ~typing.~P) Out[source]

Call self as a function.

compile() Package[source]

Compiles an execution entrypoint function definition to a HUGR package

Equivalent to GuppyDefinition.compile_entrypoint().

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_function() Package[source]

Compile a Guppy function definition to HUGR.

Returns:

The compiled package object.

Return type:

Package

compile_entrypoint() Package[source]

Compiles an execution entrypoint function definition to a 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') 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 (use builder.with_platform() in that case)

  • needs (the function has to declare the expected number of qubits it)

  • @expected_qubits. (with the decorator)

  • builder – An optional EmulatorBuilder to use for building the emulator

  • provided

  • used. (the default EmulatorBuilder will be)

  • libs – An optional list of additional HUGR packages to link with the compiled

  • the (function. This can be used to provide additional library functions that)

  • on. (function being compiled depends)

  • platform – The quantum platform to target. Defaults to "helios". Set to

  • is ("sol" to target the Sol QIS. Ignored if an explicit builder)

  • provided

Returns:

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

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

Bases: GuppyDefinition

Definition of a Guppy type variable.

compile() 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() Package[source]

Compile an execution entrypoint to a HUGR package.

Alias for compile_entrypoint().

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_entrypoint() Package[source]

Compile an execution entrypoint to a HUGR package.

Returns:

The compiled package object.

Return type:

Package

Raises:

GuppyError – If the entrypoint has arguments.

compile_function() 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') 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 (use builder.with_platform() in that case)

  • needs (the function has to declare the expected number of qubits it)

  • @expected_qubits. (with the decorator)

  • builder – An optional EmulatorBuilder to use for building the emulator

  • provided

  • used. (the default EmulatorBuilder will be)

  • libs – An optional list of additional HUGR packages to link with the compiled

  • the (function. This can be used to provide additional library functions that)

  • on. (function being compiled depends)

  • platform – The quantum platform to target. Defaults to "helios". Set to

  • is ("sol" to target the Sol QIS. Ignored if an explicit builder)

  • provided

Returns:

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

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