encode

guppyft.encode.encode(hugr: Package | GuppyFunctionDefinition[(), None], spec: EncodeSpec, *, passes: list[ComposablePass] | None = None, as_bytes: Literal[False] = False) → Package[source]
guppyft.encode.encode(hugr: Package | GuppyFunctionDefinition[(), None], spec: EncodeSpec, *, passes: list[ComposablePass] | None = None, as_bytes: Literal[True]) → bytes

Encodes the given package (or Guppy function, directly compiled to a package for convenience) by applying four stages.

  1. running the given computational passes;

  2. lowering the operations in the package to logical operations and potentially performing static optimizations (e.g. resolving some qubit address assignments statically);

  3. running additional logical passes (e.g. inserting additional QEC cycles); and

  4. implementing the logical operations with physical gates.

The returned runnable package is guaranteed to be semantically equivalent to the given one.

Parameters:
  • hugr – The package to encode, or a Guppy function for convenience.

  • spec – See EncodeSpec.

  • passes – Computational passes to run on the given package. Defaults to one run of Normalize.

  • as_bytes – Whether to return the encoded package as bytes.

Returns:

The encoded runnable package, or its serialized representation when as_bytes is True.