Extension#
- class hugr.ext.Extension(name: ExtensionId, version: Version, extension_reqs: set[ExtensionId] = <factory>, types: dict[str, TypeDef] = <factory>, values: dict[str, ExtensionValue] = <factory>, operations: dict[str, OpDef] = <factory>)[source]#
Bases:
object
HUGR extension declaration.
Methods
Add a value to the extension.
Add an operation definition to the extension.
Add a type definition to the extension.
Deserialize a JSON string to a Extension object.
Retrieve an operation definition by name.
Retrieve a type definition by name.
get_value
Register a class as corresponding to an operation definition.
Serialize the extension to a JSON string.
Attributes
T
The name of the extension.
The version of the extension.
Extensions required by this extension, identified by name.
Type definitions in the extension.
Values defined in the extension.
Operation definitions in the extension.
- exception NotFound(name: str)[source]#
Bases:
Exception
An object was not found in the extension.
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception OperationNotFound(name: str)[source]#
Bases:
NotFound
Operation not found in extension.
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception TypeNotFound(name: str)[source]#
Bases:
NotFound
Type not found in extension.
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ValueNotFound(name: str)[source]#
Bases:
NotFound
Value not found in extension.
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- add_extension_value(extension_value: ExtensionValue) ExtensionValue [source]#
Add a value to the extension.
- Parameters:
extension_value – The value to add.
- Returns:
The added value, now associated with the extension.
- add_op_def(op_def: OpDef) OpDef [source]#
Add an operation definition to the extension.
- Parameters:
op_def – The operation definition to add.
- Returns:
The added operation definition, now associated with the extension.
- add_type_def(type_def: TypeDef) TypeDef [source]#
Add a type definition to the extension.
- Parameters:
type_def – The type definition to add.
- Returns:
The added type definition, now associated with the extension.
- classmethod from_json(json_str: str) Extension [source]#
Deserialize a JSON string to a Extension object.
- Parameters:
json_str – The JSON string representing a Extension.
- Returns:
The deserialized Extension object.
- get_op(name: str) OpDef [source]#
Retrieve an operation definition by name.
- Parameters:
name – The name of the operation.
- Returns:
The operation definition.
- Raises:
OperationNotFound – If the operation is not found in the extension.
- get_type(name: str) TypeDef [source]#
Retrieve a type definition by name.
- Parameters:
name – The name of the type.
- Returns:
The type definition.
- Raises:
TypeNotFound – If the type is not found in the extension.
- name: ExtensionId#
The name of the extension.
- register_op(name: str | None = None, signature: OpDefSig | tys.PolyFuncType | tys.FunctionType | None = None, description: str | None = None, misc: dict[str, Any] | None = None, lower_funcs: list[FixedHugr] | None = None) Callable[[type[T]], type[T]] [source]#
Register a class as corresponding to an operation definition.
If name is not provided, the class name is used. If signature is not provided, a binary signature is assumed. If description is not provided, the class docstring is used.
See
OpDef
for other parameters.
- values: dict[str, ExtensionValue]#
Values defined in the extension.
- version: Version#
The version of the extension.