ReplacementCompiler

class guppyft.encode.ReplacementCompiler(op_replacements: dict[tuple[str, str], tuple[str, str, list[int | str]]], compound_op_replacements: dict[tuple[str, str], ~hugr.hugr.base.Hugr[~typing.Any] | ~guppylang.defs.GuppyFunctionDefinition[(typing.Any,), ~typing.Any] | ~hugr.package.Package] = <factory>, ty_replacements: dict[tuple[str, str], tuple[str, str]] = <factory>, extensions: ~hugr.ext.ExtensionRegistry | None = None)[source]

A composable pass that replaces extension ops in a Hugr according to the given mappings.

See guppyft._bindings._run_replacement_compiler for semantic details.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__init__(op_replacements: dict[tuple[str, str], tuple[str, str, list[int | str]]], compound_op_replacements: dict[tuple[str, str], ~hugr.hugr.base.Hugr[~typing.Any] | ~guppylang.defs.GuppyFunctionDefinition[(typing.Any,), ~typing.Any] | ~hugr.package.Package] = <factory>, ty_replacements: dict[tuple[str, str], tuple[str, str]] = <factory>, extensions: ~hugr.ext.ExtensionRegistry | None = None) None
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

check_may_compile(pkg: Package) UncompilableError | None[source]

Check whether any issues can be detected that would arise when trying to compile the given package, e.g. the package containing unsupported gates.

Note that this function returning without error is not a guarantee that a subsequent call to encode will succeed.

compound_op_replacements: dict[tuple[str, str], Hugr[Any] | GuppyFunctionDefinition[Any, Any] | Package]

Replaces each source (extension_name, op_name) pair (taking no type args) with the given HUGR. When a Guppy function is given as a replacement, it is compiled to HUGR first.

extensions: ExtensionRegistry | None = None

Optional JSON-encoded list of additional extension definitions, used to resolve target ops/types that are not already registered on the input Hugr.

op_replacements: dict[tuple[str, str], tuple[str, str, list[int | str]]]

Maps each source (extension_name, op_name) pair (taking no type args) to a target (extension_name, op_name, args) triple, where args is the list of type args (integers or strings) used to instantiate the target op.

ty_replacements: dict[tuple[str, str], tuple[str, str]]

Optional mapping between src and tgt types to be replaced globally during encoding where types are provided in the form (extension_name, ty_name).