From 6136098039b2da3fce36885b4d5e581003af4719 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 28 Aug 2024 12:36:19 +0100 Subject: [PATCH 1/3] refactor(hugr-py)!: make serialization (module/methods) private Closes #1464 --- .../__init__.py | 0 .../extension.py | 0 .../{serialization => _serialization}/ops.py | 4 +- .../serial_hugr.py | 0 .../testing_hugr.py | 0 .../{serialization => _serialization}/tys.py | 0 hugr-py/src/hugr/ext.py | 46 ++++----- hugr-py/src/hugr/hugr.py | 18 ++-- hugr-py/src/hugr/ops.py | 94 +++++++++---------- hugr-py/src/hugr/std/__init__.py | 2 +- hugr-py/src/hugr/tys.py | 83 ++++++++-------- hugr-py/src/hugr/utils.py | 4 +- hugr-py/src/hugr/val.py | 30 +++--- hugr-py/tests/conftest.py | 10 +- hugr-py/tests/serialization/test_basic.py | 2 +- hugr-py/tests/serialization/test_extension.py | 6 +- hugr-py/tests/test_custom.py | 8 +- hugr-py/tests/test_hugr_build.py | 2 +- scripts/generate_schema.py | 8 +- 19 files changed, 159 insertions(+), 158 deletions(-) rename hugr-py/src/hugr/{serialization => _serialization}/__init__.py (100%) rename hugr-py/src/hugr/{serialization => _serialization}/extension.py (100%) rename hugr-py/src/hugr/{serialization => _serialization}/ops.py (99%) rename hugr-py/src/hugr/{serialization => _serialization}/serial_hugr.py (100%) rename hugr-py/src/hugr/{serialization => _serialization}/testing_hugr.py (100%) rename hugr-py/src/hugr/{serialization => _serialization}/tys.py (100%) diff --git a/hugr-py/src/hugr/serialization/__init__.py b/hugr-py/src/hugr/_serialization/__init__.py similarity index 100% rename from hugr-py/src/hugr/serialization/__init__.py rename to hugr-py/src/hugr/_serialization/__init__.py diff --git a/hugr-py/src/hugr/serialization/extension.py b/hugr-py/src/hugr/_serialization/extension.py similarity index 100% rename from hugr-py/src/hugr/serialization/extension.py rename to hugr-py/src/hugr/_serialization/extension.py diff --git a/hugr-py/src/hugr/serialization/ops.py b/hugr-py/src/hugr/_serialization/ops.py similarity index 99% rename from hugr-py/src/hugr/serialization/ops.py rename to hugr-py/src/hugr/_serialization/ops.py index 10aa198f7..b6c9e77c1 100644 --- a/hugr-py/src/hugr/serialization/ops.py +++ b/hugr-py/src/hugr/_serialization/ops.py @@ -127,11 +127,11 @@ class FunctionValue(BaseValue): hugr: Any def deserialize(self) -> val.Value: + from hugr._serialization.serial_hugr import SerialHugr from hugr.hugr import Hugr - from hugr.serialization.serial_hugr import SerialHugr # pydantic stores the serialized dictionary because of the "Any" annotation - return val.Function(Hugr.from_serial(SerialHugr(**self.hugr))) + return val.Function(Hugr._from_serial(SerialHugr(**self.hugr))) class TupleValue(BaseValue): diff --git a/hugr-py/src/hugr/serialization/serial_hugr.py b/hugr-py/src/hugr/_serialization/serial_hugr.py similarity index 100% rename from hugr-py/src/hugr/serialization/serial_hugr.py rename to hugr-py/src/hugr/_serialization/serial_hugr.py diff --git a/hugr-py/src/hugr/serialization/testing_hugr.py b/hugr-py/src/hugr/_serialization/testing_hugr.py similarity index 100% rename from hugr-py/src/hugr/serialization/testing_hugr.py rename to hugr-py/src/hugr/_serialization/testing_hugr.py diff --git a/hugr-py/src/hugr/serialization/tys.py b/hugr-py/src/hugr/_serialization/tys.py similarity index 100% rename from hugr-py/src/hugr/serialization/tys.py rename to hugr-py/src/hugr/_serialization/tys.py diff --git a/hugr-py/src/hugr/ext.py b/hugr-py/src/hugr/ext.py index 85b6d0abb..110625a2b 100644 --- a/hugr-py/src/hugr/ext.py +++ b/hugr-py/src/hugr/ext.py @@ -7,7 +7,7 @@ from semver import Version -import hugr.serialization.extension as ext_s +import hugr._serialization.extension as ext_s from hugr import ops, tys, val from hugr.utils import ser_it @@ -43,11 +43,11 @@ class ExplicitBound: bound: tys.TypeBound - def to_serial(self) -> ext_s.ExplicitBound: + def _to_serial(self) -> ext_s.ExplicitBound: return ext_s.ExplicitBound(bound=self.bound) - def to_serial_root(self) -> ext_s.TypeDefBound: - return ext_s.TypeDefBound(root=self.to_serial()) + def _to_serial_root(self) -> ext_s.TypeDefBound: + return ext_s.TypeDefBound(root=self._to_serial()) @dataclass @@ -63,11 +63,11 @@ class FromParamsBound: indices: list[int] - def to_serial(self) -> ext_s.FromParamsBound: + def _to_serial(self) -> ext_s.FromParamsBound: return ext_s.FromParamsBound(indices=self.indices) - def to_serial_root(self) -> ext_s.TypeDefBound: - return ext_s.TypeDefBound(root=self.to_serial()) + def _to_serial_root(self) -> ext_s.TypeDefBound: + return ext_s.TypeDefBound(root=self._to_serial()) @dataclass @@ -128,13 +128,13 @@ class TypeDef(ExtensionObject): #: The type bound of the type. bound: ExplicitBound | FromParamsBound - def to_serial(self) -> ext_s.TypeDef: + def _to_serial(self) -> ext_s.TypeDef: return ext_s.TypeDef( extension=self.get_extension().name, name=self.name, description=self.description, params=ser_it(self.params), - bound=ext_s.TypeDefBound(root=self.bound.to_serial()), + bound=ext_s.TypeDefBound(root=self.bound._to_serial()), ) def instantiate(self, args: Sequence[tys.TypeArg]) -> tys.ExtType: @@ -155,7 +155,7 @@ class FixedHugr: #: HUGR defining operation lowering. hugr: Hugr - def to_serial(self) -> ext_s.FixedHugr: + def _to_serial(self) -> ext_s.FixedHugr: return ext_s.FixedHugr(extensions=self.extensions, hugr=self.hugr) @@ -200,17 +200,17 @@ class OpDef(ExtensionObject): #: Lowerings of the operation. lower_funcs: list[FixedHugr] = field(default_factory=list, repr=False) - def to_serial(self) -> ext_s.OpDef: + def _to_serial(self) -> ext_s.OpDef: return ext_s.OpDef( extension=self.get_extension().name, name=self.name, description=self.description, misc=self.misc, - signature=self.signature.poly_func.to_serial() + signature=self.signature.poly_func._to_serial() if self.signature.poly_func else None, binary=self.signature.binary, - lower_funcs=[f.to_serial() for f in self.lower_funcs], + lower_funcs=[f._to_serial() for f in self.lower_funcs], ) @@ -223,11 +223,11 @@ class ExtensionValue(ExtensionObject): #: Value payload. val: val.Value - def to_serial(self) -> ext_s.ExtensionValue: + def _to_serial(self) -> ext_s.ExtensionValue: return ext_s.ExtensionValue( extension=self.get_extension().name, name=self.name, - typed_value=self.val.to_serial_root(), + typed_value=self.val._to_serial_root(), ) @@ -257,14 +257,14 @@ class NotFound(Exception): name: str - def to_serial(self) -> ext_s.Extension: + def _to_serial(self) -> ext_s.Extension: return ext_s.Extension( name=self.name, version=self.version, # type: ignore[arg-type] extension_reqs=self.extension_reqs, - types={k: v.to_serial() for k, v in self.types.items()}, - values={k: v.to_serial() for k, v in self.values.items()}, - operations={k: v.to_serial() for k, v in self.operations.items()}, + types={k: v._to_serial() for k, v in self.types.items()}, + values={k: v._to_serial() for k, v in self.values.items()}, + operations={k: v._to_serial() for k, v in self.operations.items()}, ) def add_op_def(self, op_def: OpDef) -> OpDef: @@ -465,11 +465,11 @@ class Package: #: Extensions included in the package. extensions: list[Extension] = field(default_factory=list) - def to_serial(self) -> ext_s.Package: + def _to_serial(self) -> ext_s.Package: return ext_s.Package( - modules=[m.to_serial() for m in self.modules], - extensions=[e.to_serial() for e in self.extensions], + modules=[m._to_serial() for m in self.modules], + extensions=[e._to_serial() for e in self.extensions], ) def to_json(self) -> str: - return self.to_serial().model_dump_json() + return self._to_serial().model_dump_json() diff --git a/hugr-py/src/hugr/hugr.py b/hugr-py/src/hugr/hugr.py index 7631c5e90..318dd29ea 100644 --- a/hugr-py/src/hugr/hugr.py +++ b/hugr-py/src/hugr/hugr.py @@ -15,6 +15,8 @@ overload, ) +from hugr._serialization.ops import OpType as SerialOp +from hugr._serialization.serial_hugr import SerialHugr from hugr.node_port import ( Direction, InPort, @@ -26,8 +28,6 @@ _SubPort, ) from hugr.ops import Call, Const, Custom, DataflowOp, Module, Op -from hugr.serialization.ops import OpType as SerialOp -from hugr.serialization.serial_hugr import SerialHugr from hugr.tys import Kind, Type, ValueKind from hugr.utils import BiMap from hugr.val import Value @@ -54,8 +54,8 @@ class NodeData: children: list[Node] = field(default_factory=list, repr=False) metadata: dict[str, Any] = field(default_factory=dict) - def to_serial(self, node: Node) -> SerialOp: - o = self.op.to_serial(self.parent if self.parent else node) + def _to_serial(self, node: Node) -> SerialOp: + o = self.op._to_serial(self.parent if self.parent else node) return SerialOp(root=o) # type: ignore[arg-type] @@ -601,7 +601,7 @@ def insert_hugr(self, hugr: Hugr, parent: ToNode | None = None) -> dict[Node, No ) return mapping - def to_serial(self) -> SerialHugr: + def _to_serial(self) -> SerialHugr: """Serialize the HUGR.""" node_it = (node for node in self._nodes if node is not None) @@ -614,7 +614,7 @@ def _serialize_link( return SerialHugr( # non contiguous indices will be erased - nodes=[node.to_serial(Node(idx, {})) for idx, node in enumerate(node_it)], + nodes=[node._to_serial(Node(idx, {})) for idx, node in enumerate(node_it)], edges=[_serialize_link(link) for link in self._links.items()], metadata=[node.metadata if node.metadata else None for node in node_it], ) @@ -644,7 +644,7 @@ def resolve_extensions(self, registry: ext.ExtensionRegistry) -> Hugr: return self @classmethod - def from_serial(cls, serial: SerialHugr) -> Hugr: + def _from_serial(cls, serial: SerialHugr) -> Hugr: """Load a HUGR from a serialized form.""" assert serial.nodes, "Empty Hugr is invalid" @@ -685,14 +685,14 @@ def get_meta(idx: int) -> dict[str, Any]: def to_json(self) -> str: """Serialize the HUGR to a JSON string.""" - return self.to_serial().to_json() + return self._to_serial().to_json() @classmethod def load_json(cls, json_str: str) -> Hugr: """Deserialize a JSON string into a HUGR.""" json_dict = json.loads(json_str) serial = SerialHugr.load_json(json_dict) - return cls.from_serial(serial) + return cls._from_serial(serial) def render_dot(self, palette: str | None = None) -> gv.Digraph: """Render the HUGR to a graphviz Digraph. diff --git a/hugr-py/src/hugr/ops.py b/hugr-py/src/hugr/ops.py index e00148eb8..90586d301 100644 --- a/hugr-py/src/hugr/ops.py +++ b/hugr-py/src/hugr/ops.py @@ -8,7 +8,7 @@ from typing_extensions import Self -import hugr.serialization.ops as sops +import hugr._serialization.ops as sops from hugr import tys, val from hugr.node_port import Direction, InPort, Node, OutPort, PortOffset, Wire from hugr.utils import ser_it @@ -17,7 +17,7 @@ from collections.abc import Sequence from hugr import ext - from hugr.serialization.ops import BaseOp + from hugr._serialization.ops import BaseOp @dataclass @@ -49,7 +49,7 @@ def num_out(self) -> int: """ ... # pragma: no cover - def to_serial(self, parent: Node) -> BaseOp: + def _to_serial(self, parent: Node) -> BaseOp: """Convert this operation to a serializable form.""" ... # pragma: no cover @@ -168,7 +168,7 @@ class Input(DataflowOp): def num_out(self) -> int: return len(self.types) - def to_serial(self, parent: Node) -> sops.Input: + def _to_serial(self, parent: Node) -> sops.Input: return sops.Input(parent=parent.idx, types=ser_it(self.types)) def outer_signature(self) -> tys.FunctionType: @@ -191,7 +191,7 @@ class Output(DataflowOp, _PartialOp): def types(self) -> tys.TypeRow: return _check_complete(self, self._types) - def to_serial(self, parent: Node) -> sops.Output: + def _to_serial(self, parent: Node) -> sops.Output: return sops.Output(parent=parent.idx, types=ser_it(self.types)) def outer_signature(self) -> tys.FunctionType: @@ -279,8 +279,8 @@ def __eq__(self, other: object) -> bool: def outer_signature(self) -> tys.FunctionType: return self.ext_op.outer_signature() - def to_serial(self, parent: Node) -> sops.Extension: - return self.ext_op.to_serial(parent) + def _to_serial(self, parent: Node) -> sops.Extension: + return self.ext_op._to_serial(parent) @property def num_out(self) -> int: @@ -297,12 +297,12 @@ class Custom(DataflowOp): extension: tys.ExtensionId = "" args: list[tys.TypeArg] = field(default_factory=list) - def to_serial(self, parent: Node) -> sops.Extension: + def _to_serial(self, parent: Node) -> sops.Extension: return sops.Extension( parent=parent.idx, extension=self.extension, name=self.name, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), description=self.description, args=ser_it(self.args), ) @@ -366,8 +366,8 @@ def to_custom_op(self) -> Custom: args=self.args, ) - def to_serial(self, parent: Node) -> sops.Extension: - return self.to_custom_op().to_serial(parent) + def _to_serial(self, parent: Node) -> sops.Extension: + return self.to_custom_op()._to_serial(parent) def op_def(self) -> ext.OpDef: return self._op_def @@ -422,7 +422,7 @@ def types(self) -> tys.TypeRow: """ return _check_complete(self, self._types) - def to_serial(self, parent: Node) -> sops.MakeTuple: + def _to_serial(self, parent: Node) -> sops.MakeTuple: return sops.MakeTuple( parent=parent.idx, tys=ser_it(self.types), @@ -460,7 +460,7 @@ def types(self) -> tys.TypeRow: def num_out(self) -> int: return len(self.types) - def to_serial(self, parent: Node) -> sops.UnpackTuple: + def _to_serial(self, parent: Node) -> sops.UnpackTuple: return sops.UnpackTuple( parent=parent.idx, tys=ser_it(self.types), @@ -491,7 +491,7 @@ class Tag(DataflowOp): sum_ty: tys.Sum num_out: int = field(default=1, repr=False) - def to_serial(self, parent: Node) -> sops.Tag: + def _to_serial(self, parent: Node) -> sops.Tag: return sops.Tag( parent=parent.idx, tag=self.tag, @@ -549,10 +549,10 @@ def signature(self) -> tys.FunctionType: def num_out(self) -> int: return len(self.signature.output) - def to_serial(self, parent: Node) -> sops.DFG: + def _to_serial(self, parent: Node) -> sops.DFG: return sops.DFG( parent=parent.idx, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), ) def inner_signature(self) -> tys.FunctionType: @@ -598,10 +598,10 @@ def signature(self) -> tys.FunctionType: def num_out(self) -> int: return len(self.outputs) - def to_serial(self, parent: Node) -> sops.CFG: + def _to_serial(self, parent: Node) -> sops.CFG: return sops.CFG( parent=parent.idx, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), ) def outer_signature(self) -> tys.FunctionType: @@ -643,7 +643,7 @@ def other_outputs(self) -> tys.TypeRow: def num_out(self) -> int: return len(self.sum_ty.variant_rows) - def to_serial(self, parent: Node) -> sops.DataflowBlock: + def _to_serial(self, parent: Node) -> sops.DataflowBlock: return sops.DataflowBlock( parent=parent.idx, inputs=ser_it(self.inputs), @@ -691,7 +691,7 @@ def cfg_outputs(self) -> tys.TypeRow: """ return _check_complete(self, self._cfg_outputs) - def to_serial(self, parent: Node) -> sops.ExitBlock: + def _to_serial(self, parent: Node) -> sops.ExitBlock: return sops.ExitBlock( parent=parent.idx, cfg_outputs=ser_it(self.cfg_outputs), @@ -710,10 +710,10 @@ class Const(Op): val: val.Value num_out: int = field(default=1, repr=False) - def to_serial(self, parent: Node) -> sops.Const: + def _to_serial(self, parent: Node) -> sops.Const: return sops.Const( parent=parent.idx, - v=self.val.to_serial_root(), + v=self.val._to_serial_root(), ) def port_kind(self, port: InPort | OutPort) -> tys.Kind: @@ -743,10 +743,10 @@ def type_(self) -> tys.Type: """ return _check_complete(self, self._typ) - def to_serial(self, parent: Node) -> sops.LoadConstant: + def _to_serial(self, parent: Node) -> sops.LoadConstant: return sops.LoadConstant( parent=parent.idx, - datatype=self.type_.to_serial_root(), + datatype=self.type_._to_serial_root(), ) def outer_signature(self) -> tys.FunctionType: @@ -800,7 +800,7 @@ def signature(self) -> tys.FunctionType: def num_out(self) -> int: return len(self.outputs) - def to_serial(self, parent: Node) -> sops.Conditional: + def _to_serial(self, parent: Node) -> sops.Conditional: return sops.Conditional( parent=parent.idx, sum_rows=[ser_it(r) for r in self.sum_ty.variant_rows], @@ -836,9 +836,9 @@ def outputs(self) -> tys.TypeRow: """ return _check_complete(self, self._outputs) - def to_serial(self, parent: Node) -> sops.Case: + def _to_serial(self, parent: Node) -> sops.Case: return sops.Case( - parent=parent.idx, signature=self.inner_signature().to_serial() + parent=parent.idx, signature=self.inner_signature()._to_serial() ) def inner_signature(self) -> tys.FunctionType: @@ -880,7 +880,7 @@ def just_outputs(self) -> tys.TypeRow: def num_out(self) -> int: return len(self.just_outputs) + len(self.rest) - def to_serial(self, parent: Node) -> sops.TailLoop: + def _to_serial(self, parent: Node) -> sops.TailLoop: return sops.TailLoop( parent=parent.idx, just_inputs=ser_it(self.just_inputs), @@ -944,11 +944,11 @@ def signature(self) -> tys.PolyFuncType: self.params, tys.FunctionType(self.inputs, self.outputs) ) - def to_serial(self, parent: Node) -> sops.FuncDefn: + def _to_serial(self, parent: Node) -> sops.FuncDefn: return sops.FuncDefn( parent=parent.idx, name=self.name, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), ) def inner_signature(self) -> tys.FunctionType: @@ -978,11 +978,11 @@ class FuncDecl(Op): signature: tys.PolyFuncType num_out: int = field(default=1, repr=False) - def to_serial(self, parent: Node) -> sops.FuncDecl: + def _to_serial(self, parent: Node) -> sops.FuncDecl: return sops.FuncDecl( parent=parent.idx, name=self.name, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), ) def port_kind(self, port: InPort | OutPort) -> tys.Kind: @@ -999,7 +999,7 @@ class Module(Op): num_out: int = field(default=0, repr=False) - def to_serial(self, parent: Node) -> sops.Module: + def _to_serial(self, parent: Node) -> sops.Module: return sops.Module(parent=parent.idx) def port_kind(self, port: InPort | OutPort) -> tys.Kind: @@ -1059,12 +1059,12 @@ class Call(_CallOrLoad, Op): is provided. """ - def to_serial(self, parent: Node) -> sops.Call: + def _to_serial(self, parent: Node) -> sops.Call: return sops.Call( parent=parent.idx, - func_sig=self.signature.to_serial(), + func_sig=self.signature._to_serial(), type_args=ser_it(self.type_args), - instantiation=self.instantiation.to_serial(), + instantiation=self.instantiation._to_serial(), ) @property @@ -1103,10 +1103,10 @@ def signature(self) -> tys.FunctionType: """ return _check_complete(self, self._signature) - def to_serial(self, parent: Node) -> sops.CallIndirect: + def _to_serial(self, parent: Node) -> sops.CallIndirect: return sops.CallIndirect( parent=parent.idx, - signature=self.signature.to_serial(), + signature=self.signature._to_serial(), ) def __call__(self, function: ComWire, *args: ComWire) -> Command: # type: ignore[override] @@ -1141,12 +1141,12 @@ class LoadFunc(_CallOrLoad, DataflowOp): num_out: int = field(default=1, repr=False) - def to_serial(self, parent: Node) -> sops.LoadFunction: + def _to_serial(self, parent: Node) -> sops.LoadFunction: return sops.LoadFunction( parent=parent.idx, - func_sig=self.signature.to_serial(), + func_sig=self.signature._to_serial(), type_args=ser_it(self.type_args), - signature=self.outer_signature().to_serial(), + signature=self.outer_signature()._to_serial(), ) def outer_signature(self) -> tys.FunctionType: @@ -1174,8 +1174,8 @@ def type_(self) -> tys.Type: """The type of the input and output of the operation.""" return _check_complete(self, self._type) - def to_serial(self, parent: Node) -> sops.Noop: - return sops.Noop(parent=parent.idx, ty=self.type_.to_serial_root()) + def _to_serial(self, parent: Node) -> sops.Noop: + return sops.Noop(parent=parent.idx, ty=self.type_._to_serial_root()) def outer_signature(self) -> tys.FunctionType: return tys.FunctionType.endo([self.type_]) @@ -1202,7 +1202,7 @@ def type_row(self) -> tys.TypeRow: """Types of the input and output of the operation.""" return _check_complete(self, self._type_row) - def to_serial(self, parent: Node) -> sops.Lift: + def _to_serial(self, parent: Node) -> sops.Lift: return sops.Lift( parent=parent.idx, new_extension=self.new_extension, @@ -1226,7 +1226,7 @@ class AliasDecl(Op): bound: tys.TypeBound num_out: int = field(default=0, repr=False) - def to_serial(self, parent: Node) -> sops.AliasDecl: + def _to_serial(self, parent: Node) -> sops.AliasDecl: return sops.AliasDecl( parent=parent.idx, name=self.name, @@ -1247,11 +1247,11 @@ class AliasDefn(Op): definition: tys.Type num_out: int = field(default=0, repr=False) - def to_serial(self, parent: Node) -> sops.AliasDefn: + def _to_serial(self, parent: Node) -> sops.AliasDefn: return sops.AliasDefn( parent=parent.idx, name=self.name, - definition=self.definition.to_serial_root(), + definition=self.definition._to_serial_root(), ) def port_kind(self, port: InPort | OutPort) -> tys.Kind: diff --git a/hugr-py/src/hugr/std/__init__.py b/hugr-py/src/hugr/std/__init__.py index f3dd70167..aa97cf0b0 100644 --- a/hugr-py/src/hugr/std/__init__.py +++ b/hugr-py/src/hugr/std/__init__.py @@ -2,8 +2,8 @@ import pkgutil +from hugr._serialization.extension import Extension as PdExtension from hugr.ext import Extension -from hugr.serialization.extension import Extension as PdExtension def _load_extension(name: str) -> Extension: diff --git a/hugr-py/src/hugr/tys.py b/hugr-py/src/hugr/tys.py index 5570f72ca..c6544b5bf 100644 --- a/hugr-py/src/hugr/tys.py +++ b/hugr-py/src/hugr/tys.py @@ -5,7 +5,7 @@ from dataclasses import dataclass, field from typing import TYPE_CHECKING, Protocol, runtime_checkable -import hugr.serialization.tys as stys +import hugr._serialization.tys as stys from hugr.utils import ser_it if TYPE_CHECKING: @@ -20,23 +20,23 @@ class TypeParam(Protocol): """A HUGR type parameter.""" - def to_serial(self) -> stys.BaseTypeParam: + def _to_serial(self) -> stys.BaseTypeParam: """Convert to serializable model.""" ... # pragma: no cover - def to_serial_root(self) -> stys.TypeParam: - return stys.TypeParam(root=self.to_serial()) # type: ignore[arg-type] + def _to_serial_root(self) -> stys.TypeParam: + return stys.TypeParam(root=self._to_serial()) # type: ignore[arg-type] class TypeArg(Protocol): """A HUGR type argument, which can be bound to a :class:TypeParam.""" - def to_serial(self) -> stys.BaseTypeArg: + def _to_serial(self) -> stys.BaseTypeArg: """Convert to serializable model.""" ... # pragma: no cover - def to_serial_root(self) -> stys.TypeArg: - return stys.TypeArg(root=self.to_serial()) # type: ignore[arg-type] + def _to_serial_root(self) -> stys.TypeArg: + return stys.TypeArg(root=self._to_serial()) # type: ignore[arg-type] def resolve(self, registry: ext.ExtensionRegistry) -> TypeArg: """Resolve types in the argument using the given registry.""" @@ -58,12 +58,12 @@ def type_bound(self) -> stys.TypeBound: """ ... # pragma: no cover - def to_serial(self) -> stys.BaseType: + def _to_serial(self) -> stys.BaseType: """Convert to serializable model.""" ... # pragma: no cover - def to_serial_root(self) -> stys.Type: - return stys.Type(root=self.to_serial()) # type: ignore[arg-type] + def _to_serial_root(self) -> stys.Type: + return stys.Type(root=self._to_serial()) # type: ignore[arg-type] def type_arg(self) -> TypeTypeArg: """The :class:`TypeTypeArg` for this type. @@ -93,7 +93,7 @@ class TypeTypeParam(TypeParam): bound: TypeBound - def to_serial(self) -> stys.TypeTypeParam: + def _to_serial(self) -> stys.TypeTypeParam: return stys.TypeTypeParam(b=self.bound) @@ -103,7 +103,7 @@ class BoundedNatParam(TypeParam): upper_bound: int | None - def to_serial(self) -> stys.BoundedNatParam: + def _to_serial(self) -> stys.BoundedNatParam: return stys.BoundedNatParam(bound=self.upper_bound) @@ -111,7 +111,7 @@ def to_serial(self) -> stys.BoundedNatParam: class StringParam(TypeParam): """String type parameter.""" - def to_serial(self) -> stys.StringParam: + def _to_serial(self) -> stys.StringParam: return stys.StringParam() @@ -121,8 +121,8 @@ class ListParam(TypeParam): param: TypeParam - def to_serial(self) -> stys.ListParam: - return stys.ListParam(param=self.param.to_serial_root()) + def _to_serial(self) -> stys.ListParam: + return stys.ListParam(param=self.param._to_serial_root()) @dataclass(frozen=True) @@ -131,7 +131,7 @@ class TupleParam(TypeParam): params: list[TypeParam] - def to_serial(self) -> stys.TupleParam: + def _to_serial(self) -> stys.TupleParam: return stys.TupleParam(params=ser_it(self.params)) @@ -139,7 +139,7 @@ def to_serial(self) -> stys.TupleParam: class ExtensionsParam(TypeParam): """An extension set parameter.""" - def to_serial(self) -> stys.ExtensionsParam: + def _to_serial(self) -> stys.ExtensionsParam: return stys.ExtensionsParam() @@ -154,8 +154,8 @@ class TypeTypeArg(TypeArg): ty: Type - def to_serial(self) -> stys.TypeTypeArg: - return stys.TypeTypeArg(ty=self.ty.to_serial_root()) + def _to_serial(self) -> stys.TypeTypeArg: + return stys.TypeTypeArg(ty=self.ty._to_serial_root()) def resolve(self, registry: ext.ExtensionRegistry) -> TypeArg: return TypeTypeArg(self.ty.resolve(registry)) @@ -167,7 +167,7 @@ class BoundedNatArg(TypeArg): n: int - def to_serial(self) -> stys.BoundedNatArg: + def _to_serial(self) -> stys.BoundedNatArg: return stys.BoundedNatArg(n=self.n) @@ -177,7 +177,7 @@ class StringArg(TypeArg): value: str - def to_serial(self) -> stys.StringArg: + def _to_serial(self) -> stys.StringArg: return stys.StringArg(arg=self.value) @@ -187,7 +187,7 @@ class SequenceArg(TypeArg): elems: list[TypeArg] - def to_serial(self) -> stys.SequenceArg: + def _to_serial(self) -> stys.SequenceArg: return stys.SequenceArg(elems=ser_it(self.elems)) def resolve(self, registry: ext.ExtensionRegistry) -> TypeArg: @@ -200,7 +200,7 @@ class ExtensionsArg(TypeArg): extensions: ExtensionSet - def to_serial(self) -> stys.ExtensionsArg: + def _to_serial(self) -> stys.ExtensionsArg: return stys.ExtensionsArg(es=self.extensions) @@ -211,8 +211,8 @@ class VariableArg(TypeArg): idx: int param: TypeParam - def to_serial(self) -> stys.VariableArg: - return stys.VariableArg(idx=self.idx, cached_decl=self.param.to_serial_root()) + def _to_serial(self) -> stys.VariableArg: + return stys.VariableArg(idx=self.idx, cached_decl=self.param._to_serial_root()) # ---------------------------------------------- @@ -227,8 +227,8 @@ class Array(Type): ty: Type size: int - def to_serial(self) -> stys.Array: - return stys.Array(ty=self.ty.to_serial_root(), len=self.size) + def _to_serial(self) -> stys.Array: + return stys.Array(ty=self.ty._to_serial_root(), len=self.size) def type_bound(self) -> TypeBound: return self.ty.type_bound() @@ -243,7 +243,7 @@ class Sum(Type): variant_rows: list[TypeRow] - def to_serial(self) -> stys.GeneralSum: + def _to_serial(self) -> stys.GeneralSum: return stys.GeneralSum(rows=[ser_it(row) for row in self.variant_rows]) def as_tuple(self) -> Tuple: @@ -276,7 +276,7 @@ def __init__(self, size: int): self.size = size super().__init__(variant_rows=[[]] * size) - def to_serial(self) -> stys.UnitSum: # type: ignore[override] + def _to_serial(self) -> stys.UnitSum: # type: ignore[override] return stys.UnitSum(size=self.size) def __repr__(self) -> str: @@ -310,7 +310,7 @@ class Variable(Type): idx: int bound: TypeBound - def to_serial(self) -> stys.Variable: + def _to_serial(self) -> stys.Variable: return stys.Variable(i=self.idx, b=self.bound) def type_bound(self) -> TypeBound: @@ -324,7 +324,7 @@ class RowVariable(Type): idx: int bound: TypeBound - def to_serial(self) -> stys.RowVar: + def _to_serial(self) -> stys.RowVar: return stys.RowVar(i=self.idx, b=self.bound) def type_bound(self) -> TypeBound: @@ -335,7 +335,7 @@ def type_bound(self) -> TypeBound: class USize(Type): """The Prelude unsigned size type.""" - def to_serial(self) -> stys.USize: + def _to_serial(self) -> stys.USize: return stys.USize() def type_bound(self) -> TypeBound: @@ -349,7 +349,7 @@ class Alias(Type): name: str bound: TypeBound - def to_serial(self) -> stys.Alias: + def _to_serial(self) -> stys.Alias: return stys.Alias(name=self.name, bound=self.bound) def type_bound(self) -> TypeBound: @@ -369,7 +369,7 @@ class FunctionType(Type): def type_bound(self) -> TypeBound: return TypeBound.Copyable - def to_serial(self) -> stys.FunctionType: + def _to_serial(self) -> stys.FunctionType: return stys.FunctionType( input=ser_it(self.input), output=ser_it(self.output), @@ -433,9 +433,10 @@ class PolyFuncType(Type): def type_bound(self) -> TypeBound: return TypeBound.Copyable - def to_serial(self) -> stys.PolyFuncType: + def _to_serial(self) -> stys.PolyFuncType: return stys.PolyFuncType( - params=[p.to_serial_root() for p in self.params], body=self.body.to_serial() + params=[p._to_serial_root() for p in self.params], + body=self.body._to_serial(), ) def resolve(self, registry: ext.ExtensionRegistry) -> PolyFuncType: @@ -467,13 +468,13 @@ def type_bound(self) -> TypeBound: bounds.append(arg.ty.type_bound()) return TypeBound.join(*bounds) - def to_serial(self) -> stys.Opaque: + def _to_serial(self) -> stys.Opaque: assert self.type_def._extension is not None, "Extension must be initialised." return stys.Opaque( extension=self.type_def._extension.name, id=self.type_def.name, - args=[arg.to_serial_root() for arg in self.args], + args=[arg._to_serial_root() for arg in self.args], bound=self.type_bound(), ) @@ -487,11 +488,11 @@ class Opaque(Type): args: list[TypeArg] = field(default_factory=list) extension: ExtensionId = "" - def to_serial(self) -> stys.Opaque: + def _to_serial(self) -> stys.Opaque: return stys.Opaque( extension=self.extension, id=self.id, - args=[arg.to_serial_root() for arg in self.args], + args=[arg._to_serial_root() for arg in self.args], bound=self.bound, ) @@ -518,7 +519,7 @@ class _QubitDef(Type): def type_bound(self) -> TypeBound: return TypeBound.Any - def to_serial(self) -> stys.Qubit: + def _to_serial(self) -> stys.Qubit: return stys.Qubit() def __repr__(self) -> str: diff --git a/hugr-py/src/hugr/utils.py b/hugr-py/src/hugr/utils.py index 4e67adc67..83e002eda 100644 --- a/hugr-py/src/hugr/utils.py +++ b/hugr-py/src/hugr/utils.py @@ -181,7 +181,7 @@ def __repr__(self) -> str: class SerCollection(Protocol[S]): """Protocol for serializable objects.""" - def to_serial_root(self) -> S: + def _to_serial_root(self) -> S: """Convert to serializable root model.""" ... # pragma: no cover @@ -196,7 +196,7 @@ def deserialize(self) -> S: def ser_it(it: Iterable[SerCollection[S]]) -> list[S]: """Serialize an iterable of serializable objects.""" - return [v.to_serial_root() for v in it] + return [v._to_serial_root() for v in it] def deser_it(it: Iterable[DeserCollection[S]]) -> list[S]: diff --git a/hugr-py/src/hugr/val.py b/hugr-py/src/hugr/val.py index 7f0a8f249..dc7b2cc57 100644 --- a/hugr-py/src/hugr/val.py +++ b/hugr-py/src/hugr/val.py @@ -5,8 +5,8 @@ from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable -import hugr.serialization.ops as sops -import hugr.serialization.tys as stys +import hugr._serialization.ops as sops +import hugr._serialization.tys as stys from hugr import tys from hugr.utils import ser_it @@ -18,12 +18,12 @@ class Value(Protocol): """Abstract value definition. Must be serializable into a HUGR value.""" - def to_serial(self) -> sops.BaseValue: + def _to_serial(self) -> sops.BaseValue: """Convert to serializable model.""" ... # pragma: no cover - def to_serial_root(self) -> sops.Value: - return sops.Value(root=self.to_serial()) # type: ignore[arg-type] + def _to_serial_root(self) -> sops.Value: + return sops.Value(root=self._to_serial()) # type: ignore[arg-type] def type_(self) -> tys.Type: """Report the type of the value. @@ -58,10 +58,10 @@ def n_variants(self) -> int: def type_(self) -> tys.Sum: return self.typ - def to_serial(self) -> sops.SumValue: + def _to_serial(self) -> sops.SumValue: return sops.SumValue( tag=self.tag, - typ=stys.SumType(root=self.type_().to_serial()), + typ=stys.SumType(root=self.type_()._to_serial()), vs=ser_it(self.vals), ) @@ -139,8 +139,8 @@ def __init__(self, *vals: Value): ) # sops.TupleValue isn't an instance of sops.SumValue - # so mypy doesn't like the override of Sum.to_serial - def to_serial(self) -> sops.TupleValue: # type: ignore[override] + # so mypy doesn't like the override of Sum._to_serial + def _to_serial(self) -> sops.TupleValue: # type: ignore[override] return sops.TupleValue( vs=ser_it(self.vals), ) @@ -158,9 +158,9 @@ class Function(Value): def type_(self) -> tys.FunctionType: return self.body.root_op().inner_signature() - def to_serial(self) -> sops.FunctionValue: + def _to_serial(self) -> sops.FunctionValue: return sops.FunctionValue( - hugr=self.body.to_serial(), + hugr=self.body._to_serial(), ) @@ -179,9 +179,9 @@ class Extension(Value): def type_(self) -> tys.Type: return self.typ - def to_serial(self) -> sops.ExtensionValue: + def _to_serial(self) -> sops.ExtensionValue: return sops.ExtensionValue( - typ=self.typ.to_serial_root(), + typ=self.typ._to_serial_root(), value=sops.CustomConst(c=self.name, v=self.val), extensions=self.extensions, ) @@ -197,5 +197,5 @@ def to_value(self) -> Extension: def type_(self) -> tys.Type: return self.to_value().type_() - def to_serial(self) -> sops.ExtensionValue: - return self.to_value().to_serial() + def _to_serial(self) -> sops.ExtensionValue: + return self.to_value()._to_serial() diff --git a/hugr-py/tests/conftest.py b/hugr-py/tests/conftest.py index daf1f72a2..2b0ee0f98 100644 --- a/hugr-py/tests/conftest.py +++ b/hugr-py/tests/conftest.py @@ -11,9 +11,9 @@ from typing_extensions import Self from hugr import ext, tys +from hugr._serialization.serial_hugr import SerialHugr from hugr.hugr import Hugr from hugr.ops import AsExtOp, Command, DataflowOp, ExtOp, RegisteredOp -from hugr.serialization.serial_hugr import SerialHugr from hugr.std.float import FLOAT_T if TYPE_CHECKING: @@ -129,7 +129,7 @@ def _base_command() -> list[str]: def mermaid(h: Hugr): """Render the Hugr as a mermaid diagram for debugging.""" cmd = [*_base_command(), "mermaid", "-"] - _run_hugr_cmd(h.to_serial().to_json(), cmd) + _run_hugr_cmd(h._to_serial().to_json(), cmd) def validate( @@ -157,11 +157,11 @@ def validate( serial = h.to_json() starting_json = json.loads(serial) - h2 = Hugr.from_serial(SerialHugr.load_json(starting_json)) - roundtrip_json = json.loads(h2.to_serial().to_json()) + h2 = Hugr._from_serial(SerialHugr.load_json(starting_json)) + roundtrip_json = json.loads(h2._to_serial().to_json()) assert roundtrip_json == starting_json - if snap is not None: + if snap is not None and isinstance(h, Hugr): dot = h.render_dot() assert snap == dot.source diff --git a/hugr-py/tests/serialization/test_basic.py b/hugr-py/tests/serialization/test_basic.py index ccf43ca90..b0dc69f1c 100644 --- a/hugr-py/tests/serialization/test_basic.py +++ b/hugr-py/tests/serialization/test_basic.py @@ -1,4 +1,4 @@ -from hugr.serialization.serial_hugr import SerialHugr, serialization_version +from hugr._serialization.serial_hugr import SerialHugr, serialization_version def test_empty(): diff --git a/hugr-py/tests/serialization/test_extension.py b/hugr-py/tests/serialization/test_extension.py index 6d4425b7d..bd08055ec 100644 --- a/hugr-py/tests/serialization/test_extension.py +++ b/hugr-py/tests/serialization/test_extension.py @@ -1,6 +1,6 @@ from semver import Version -from hugr.serialization.extension import ( +from hugr._serialization.extension import ( ExplicitBound, Extension, OpDef, @@ -8,8 +8,8 @@ TypeDef, TypeDefBound, ) -from hugr.serialization.serial_hugr import SerialHugr, serialization_version -from hugr.serialization.tys import ( +from hugr._serialization.serial_hugr import SerialHugr, serialization_version +from hugr._serialization.tys import ( FunctionType, PolyFuncType, Type, diff --git a/hugr-py/tests/test_custom.py b/hugr-py/tests/test_custom.py index 8b14b8031..7d91066c4 100644 --- a/hugr-py/tests/test_custom.py +++ b/hugr-py/tests/test_custom.py @@ -59,7 +59,7 @@ def test_stringly_typed(): assert dfg.hugr[n].op == StringlyOp("world") validate(ext.Package([dfg.hugr], [STRINGLY_EXT])) - new_h = Hugr.from_serial(dfg.hugr.to_serial()) + new_h = Hugr._from_serial(dfg.hugr._to_serial()) assert isinstance(new_h[n].op, Custom) @@ -110,7 +110,7 @@ def test_custom_op(as_ext: AsExtOp, registry: ext.ExtensionRegistry): assert ExtOp.from_ext(ext_op) == ext_op assert type(as_ext).from_ext(ext_op) == as_ext - custom = as_ext.to_serial(Node(0)).deserialize() + custom = as_ext._to_serial(Node(0)).deserialize() assert isinstance(custom, Custom) # ExtOp compared to Custom via `to_custom` assert custom.resolve(registry) == ext_op @@ -152,14 +152,14 @@ def test_custom_bad_eq(): [FLOAT_T, int_t(5), _BOOL_LIST_T], ) def test_custom_type(ext_t: tys.ExtType, registry: ext.ExtensionRegistry): - opaque = ext_t.to_serial().deserialize() + opaque = ext_t._to_serial().deserialize() assert isinstance(opaque, tys.Opaque) assert opaque.resolve(registry) == ext_t assert opaque.resolve(ext.ExtensionRegistry()) == opaque f_t = tys.FunctionType.endo([ext_t]) - f_t_opaque = f_t.to_serial().deserialize() + f_t_opaque = f_t._to_serial().deserialize() assert isinstance(f_t_opaque.input[0], tys.Opaque) assert f_t_opaque.resolve(registry) == f_t diff --git a/hugr-py/tests/test_hugr_build.py b/hugr-py/tests/test_hugr_build.py index b9f2d997e..88d177604 100644 --- a/hugr-py/tests/test_hugr_build.py +++ b/hugr-py/tests/test_hugr_build.py @@ -129,7 +129,7 @@ def test_tuple(snapshot): a, b = h1.add_op(ops.UnpackTuple(), mt)[0, 1] h1.set_outputs(a, b) - assert h.hugr.to_serial() == h1.hugr.to_serial() + assert h.hugr._to_serial() == h1.hugr._to_serial() def test_multi_out(snapshot): diff --git a/scripts/generate_schema.py b/scripts/generate_schema.py index 908bdfa1a..98661914c 100644 --- a/scripts/generate_schema.py +++ b/scripts/generate_schema.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -"""Dumps the json schema for `hugr.serialization.SerialHugr` to a file. +"""Dumps the json schema for `hugr._serialization.SerialHugr` to a file. The schema is written to a file named `hugr_schema_v#.json` in the specified output directory. @@ -16,9 +16,9 @@ from pydantic import ConfigDict from pydantic.json_schema import models_json_schema -from hugr.serialization.extension import Extension, Package -from hugr.serialization.serial_hugr import SerialHugr -from hugr.serialization.testing_hugr import TestingHugr +from hugr._serialization.extension import Extension, Package +from hugr._serialization.serial_hugr import SerialHugr +from hugr._serialization.testing_hugr import TestingHugr def write_schema( From c76787374b101d81fc4a904b12787029552a6868 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 28 Aug 2024 13:38:39 +0100 Subject: [PATCH 2/3] fix ruff.toml --- ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 6aeaa0c53..7c8b3ba37 100644 --- a/ruff.toml +++ b/ruff.toml @@ -77,7 +77,7 @@ ignore = [ [lint.per-file-ignores] "hugr-py/tests/**" = ["D"] "hugr-py/docs/**" = ["D"] -"hugr-py/src/hugr/serialization/**" = ["D"] +"hugr-py/src/hugr/_serialization/**" = ["D"] "scripts/*" = ["T201", "EXE001", "D"] [lint.pydocstyle] From a3eaa49e3d2fd2526e89dee7542c6e15386ad322 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 28 Aug 2024 13:50:55 +0100 Subject: [PATCH 3/3] refactor!: fix naming conflicts in schema to remove any references to module python structure --- hugr-py/src/hugr/_serialization/ops.py | 10 +- hugr-py/src/hugr/ops.py | 8 +- hugr-py/src/hugr/val.py | 6 +- specification/schema/hugr_schema_live.json | 324 +++++++++--------- .../schema/hugr_schema_strict_live.json | 324 +++++++++--------- .../schema/testing_hugr_schema_live.json | 324 +++++++++--------- .../testing_hugr_schema_strict_live.json | 324 +++++++++--------- 7 files changed, 659 insertions(+), 661 deletions(-) diff --git a/hugr-py/src/hugr/_serialization/ops.py b/hugr-py/src/hugr/_serialization/ops.py index b6c9e77c1..993a9b070 100644 --- a/hugr-py/src/hugr/_serialization/ops.py +++ b/hugr-py/src/hugr/_serialization/ops.py @@ -103,7 +103,7 @@ class BaseValue(ABC, ConfiguredBaseModel): def deserialize(self) -> val.Value: ... -class ExtensionValue(BaseValue): +class CustomValue(BaseValue): """An extension constant value, that can check it is of a given [CustomType].""" v: Literal["Extension"] = Field(default="Extension", title="ValueTag") @@ -172,9 +172,7 @@ def deserialize(self) -> val.Value: class Value(RootModel): """A constant Value.""" - root: ExtensionValue | FunctionValue | TupleValue | SumValue = Field( - discriminator="v" - ) + root: CustomValue | FunctionValue | TupleValue | SumValue = Field(discriminator="v") model_config = ConfigDict(json_schema_extra={"required": ["v"]}) @@ -501,7 +499,7 @@ def deserialize(self) -> ops.CFG: ControlFlowOp = Conditional | TailLoop | CFG -class Extension(DataflowOp): +class ExtensionOp(DataflowOp): """A user-defined operation that can be downcasted by the extensions that define it. """ @@ -649,7 +647,7 @@ class OpType(RootModel): | CallIndirect | LoadConstant | LoadFunction - | Extension + | ExtensionOp | Noop | MakeTuple | UnpackTuple diff --git a/hugr-py/src/hugr/ops.py b/hugr-py/src/hugr/ops.py index 90586d301..1edcebffe 100644 --- a/hugr-py/src/hugr/ops.py +++ b/hugr-py/src/hugr/ops.py @@ -279,7 +279,7 @@ def __eq__(self, other: object) -> bool: def outer_signature(self) -> tys.FunctionType: return self.ext_op.outer_signature() - def _to_serial(self, parent: Node) -> sops.Extension: + def _to_serial(self, parent: Node) -> sops.ExtensionOp: return self.ext_op._to_serial(parent) @property @@ -297,8 +297,8 @@ class Custom(DataflowOp): extension: tys.ExtensionId = "" args: list[tys.TypeArg] = field(default_factory=list) - def _to_serial(self, parent: Node) -> sops.Extension: - return sops.Extension( + def _to_serial(self, parent: Node) -> sops.ExtensionOp: + return sops.ExtensionOp( parent=parent.idx, extension=self.extension, name=self.name, @@ -366,7 +366,7 @@ def to_custom_op(self) -> Custom: args=self.args, ) - def _to_serial(self, parent: Node) -> sops.Extension: + def _to_serial(self, parent: Node) -> sops.ExtensionOp: return self.to_custom_op()._to_serial(parent) def op_def(self) -> ext.OpDef: diff --git a/hugr-py/src/hugr/val.py b/hugr-py/src/hugr/val.py index dc7b2cc57..210b19dff 100644 --- a/hugr-py/src/hugr/val.py +++ b/hugr-py/src/hugr/val.py @@ -179,8 +179,8 @@ class Extension(Value): def type_(self) -> tys.Type: return self.typ - def _to_serial(self) -> sops.ExtensionValue: - return sops.ExtensionValue( + def _to_serial(self) -> sops.CustomValue: + return sops.CustomValue( typ=self.typ._to_serial_root(), value=sops.CustomConst(c=self.name, v=self.val), extensions=self.extensions, @@ -197,5 +197,5 @@ def to_value(self) -> Extension: def type_(self) -> tys.Type: return self.to_value().type_() - def _to_serial(self) -> sops.ExtensionValue: + def _to_serial(self) -> sops.CustomValue: return self.to_value()._to_serial() diff --git a/specification/schema/hugr_schema_live.json b/specification/schema/hugr_schema_live.json index 0b8096a43..18c8d6a40 100644 --- a/specification/schema/hugr_schema_live.json +++ b/specification/schema/hugr_schema_live.json @@ -396,6 +396,41 @@ "title": "CustomConst", "type": "object" }, + "CustomValue": { + "additionalProperties": true, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "v": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "extensions": { + "items": { + "type": "string" + }, + "title": "Extensions", + "type": "array" + }, + "typ": { + "$ref": "#/$defs/Type" + }, + "value": { + "$ref": "#/$defs/CustomConst" + } + }, + "required": [ + "extensions", + "typ", + "value" + ], + "title": "CustomValue", + "type": "object" + }, "DFG": { "additionalProperties": true, "description": "A simply nested dataflow graph.", @@ -532,6 +567,128 @@ "title": "ExplicitBound", "type": "object" }, + "Extension": { + "properties": { + "version": { + "title": "Version", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "extension_reqs": { + "items": { + "type": "string" + }, + "title": "Extension Reqs", + "type": "array", + "uniqueItems": true + }, + "types": { + "additionalProperties": { + "$ref": "#/$defs/TypeDef" + }, + "title": "Types", + "type": "object" + }, + "values": { + "additionalProperties": { + "$ref": "#/$defs/ExtensionValue" + }, + "title": "Values", + "type": "object" + }, + "operations": { + "additionalProperties": { + "$ref": "#/$defs/OpDef" + }, + "title": "Operations", + "type": "object" + } + }, + "required": [ + "version", + "name", + "extension_reqs", + "types", + "values", + "operations" + ], + "title": "Extension", + "type": "object" + }, + "ExtensionOp": { + "additionalProperties": true, + "description": "A user-defined operation that can be downcasted by the extensions that define it.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "op": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + }, + "description": { + "default": "", + "title": "Description", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "parent", + "extension", + "name" + ], + "title": "ExtensionOp", + "type": "object" + }, + "ExtensionValue": { + "properties": { + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "typed_value": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "extension", + "name", + "typed_value" + ], + "title": "ExtensionValue", + "type": "object" + }, "ExtensionsArg": { "additionalProperties": true, "properties": { @@ -1104,7 +1261,7 @@ "DFG": "#/$defs/DFG", "DataflowBlock": "#/$defs/DataflowBlock", "ExitBlock": "#/$defs/ExitBlock", - "Extension": "#/$defs/hugr__serialization__ops__Extension", + "Extension": "#/$defs/ExtensionOp", "FuncDecl": "#/$defs/FuncDecl", "FuncDefn": "#/$defs/FuncDefn", "Input": "#/$defs/Input", @@ -1171,7 +1328,7 @@ "$ref": "#/$defs/LoadFunction" }, { - "$ref": "#/$defs/hugr__serialization__ops__Extension" + "$ref": "#/$defs/ExtensionOp" }, { "$ref": "#/$defs/Noop" @@ -1287,7 +1444,7 @@ }, "extensions": { "items": { - "$ref": "#/$defs/hugr__serialization__extension__Extension" + "$ref": "#/$defs/Extension" }, "title": "Extensions", "type": "array" @@ -2060,7 +2217,7 @@ "description": "A constant Value.", "discriminator": { "mapping": { - "Extension": "#/$defs/hugr__serialization__ops__ExtensionValue", + "Extension": "#/$defs/CustomValue", "Function": "#/$defs/FunctionValue", "Sum": "#/$defs/SumValue", "Tuple": "#/$defs/TupleValue" @@ -2069,7 +2226,7 @@ }, "oneOf": [ { - "$ref": "#/$defs/hugr__serialization__ops__ExtensionValue" + "$ref": "#/$defs/CustomValue" }, { "$ref": "#/$defs/FunctionValue" @@ -2140,163 +2297,6 @@ ], "title": "VariableArg", "type": "object" - }, - "hugr__serialization__extension__Extension": { - "properties": { - "version": { - "title": "Version", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "extension_reqs": { - "items": { - "type": "string" - }, - "title": "Extension Reqs", - "type": "array", - "uniqueItems": true - }, - "types": { - "additionalProperties": { - "$ref": "#/$defs/TypeDef" - }, - "title": "Types", - "type": "object" - }, - "values": { - "additionalProperties": { - "$ref": "#/$defs/hugr__serialization__extension__ExtensionValue" - }, - "title": "Values", - "type": "object" - }, - "operations": { - "additionalProperties": { - "$ref": "#/$defs/OpDef" - }, - "title": "Operations", - "type": "object" - } - }, - "required": [ - "version", - "name", - "extension_reqs", - "types", - "values", - "operations" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__extension__ExtensionValue": { - "properties": { - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "typed_value": { - "$ref": "#/$defs/Value" - } - }, - "required": [ - "extension", - "name", - "typed_value" - ], - "title": "ExtensionValue", - "type": "object" - }, - "hugr__serialization__ops__Extension": { - "additionalProperties": true, - "description": "A user-defined operation that can be downcasted by the extensions that define it.", - "properties": { - "parent": { - "title": "Parent", - "type": "integer" - }, - "op": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "Op", - "type": "string" - }, - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "signature": { - "$ref": "#/$defs/FunctionType" - }, - "description": { - "default": "", - "title": "Description", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - } - }, - "required": [ - "parent", - "extension", - "name" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__ops__ExtensionValue": { - "additionalProperties": true, - "description": "An extension constant value, that can check it is of a given [CustomType].", - "properties": { - "v": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "ValueTag", - "type": "string" - }, - "extensions": { - "items": { - "type": "string" - }, - "title": "Extensions", - "type": "array" - }, - "typ": { - "$ref": "#/$defs/Type" - }, - "value": { - "$ref": "#/$defs/CustomConst" - } - }, - "required": [ - "extensions", - "typ", - "value" - ], - "title": "ExtensionValue", - "type": "object" } }, "title": "HUGR schema" diff --git a/specification/schema/hugr_schema_strict_live.json b/specification/schema/hugr_schema_strict_live.json index ba23a6233..4a2f6b7d0 100644 --- a/specification/schema/hugr_schema_strict_live.json +++ b/specification/schema/hugr_schema_strict_live.json @@ -396,6 +396,41 @@ "title": "CustomConst", "type": "object" }, + "CustomValue": { + "additionalProperties": false, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "v": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "extensions": { + "items": { + "type": "string" + }, + "title": "Extensions", + "type": "array" + }, + "typ": { + "$ref": "#/$defs/Type" + }, + "value": { + "$ref": "#/$defs/CustomConst" + } + }, + "required": [ + "extensions", + "typ", + "value" + ], + "title": "CustomValue", + "type": "object" + }, "DFG": { "additionalProperties": false, "description": "A simply nested dataflow graph.", @@ -532,6 +567,128 @@ "title": "ExplicitBound", "type": "object" }, + "Extension": { + "properties": { + "version": { + "title": "Version", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "extension_reqs": { + "items": { + "type": "string" + }, + "title": "Extension Reqs", + "type": "array", + "uniqueItems": true + }, + "types": { + "additionalProperties": { + "$ref": "#/$defs/TypeDef" + }, + "title": "Types", + "type": "object" + }, + "values": { + "additionalProperties": { + "$ref": "#/$defs/ExtensionValue" + }, + "title": "Values", + "type": "object" + }, + "operations": { + "additionalProperties": { + "$ref": "#/$defs/OpDef" + }, + "title": "Operations", + "type": "object" + } + }, + "required": [ + "version", + "name", + "extension_reqs", + "types", + "values", + "operations" + ], + "title": "Extension", + "type": "object" + }, + "ExtensionOp": { + "additionalProperties": false, + "description": "A user-defined operation that can be downcasted by the extensions that define it.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "op": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + }, + "description": { + "default": "", + "title": "Description", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "parent", + "extension", + "name" + ], + "title": "ExtensionOp", + "type": "object" + }, + "ExtensionValue": { + "properties": { + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "typed_value": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "extension", + "name", + "typed_value" + ], + "title": "ExtensionValue", + "type": "object" + }, "ExtensionsArg": { "additionalProperties": false, "properties": { @@ -1104,7 +1261,7 @@ "DFG": "#/$defs/DFG", "DataflowBlock": "#/$defs/DataflowBlock", "ExitBlock": "#/$defs/ExitBlock", - "Extension": "#/$defs/hugr__serialization__ops__Extension", + "Extension": "#/$defs/ExtensionOp", "FuncDecl": "#/$defs/FuncDecl", "FuncDefn": "#/$defs/FuncDefn", "Input": "#/$defs/Input", @@ -1171,7 +1328,7 @@ "$ref": "#/$defs/LoadFunction" }, { - "$ref": "#/$defs/hugr__serialization__ops__Extension" + "$ref": "#/$defs/ExtensionOp" }, { "$ref": "#/$defs/Noop" @@ -1287,7 +1444,7 @@ }, "extensions": { "items": { - "$ref": "#/$defs/hugr__serialization__extension__Extension" + "$ref": "#/$defs/Extension" }, "title": "Extensions", "type": "array" @@ -2060,7 +2217,7 @@ "description": "A constant Value.", "discriminator": { "mapping": { - "Extension": "#/$defs/hugr__serialization__ops__ExtensionValue", + "Extension": "#/$defs/CustomValue", "Function": "#/$defs/FunctionValue", "Sum": "#/$defs/SumValue", "Tuple": "#/$defs/TupleValue" @@ -2069,7 +2226,7 @@ }, "oneOf": [ { - "$ref": "#/$defs/hugr__serialization__ops__ExtensionValue" + "$ref": "#/$defs/CustomValue" }, { "$ref": "#/$defs/FunctionValue" @@ -2140,163 +2297,6 @@ ], "title": "VariableArg", "type": "object" - }, - "hugr__serialization__extension__Extension": { - "properties": { - "version": { - "title": "Version", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "extension_reqs": { - "items": { - "type": "string" - }, - "title": "Extension Reqs", - "type": "array", - "uniqueItems": true - }, - "types": { - "additionalProperties": { - "$ref": "#/$defs/TypeDef" - }, - "title": "Types", - "type": "object" - }, - "values": { - "additionalProperties": { - "$ref": "#/$defs/hugr__serialization__extension__ExtensionValue" - }, - "title": "Values", - "type": "object" - }, - "operations": { - "additionalProperties": { - "$ref": "#/$defs/OpDef" - }, - "title": "Operations", - "type": "object" - } - }, - "required": [ - "version", - "name", - "extension_reqs", - "types", - "values", - "operations" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__extension__ExtensionValue": { - "properties": { - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "typed_value": { - "$ref": "#/$defs/Value" - } - }, - "required": [ - "extension", - "name", - "typed_value" - ], - "title": "ExtensionValue", - "type": "object" - }, - "hugr__serialization__ops__Extension": { - "additionalProperties": false, - "description": "A user-defined operation that can be downcasted by the extensions that define it.", - "properties": { - "parent": { - "title": "Parent", - "type": "integer" - }, - "op": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "Op", - "type": "string" - }, - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "signature": { - "$ref": "#/$defs/FunctionType" - }, - "description": { - "default": "", - "title": "Description", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - } - }, - "required": [ - "parent", - "extension", - "name" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__ops__ExtensionValue": { - "additionalProperties": false, - "description": "An extension constant value, that can check it is of a given [CustomType].", - "properties": { - "v": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "ValueTag", - "type": "string" - }, - "extensions": { - "items": { - "type": "string" - }, - "title": "Extensions", - "type": "array" - }, - "typ": { - "$ref": "#/$defs/Type" - }, - "value": { - "$ref": "#/$defs/CustomConst" - } - }, - "required": [ - "extensions", - "typ", - "value" - ], - "title": "ExtensionValue", - "type": "object" } }, "title": "HUGR schema" diff --git a/specification/schema/testing_hugr_schema_live.json b/specification/schema/testing_hugr_schema_live.json index b58866307..f454c556c 100644 --- a/specification/schema/testing_hugr_schema_live.json +++ b/specification/schema/testing_hugr_schema_live.json @@ -396,6 +396,41 @@ "title": "CustomConst", "type": "object" }, + "CustomValue": { + "additionalProperties": true, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "v": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "extensions": { + "items": { + "type": "string" + }, + "title": "Extensions", + "type": "array" + }, + "typ": { + "$ref": "#/$defs/Type" + }, + "value": { + "$ref": "#/$defs/CustomConst" + } + }, + "required": [ + "extensions", + "typ", + "value" + ], + "title": "CustomValue", + "type": "object" + }, "DFG": { "additionalProperties": true, "description": "A simply nested dataflow graph.", @@ -532,6 +567,128 @@ "title": "ExplicitBound", "type": "object" }, + "Extension": { + "properties": { + "version": { + "title": "Version", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "extension_reqs": { + "items": { + "type": "string" + }, + "title": "Extension Reqs", + "type": "array", + "uniqueItems": true + }, + "types": { + "additionalProperties": { + "$ref": "#/$defs/TypeDef" + }, + "title": "Types", + "type": "object" + }, + "values": { + "additionalProperties": { + "$ref": "#/$defs/ExtensionValue" + }, + "title": "Values", + "type": "object" + }, + "operations": { + "additionalProperties": { + "$ref": "#/$defs/OpDef" + }, + "title": "Operations", + "type": "object" + } + }, + "required": [ + "version", + "name", + "extension_reqs", + "types", + "values", + "operations" + ], + "title": "Extension", + "type": "object" + }, + "ExtensionOp": { + "additionalProperties": true, + "description": "A user-defined operation that can be downcasted by the extensions that define it.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "op": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + }, + "description": { + "default": "", + "title": "Description", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "parent", + "extension", + "name" + ], + "title": "ExtensionOp", + "type": "object" + }, + "ExtensionValue": { + "properties": { + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "typed_value": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "extension", + "name", + "typed_value" + ], + "title": "ExtensionValue", + "type": "object" + }, "ExtensionsArg": { "additionalProperties": true, "properties": { @@ -1104,7 +1261,7 @@ "DFG": "#/$defs/DFG", "DataflowBlock": "#/$defs/DataflowBlock", "ExitBlock": "#/$defs/ExitBlock", - "Extension": "#/$defs/hugr__serialization__ops__Extension", + "Extension": "#/$defs/ExtensionOp", "FuncDecl": "#/$defs/FuncDecl", "FuncDefn": "#/$defs/FuncDefn", "Input": "#/$defs/Input", @@ -1171,7 +1328,7 @@ "$ref": "#/$defs/LoadFunction" }, { - "$ref": "#/$defs/hugr__serialization__ops__Extension" + "$ref": "#/$defs/ExtensionOp" }, { "$ref": "#/$defs/Noop" @@ -1287,7 +1444,7 @@ }, "extensions": { "items": { - "$ref": "#/$defs/hugr__serialization__extension__Extension" + "$ref": "#/$defs/Extension" }, "title": "Extensions", "type": "array" @@ -2138,7 +2295,7 @@ "description": "A constant Value.", "discriminator": { "mapping": { - "Extension": "#/$defs/hugr__serialization__ops__ExtensionValue", + "Extension": "#/$defs/CustomValue", "Function": "#/$defs/FunctionValue", "Sum": "#/$defs/SumValue", "Tuple": "#/$defs/TupleValue" @@ -2147,7 +2304,7 @@ }, "oneOf": [ { - "$ref": "#/$defs/hugr__serialization__ops__ExtensionValue" + "$ref": "#/$defs/CustomValue" }, { "$ref": "#/$defs/FunctionValue" @@ -2218,163 +2375,6 @@ ], "title": "VariableArg", "type": "object" - }, - "hugr__serialization__extension__Extension": { - "properties": { - "version": { - "title": "Version", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "extension_reqs": { - "items": { - "type": "string" - }, - "title": "Extension Reqs", - "type": "array", - "uniqueItems": true - }, - "types": { - "additionalProperties": { - "$ref": "#/$defs/TypeDef" - }, - "title": "Types", - "type": "object" - }, - "values": { - "additionalProperties": { - "$ref": "#/$defs/hugr__serialization__extension__ExtensionValue" - }, - "title": "Values", - "type": "object" - }, - "operations": { - "additionalProperties": { - "$ref": "#/$defs/OpDef" - }, - "title": "Operations", - "type": "object" - } - }, - "required": [ - "version", - "name", - "extension_reqs", - "types", - "values", - "operations" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__extension__ExtensionValue": { - "properties": { - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "typed_value": { - "$ref": "#/$defs/Value" - } - }, - "required": [ - "extension", - "name", - "typed_value" - ], - "title": "ExtensionValue", - "type": "object" - }, - "hugr__serialization__ops__Extension": { - "additionalProperties": true, - "description": "A user-defined operation that can be downcasted by the extensions that define it.", - "properties": { - "parent": { - "title": "Parent", - "type": "integer" - }, - "op": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "Op", - "type": "string" - }, - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "signature": { - "$ref": "#/$defs/FunctionType" - }, - "description": { - "default": "", - "title": "Description", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - } - }, - "required": [ - "parent", - "extension", - "name" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__ops__ExtensionValue": { - "additionalProperties": true, - "description": "An extension constant value, that can check it is of a given [CustomType].", - "properties": { - "v": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "ValueTag", - "type": "string" - }, - "extensions": { - "items": { - "type": "string" - }, - "title": "Extensions", - "type": "array" - }, - "typ": { - "$ref": "#/$defs/Type" - }, - "value": { - "$ref": "#/$defs/CustomConst" - } - }, - "required": [ - "extensions", - "typ", - "value" - ], - "title": "ExtensionValue", - "type": "object" } }, "title": "HUGR schema" diff --git a/specification/schema/testing_hugr_schema_strict_live.json b/specification/schema/testing_hugr_schema_strict_live.json index ffa2b42f4..9fa982403 100644 --- a/specification/schema/testing_hugr_schema_strict_live.json +++ b/specification/schema/testing_hugr_schema_strict_live.json @@ -396,6 +396,41 @@ "title": "CustomConst", "type": "object" }, + "CustomValue": { + "additionalProperties": false, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "v": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "extensions": { + "items": { + "type": "string" + }, + "title": "Extensions", + "type": "array" + }, + "typ": { + "$ref": "#/$defs/Type" + }, + "value": { + "$ref": "#/$defs/CustomConst" + } + }, + "required": [ + "extensions", + "typ", + "value" + ], + "title": "CustomValue", + "type": "object" + }, "DFG": { "additionalProperties": false, "description": "A simply nested dataflow graph.", @@ -532,6 +567,128 @@ "title": "ExplicitBound", "type": "object" }, + "Extension": { + "properties": { + "version": { + "title": "Version", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "extension_reqs": { + "items": { + "type": "string" + }, + "title": "Extension Reqs", + "type": "array", + "uniqueItems": true + }, + "types": { + "additionalProperties": { + "$ref": "#/$defs/TypeDef" + }, + "title": "Types", + "type": "object" + }, + "values": { + "additionalProperties": { + "$ref": "#/$defs/ExtensionValue" + }, + "title": "Values", + "type": "object" + }, + "operations": { + "additionalProperties": { + "$ref": "#/$defs/OpDef" + }, + "title": "Operations", + "type": "object" + } + }, + "required": [ + "version", + "name", + "extension_reqs", + "types", + "values", + "operations" + ], + "title": "Extension", + "type": "object" + }, + "ExtensionOp": { + "additionalProperties": false, + "description": "A user-defined operation that can be downcasted by the extensions that define it.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "op": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + }, + "description": { + "default": "", + "title": "Description", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "parent", + "extension", + "name" + ], + "title": "ExtensionOp", + "type": "object" + }, + "ExtensionValue": { + "properties": { + "extension": { + "title": "Extension", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "typed_value": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "extension", + "name", + "typed_value" + ], + "title": "ExtensionValue", + "type": "object" + }, "ExtensionsArg": { "additionalProperties": false, "properties": { @@ -1104,7 +1261,7 @@ "DFG": "#/$defs/DFG", "DataflowBlock": "#/$defs/DataflowBlock", "ExitBlock": "#/$defs/ExitBlock", - "Extension": "#/$defs/hugr__serialization__ops__Extension", + "Extension": "#/$defs/ExtensionOp", "FuncDecl": "#/$defs/FuncDecl", "FuncDefn": "#/$defs/FuncDefn", "Input": "#/$defs/Input", @@ -1171,7 +1328,7 @@ "$ref": "#/$defs/LoadFunction" }, { - "$ref": "#/$defs/hugr__serialization__ops__Extension" + "$ref": "#/$defs/ExtensionOp" }, { "$ref": "#/$defs/Noop" @@ -1287,7 +1444,7 @@ }, "extensions": { "items": { - "$ref": "#/$defs/hugr__serialization__extension__Extension" + "$ref": "#/$defs/Extension" }, "title": "Extensions", "type": "array" @@ -2138,7 +2295,7 @@ "description": "A constant Value.", "discriminator": { "mapping": { - "Extension": "#/$defs/hugr__serialization__ops__ExtensionValue", + "Extension": "#/$defs/CustomValue", "Function": "#/$defs/FunctionValue", "Sum": "#/$defs/SumValue", "Tuple": "#/$defs/TupleValue" @@ -2147,7 +2304,7 @@ }, "oneOf": [ { - "$ref": "#/$defs/hugr__serialization__ops__ExtensionValue" + "$ref": "#/$defs/CustomValue" }, { "$ref": "#/$defs/FunctionValue" @@ -2218,163 +2375,6 @@ ], "title": "VariableArg", "type": "object" - }, - "hugr__serialization__extension__Extension": { - "properties": { - "version": { - "title": "Version", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "extension_reqs": { - "items": { - "type": "string" - }, - "title": "Extension Reqs", - "type": "array", - "uniqueItems": true - }, - "types": { - "additionalProperties": { - "$ref": "#/$defs/TypeDef" - }, - "title": "Types", - "type": "object" - }, - "values": { - "additionalProperties": { - "$ref": "#/$defs/hugr__serialization__extension__ExtensionValue" - }, - "title": "Values", - "type": "object" - }, - "operations": { - "additionalProperties": { - "$ref": "#/$defs/OpDef" - }, - "title": "Operations", - "type": "object" - } - }, - "required": [ - "version", - "name", - "extension_reqs", - "types", - "values", - "operations" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__extension__ExtensionValue": { - "properties": { - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "typed_value": { - "$ref": "#/$defs/Value" - } - }, - "required": [ - "extension", - "name", - "typed_value" - ], - "title": "ExtensionValue", - "type": "object" - }, - "hugr__serialization__ops__Extension": { - "additionalProperties": false, - "description": "A user-defined operation that can be downcasted by the extensions that define it.", - "properties": { - "parent": { - "title": "Parent", - "type": "integer" - }, - "op": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "Op", - "type": "string" - }, - "extension": { - "title": "Extension", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "signature": { - "$ref": "#/$defs/FunctionType" - }, - "description": { - "default": "", - "title": "Description", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - } - }, - "required": [ - "parent", - "extension", - "name" - ], - "title": "Extension", - "type": "object" - }, - "hugr__serialization__ops__ExtensionValue": { - "additionalProperties": false, - "description": "An extension constant value, that can check it is of a given [CustomType].", - "properties": { - "v": { - "const": "Extension", - "default": "Extension", - "enum": [ - "Extension" - ], - "title": "ValueTag", - "type": "string" - }, - "extensions": { - "items": { - "type": "string" - }, - "title": "Extensions", - "type": "array" - }, - "typ": { - "$ref": "#/$defs/Type" - }, - "value": { - "$ref": "#/$defs/CustomConst" - } - }, - "required": [ - "extensions", - "typ", - "value" - ], - "title": "ExtensionValue", - "type": "object" } }, "title": "HUGR schema"