Extension¶
- class hugr.ext.Extension(name: ExtensionId, version: Version, types: dict[str, TypeDef] = <factory>, operations: dict[str, OpDef] = <factory>)[source]¶
Bases:
object
HUGR extension declaration.
Methods
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.
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.
Type definitions in the extension.
Operation definitions in the extension.
- exception NotFound(name: str)[source]¶
Bases:
Exception
An object was not found in the extension.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- 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.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- 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.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- 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.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- 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.
- version: Version¶
The version of the extension.