diff --git a/hugr-py/src/hugr/serialization/ops.py b/hugr-py/src/hugr/serialization/ops.py index d722249a4..8ec8dcdab 100644 --- a/hugr-py/src/hugr/serialization/ops.py +++ b/hugr-py/src/hugr/serialization/ops.py @@ -126,6 +126,10 @@ class Value(RootModel): discriminator="v" ) + class Config: + # Needed to avoid random '\n's in the pydantic description + json_schema_extra = {"required": ["v"]} + class Const(BaseOp): """A Const operation definition.""" @@ -133,11 +137,6 @@ class Const(BaseOp): op: Literal["Const"] = "Const" v: Value = Field() - class Config: - json_schema_extra = { - "required": ["op", "parent", "v"], - } - # ----------------------------------------------- # --------------- BasicBlock types ------------------ @@ -151,7 +150,7 @@ class DataflowBlock(BaseOp): op: Literal["DataflowBlock"] = "DataflowBlock" inputs: TypeRow = Field(default_factory=list) other_outputs: TypeRow = Field(default_factory=list) - sum_rows: list[TypeRow] = Field(default_factory=list) + sum_rows: list[TypeRow] extension_delta: ExtensionSet = Field(default_factory=list) def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None: @@ -161,26 +160,18 @@ def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None: def insert_child_dfg_signature(self, inputs: TypeRow, outputs: TypeRow) -> None: self.inputs = inputs pred = outputs[0].root - assert isinstance(pred, tys.TaggedSumType) - if isinstance(pred.st.root, tys.UnitSum): - self.sum_rows = [[] for _ in range(pred.st.root.size)] + assert isinstance(pred, tys.SumType) + if isinstance(pred.root, tys.UnitSum): + self.sum_rows = [[] for _ in range(pred.root.size)] else: self.sum_rows = [] - for variant in pred.st.root.rows: + for variant in pred.root.rows: self.sum_rows.append(variant) self.other_outputs = outputs[1:] class Config: # Needed to avoid random '\n's in the pydantic description json_schema_extra = { - "required": [ - "parent", - "op", - "inputs", - "other_outputs", - "sum_rows", - "extension_delta", - ], "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", } @@ -193,9 +184,9 @@ class ExitBlock(BaseOp): cfg_outputs: TypeRow class Config: - # Needed to avoid random '\n's in the pydantic description json_schema_extra = { - "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output." + # Needed to avoid random '\n's in the pydantic description + "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", } @@ -322,8 +313,8 @@ def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None: # First port is a predicate, i.e. a sum of tuple types. We need to unpack # those into a list of type rows pred = in_types[0] - assert isinstance(pred.root, tys.TaggedSumType) - sum = pred.root.st.root + assert isinstance(pred.root, tys.SumType) + sum = pred.root.root if isinstance(sum, tys.UnitSum): self.sum_rows = [[] for _ in range(sum.size)] else: @@ -501,6 +492,9 @@ class OpType(RootModel): | AliasDefn ) = Field(discriminator="op") + class Config: + json_schema_extra = {"required": ["parent", "op"]} + # -------------------------------------- # --------------- OpDef ---------------- diff --git a/hugr-py/src/hugr/serialization/tys.py b/hugr-py/src/hugr/serialization/tys.py index c9f116af5..c66b78bb1 100644 --- a/hugr-py/src/hugr/serialization/tys.py +++ b/hugr-py/src/hugr/serialization/tys.py @@ -48,8 +48,8 @@ class ConfiguredBaseModel(BaseModel): model_config = default_model_config @classmethod - def set_model_config(cls, config: ConfigDict): - cls.model_config = config + def update_model_config(cls, config: ConfigDict): + cls.model_config.update(config) # -------------------------------------------- @@ -99,6 +99,9 @@ class TypeParam(RootModel): WrapValidator(_json_custom_error_validator), ] = Field(discriminator="tp") + class Config: + json_schema_extra = {"required": ["tp"]} + # ------------------------------------------ # --------------- TypeArg ------------------ @@ -150,6 +153,9 @@ class TypeArg(RootModel): WrapValidator(_json_custom_error_validator), ] = Field(discriminator="tya") + class Config: + json_schema_extra = {"required": ["tya"]} + # -------------------------------------------- # --------------- Container ------------------ @@ -170,6 +176,7 @@ class Array(MultiContainer): class UnitSum(ConfiguredBaseModel): """Simple sum type where all variants are empty tuples.""" + t: Literal["Sum"] = "Sum" s: Literal["Unit"] = "Unit" size: int @@ -177,6 +184,7 @@ class UnitSum(ConfiguredBaseModel): class GeneralSum(ConfiguredBaseModel): """General sum type that explicitly stores the types of the variants.""" + t: Literal["Sum"] = "Sum" s: Literal["General"] = "General" rows: list["TypeRow"] @@ -184,10 +192,8 @@ class GeneralSum(ConfiguredBaseModel): class SumType(RootModel): root: Union[UnitSum, GeneralSum] = Field(discriminator="s") - -class TaggedSumType(ConfiguredBaseModel): - t: Literal["Sum"] = "Sum" - st: SumType + class Config: + json_schema_extra = {"required": ["s"]} # ---------------------------------------------- @@ -280,17 +286,13 @@ def join(*bs: "TypeBound") -> "TypeBound": class Opaque(ConfiguredBaseModel): """An opaque Type that can be downcasted by the extensions that define it.""" + t: Literal["Opaque"] = "Opaque" extension: ExtensionId id: str # Unique identifier of the opaque type. args: list[TypeArg] bound: TypeBound -class TaggedOpaque(ConfiguredBaseModel): - t: Literal["Opaque"] = "Opaque" - o: Opaque - - class Alias(ConfiguredBaseModel): """An Alias Type""" @@ -314,17 +316,13 @@ class Type(RootModel): """A HUGR type.""" root: Annotated[ - Qubit - | Variable - | USize - | FunctionType - | Array - | TaggedSumType - | TaggedOpaque - | Alias, + Qubit | Variable | USize | FunctionType | Array | SumType | Opaque | Alias, WrapValidator(_json_custom_error_validator), ] = Field(discriminator="t") + class Config: + json_schema_extra = {"required": ["t"]} + # ------------------------------------------- # --------------- TypeRow ------------------- @@ -365,11 +363,9 @@ def model_rebuild( config: ConfigDict = ConfigDict(), **kwargs, ): - new_config = default_model_config.copy() - new_config.update(config) for c in classes.values(): if issubclass(c, ConfiguredBaseModel): - c.set_model_config(new_config) + c.update_model_config(config) c.model_rebuild(**kwargs) diff --git a/hugr/src/types/serialize.rs b/hugr/src/types/serialize.rs index 83718a5c5..4a263af14 100644 --- a/hugr/src/types/serialize.rs +++ b/hugr/src/types/serialize.rs @@ -11,9 +11,9 @@ pub(super) enum SerSimpleType { Q, I, G(Box), - Sum { st: SumType }, + Sum(SumType), Array { inner: Box, len: u64 }, - Opaque { o: CustomType }, + Opaque(CustomType), Alias(AliasDecl), V { i: usize, b: TypeBound }, } @@ -29,11 +29,11 @@ impl From for SerSimpleType { // TODO short circuiting for array. let Type(value, _) = value; match value { - TypeEnum::Extension(o) => SerSimpleType::Opaque { o }, + TypeEnum::Extension(o) => SerSimpleType::Opaque(o), TypeEnum::Alias(a) => SerSimpleType::Alias(a), TypeEnum::Function(sig) => SerSimpleType::G(sig), TypeEnum::Variable(i, b) => SerSimpleType::V { i, b }, - TypeEnum::Sum(st) => SerSimpleType::Sum { st }, + TypeEnum::Sum(st) => SerSimpleType::Sum(st), } } } @@ -44,11 +44,11 @@ impl From for Type { SerSimpleType::Q => QB_T, SerSimpleType::I => USIZE_T, SerSimpleType::G(sig) => Type::new_function(*sig), - SerSimpleType::Sum { st } => st.into(), + SerSimpleType::Sum(st) => st.into(), SerSimpleType::Array { inner, len } => { array_type(TypeArg::BoundedNat { n: len }, (*inner).into()) } - SerSimpleType::Opaque { o } => Type::new_extension(o), + SerSimpleType::Opaque(o) => Type::new_extension(o), SerSimpleType::Alias(a) => Type::new_alias(a), SerSimpleType::V { i, b } => Type::new_var_use(i, b), } diff --git a/specification/schema/.gitattributes b/specification/schema/.gitattributes index 94ff3e30f..266907b7a 100644 --- a/specification/schema/.gitattributes +++ b/specification/schema/.gitattributes @@ -1 +1 @@ -*schema_v*.json -diff +*schema*.json -diff diff --git a/specification/schema/hugr_schema_strict_v1.json b/specification/schema/hugr_schema_strict_v1.json index 6dde15c17..056ceeaf2 100644 --- a/specification/schema/hugr_schema_strict_v1.json +++ b/specification/schema/hugr_schema_strict_v1.json @@ -247,7 +247,7 @@ }, "Call": { "additionalProperties": false, - "description": "Call a function directly.\n\nThe first port is connected to the def/declare of the function being called\ndirectly, with a `ConstE` edge. The signature of the remaining ports matches\nthe function being called.", + "description": "Operation to call a function directly. The first port is connected to the def/declare of the function being called directly, with a `Static` edge. The signature of the remaining ports matches the function being called.", "properties": { "parent": { "title": "Parent", @@ -518,7 +518,7 @@ }, "CustomOp": { "additionalProperties": false, - "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "description": "A user-defined operation that can be downcasted by the extensions that define it.", "properties": { "parent": { "title": "Parent", @@ -624,7 +624,7 @@ }, "DataflowBlock": { "additionalProperties": false, - "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", "properties": { "parent": { "title": "Parent", @@ -687,14 +687,15 @@ } }, "required": [ - "parent" + "parent", + "sum_rows" ], "title": "DataflowBlock", "type": "object" }, "ExitBlock": { "additionalProperties": false, - "description": "The single exit node of the CFG, has no children, stores the types of\nthe CFG node output.", + "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", "properties": { "parent": { "title": "Parent", @@ -914,7 +915,7 @@ }, "FunctionType": { "additionalProperties": false, - "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", "properties": { "t": { "const": "G", @@ -981,6 +982,15 @@ "additionalProperties": false, "description": "General sum type that explicitly stores the types of the variants.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "General", "default": "General", @@ -1462,12 +1472,25 @@ "$ref": "#/$defs/AliasDefn" } ], + "required": [ + "parent", + "op" + ], "title": "OpType" }, "Opaque": { "additionalProperties": false, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { + "t": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "T", + "type": "string" + }, "extension": { "title": "Extension", "type": "string" @@ -1592,7 +1615,7 @@ }, "PolyFuncType": { "additionalProperties": false, - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -1671,11 +1694,14 @@ "$ref": "#/$defs/GeneralSum" } ], + "required": [ + "s" + ], "title": "SumType" }, "SumValue": { "additionalProperties": false, - "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", + "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", "properties": { "v": { "const": "Sum", @@ -1764,50 +1790,6 @@ "title": "Tag", "type": "object" }, - "TaggedOpaque": { - "additionalProperties": false, - "properties": { - "t": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "T", - "type": "string" - }, - "o": { - "$ref": "#/$defs/Opaque" - } - }, - "required": [ - "o" - ], - "title": "TaggedOpaque", - "type": "object" - }, - "TaggedSumType": { - "additionalProperties": false, - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumType" - } - }, - "required": [ - "st" - ], - "title": "TaggedSumType", - "type": "object" - }, "TailLoop": { "additionalProperties": false, "description": "Tail-controlled loop.", @@ -1929,9 +1911,9 @@ "Array": "#/$defs/Array", "G": "#/$defs/FunctionType", "I": "#/$defs/USize", - "Opaque": "#/$defs/TaggedOpaque", + "Opaque": "#/$defs/Opaque", "Q": "#/$defs/Qubit", - "Sum": "#/$defs/TaggedSumType", + "Sum": "#/$defs/SumType", "V": "#/$defs/Variable" }, "propertyName": "t" @@ -1953,15 +1935,18 @@ "$ref": "#/$defs/Array" }, { - "$ref": "#/$defs/TaggedSumType" + "$ref": "#/$defs/SumType" }, { - "$ref": "#/$defs/TaggedOpaque" + "$ref": "#/$defs/Opaque" }, { "$ref": "#/$defs/Alias" } ], + "required": [ + "t" + ], "title": "Type" }, "TypeArg": { @@ -1997,6 +1982,9 @@ "$ref": "#/$defs/VariableArg" } ], + "required": [ + "tya" + ], "title": "TypeArg" }, "TypeBound": { @@ -2041,6 +2029,9 @@ "$ref": "#/$defs/ExtensionsParam" } ], + "required": [ + "tp" + ], "title": "TypeParam" }, "TypeTypeArg": { @@ -2108,6 +2099,15 @@ "additionalProperties": false, "description": "Simple sum type where all variants are empty tuples.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "Unit", "default": "Unit", @@ -2199,6 +2199,9 @@ "$ref": "#/$defs/SumValue" } ], + "required": [ + "v" + ], "title": "Value" }, "Variable": { diff --git a/specification/schema/hugr_schema_v1.json b/specification/schema/hugr_schema_v1.json index eadf57675..27d58db73 100644 --- a/specification/schema/hugr_schema_v1.json +++ b/specification/schema/hugr_schema_v1.json @@ -247,7 +247,7 @@ }, "Call": { "additionalProperties": true, - "description": "Call a function directly.\n\nThe first port is connected to the def/declare of the function being called\ndirectly, with a `ConstE` edge. The signature of the remaining ports matches\nthe function being called.", + "description": "Operation to call a function directly. The first port is connected to the def/declare of the function being called directly, with a `Static` edge. The signature of the remaining ports matches the function being called.", "properties": { "parent": { "title": "Parent", @@ -518,7 +518,7 @@ }, "CustomOp": { "additionalProperties": true, - "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "description": "A user-defined operation that can be downcasted by the extensions that define it.", "properties": { "parent": { "title": "Parent", @@ -624,7 +624,7 @@ }, "DataflowBlock": { "additionalProperties": true, - "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", "properties": { "parent": { "title": "Parent", @@ -687,14 +687,15 @@ } }, "required": [ - "parent" + "parent", + "sum_rows" ], "title": "DataflowBlock", "type": "object" }, "ExitBlock": { "additionalProperties": true, - "description": "The single exit node of the CFG, has no children, stores the types of\nthe CFG node output.", + "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", "properties": { "parent": { "title": "Parent", @@ -914,7 +915,7 @@ }, "FunctionType": { "additionalProperties": true, - "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", "properties": { "t": { "const": "G", @@ -981,6 +982,15 @@ "additionalProperties": true, "description": "General sum type that explicitly stores the types of the variants.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "General", "default": "General", @@ -1462,12 +1472,25 @@ "$ref": "#/$defs/AliasDefn" } ], + "required": [ + "parent", + "op" + ], "title": "OpType" }, "Opaque": { "additionalProperties": true, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { + "t": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "T", + "type": "string" + }, "extension": { "title": "Extension", "type": "string" @@ -1592,7 +1615,7 @@ }, "PolyFuncType": { "additionalProperties": true, - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -1671,11 +1694,14 @@ "$ref": "#/$defs/GeneralSum" } ], + "required": [ + "s" + ], "title": "SumType" }, "SumValue": { "additionalProperties": true, - "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", + "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", "properties": { "v": { "const": "Sum", @@ -1764,50 +1790,6 @@ "title": "Tag", "type": "object" }, - "TaggedOpaque": { - "additionalProperties": true, - "properties": { - "t": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "T", - "type": "string" - }, - "o": { - "$ref": "#/$defs/Opaque" - } - }, - "required": [ - "o" - ], - "title": "TaggedOpaque", - "type": "object" - }, - "TaggedSumType": { - "additionalProperties": true, - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumType" - } - }, - "required": [ - "st" - ], - "title": "TaggedSumType", - "type": "object" - }, "TailLoop": { "additionalProperties": true, "description": "Tail-controlled loop.", @@ -1929,9 +1911,9 @@ "Array": "#/$defs/Array", "G": "#/$defs/FunctionType", "I": "#/$defs/USize", - "Opaque": "#/$defs/TaggedOpaque", + "Opaque": "#/$defs/Opaque", "Q": "#/$defs/Qubit", - "Sum": "#/$defs/TaggedSumType", + "Sum": "#/$defs/SumType", "V": "#/$defs/Variable" }, "propertyName": "t" @@ -1953,15 +1935,18 @@ "$ref": "#/$defs/Array" }, { - "$ref": "#/$defs/TaggedSumType" + "$ref": "#/$defs/SumType" }, { - "$ref": "#/$defs/TaggedOpaque" + "$ref": "#/$defs/Opaque" }, { "$ref": "#/$defs/Alias" } ], + "required": [ + "t" + ], "title": "Type" }, "TypeArg": { @@ -1997,6 +1982,9 @@ "$ref": "#/$defs/VariableArg" } ], + "required": [ + "tya" + ], "title": "TypeArg" }, "TypeBound": { @@ -2041,6 +2029,9 @@ "$ref": "#/$defs/ExtensionsParam" } ], + "required": [ + "tp" + ], "title": "TypeParam" }, "TypeTypeArg": { @@ -2108,6 +2099,15 @@ "additionalProperties": true, "description": "Simple sum type where all variants are empty tuples.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "Unit", "default": "Unit", @@ -2199,6 +2199,9 @@ "$ref": "#/$defs/SumValue" } ], + "required": [ + "v" + ], "title": "Value" }, "Variable": { diff --git a/specification/schema/testing_hugr_schema_strict_v1.json b/specification/schema/testing_hugr_schema_strict_v1.json index ff62e7bd0..850d2674d 100644 --- a/specification/schema/testing_hugr_schema_strict_v1.json +++ b/specification/schema/testing_hugr_schema_strict_v1.json @@ -247,7 +247,7 @@ }, "Call": { "additionalProperties": false, - "description": "Call a function directly.\n\nThe first port is connected to the def/declare of the function being called\ndirectly, with a `ConstE` edge. The signature of the remaining ports matches\nthe function being called.", + "description": "Operation to call a function directly. The first port is connected to the def/declare of the function being called directly, with a `Static` edge. The signature of the remaining ports matches the function being called.", "properties": { "parent": { "title": "Parent", @@ -518,7 +518,7 @@ }, "CustomOp": { "additionalProperties": false, - "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "description": "A user-defined operation that can be downcasted by the extensions that define it.", "properties": { "parent": { "title": "Parent", @@ -624,7 +624,7 @@ }, "DataflowBlock": { "additionalProperties": false, - "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", "properties": { "parent": { "title": "Parent", @@ -687,14 +687,15 @@ } }, "required": [ - "parent" + "parent", + "sum_rows" ], "title": "DataflowBlock", "type": "object" }, "ExitBlock": { "additionalProperties": false, - "description": "The single exit node of the CFG, has no children, stores the types of\nthe CFG node output.", + "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", "properties": { "parent": { "title": "Parent", @@ -914,7 +915,7 @@ }, "FunctionType": { "additionalProperties": false, - "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", "properties": { "t": { "const": "G", @@ -981,6 +982,15 @@ "additionalProperties": false, "description": "General sum type that explicitly stores the types of the variants.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "General", "default": "General", @@ -1462,12 +1472,25 @@ "$ref": "#/$defs/AliasDefn" } ], + "required": [ + "parent", + "op" + ], "title": "OpType" }, "Opaque": { "additionalProperties": false, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { + "t": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "T", + "type": "string" + }, "extension": { "title": "Extension", "type": "string" @@ -1592,7 +1615,7 @@ }, "PolyFuncType": { "additionalProperties": false, - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -1671,11 +1694,14 @@ "$ref": "#/$defs/GeneralSum" } ], + "required": [ + "s" + ], "title": "SumType" }, "SumValue": { "additionalProperties": false, - "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", + "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", "properties": { "v": { "const": "Sum", @@ -1764,50 +1790,6 @@ "title": "Tag", "type": "object" }, - "TaggedOpaque": { - "additionalProperties": false, - "properties": { - "t": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "T", - "type": "string" - }, - "o": { - "$ref": "#/$defs/Opaque" - } - }, - "required": [ - "o" - ], - "title": "TaggedOpaque", - "type": "object" - }, - "TaggedSumType": { - "additionalProperties": false, - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumType" - } - }, - "required": [ - "st" - ], - "title": "TaggedSumType", - "type": "object" - }, "TailLoop": { "additionalProperties": false, "description": "Tail-controlled loop.", @@ -1929,9 +1911,9 @@ "Array": "#/$defs/Array", "G": "#/$defs/FunctionType", "I": "#/$defs/USize", - "Opaque": "#/$defs/TaggedOpaque", + "Opaque": "#/$defs/Opaque", "Q": "#/$defs/Qubit", - "Sum": "#/$defs/TaggedSumType", + "Sum": "#/$defs/SumType", "V": "#/$defs/Variable" }, "propertyName": "t" @@ -1953,15 +1935,18 @@ "$ref": "#/$defs/Array" }, { - "$ref": "#/$defs/TaggedSumType" + "$ref": "#/$defs/SumType" }, { - "$ref": "#/$defs/TaggedOpaque" + "$ref": "#/$defs/Opaque" }, { "$ref": "#/$defs/Alias" } ], + "required": [ + "t" + ], "title": "Type" }, "TypeArg": { @@ -1997,6 +1982,9 @@ "$ref": "#/$defs/VariableArg" } ], + "required": [ + "tya" + ], "title": "TypeArg" }, "TypeBound": { @@ -2041,6 +2029,9 @@ "$ref": "#/$defs/ExtensionsParam" } ], + "required": [ + "tp" + ], "title": "TypeParam" }, "TypeTypeArg": { @@ -2108,6 +2099,15 @@ "additionalProperties": false, "description": "Simple sum type where all variants are empty tuples.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "Unit", "default": "Unit", @@ -2199,6 +2199,9 @@ "$ref": "#/$defs/SumValue" } ], + "required": [ + "v" + ], "title": "Value" }, "Variable": { @@ -2324,6 +2327,6 @@ "default": null } }, - "title": "TestingHugr", + "title": "HugrTesting", "type": "object" } \ No newline at end of file diff --git a/specification/schema/testing_hugr_schema_v1.json b/specification/schema/testing_hugr_schema_v1.json index d782686ff..40e1b894c 100644 --- a/specification/schema/testing_hugr_schema_v1.json +++ b/specification/schema/testing_hugr_schema_v1.json @@ -247,7 +247,7 @@ }, "Call": { "additionalProperties": true, - "description": "Call a function directly.\n\nThe first port is connected to the def/declare of the function being called\ndirectly, with a `ConstE` edge. The signature of the remaining ports matches\nthe function being called.", + "description": "Operation to call a function directly. The first port is connected to the def/declare of the function being called directly, with a `Static` edge. The signature of the remaining ports matches the function being called.", "properties": { "parent": { "title": "Parent", @@ -518,7 +518,7 @@ }, "CustomOp": { "additionalProperties": true, - "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "description": "A user-defined operation that can be downcasted by the extensions that define it.", "properties": { "parent": { "title": "Parent", @@ -624,7 +624,7 @@ }, "DataflowBlock": { "additionalProperties": true, - "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", "properties": { "parent": { "title": "Parent", @@ -687,14 +687,15 @@ } }, "required": [ - "parent" + "parent", + "sum_rows" ], "title": "DataflowBlock", "type": "object" }, "ExitBlock": { "additionalProperties": true, - "description": "The single exit node of the CFG, has no children, stores the types of\nthe CFG node output.", + "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", "properties": { "parent": { "title": "Parent", @@ -914,7 +915,7 @@ }, "FunctionType": { "additionalProperties": true, - "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", "properties": { "t": { "const": "G", @@ -981,6 +982,15 @@ "additionalProperties": true, "description": "General sum type that explicitly stores the types of the variants.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "General", "default": "General", @@ -1462,12 +1472,25 @@ "$ref": "#/$defs/AliasDefn" } ], + "required": [ + "parent", + "op" + ], "title": "OpType" }, "Opaque": { "additionalProperties": true, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { + "t": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "T", + "type": "string" + }, "extension": { "title": "Extension", "type": "string" @@ -1592,7 +1615,7 @@ }, "PolyFuncType": { "additionalProperties": true, - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -1671,11 +1694,14 @@ "$ref": "#/$defs/GeneralSum" } ], + "required": [ + "s" + ], "title": "SumType" }, "SumValue": { "additionalProperties": true, - "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", + "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", "properties": { "v": { "const": "Sum", @@ -1764,50 +1790,6 @@ "title": "Tag", "type": "object" }, - "TaggedOpaque": { - "additionalProperties": true, - "properties": { - "t": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "T", - "type": "string" - }, - "o": { - "$ref": "#/$defs/Opaque" - } - }, - "required": [ - "o" - ], - "title": "TaggedOpaque", - "type": "object" - }, - "TaggedSumType": { - "additionalProperties": true, - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumType" - } - }, - "required": [ - "st" - ], - "title": "TaggedSumType", - "type": "object" - }, "TailLoop": { "additionalProperties": true, "description": "Tail-controlled loop.", @@ -1929,9 +1911,9 @@ "Array": "#/$defs/Array", "G": "#/$defs/FunctionType", "I": "#/$defs/USize", - "Opaque": "#/$defs/TaggedOpaque", + "Opaque": "#/$defs/Opaque", "Q": "#/$defs/Qubit", - "Sum": "#/$defs/TaggedSumType", + "Sum": "#/$defs/SumType", "V": "#/$defs/Variable" }, "propertyName": "t" @@ -1953,15 +1935,18 @@ "$ref": "#/$defs/Array" }, { - "$ref": "#/$defs/TaggedSumType" + "$ref": "#/$defs/SumType" }, { - "$ref": "#/$defs/TaggedOpaque" + "$ref": "#/$defs/Opaque" }, { "$ref": "#/$defs/Alias" } ], + "required": [ + "t" + ], "title": "Type" }, "TypeArg": { @@ -1997,6 +1982,9 @@ "$ref": "#/$defs/VariableArg" } ], + "required": [ + "tya" + ], "title": "TypeArg" }, "TypeBound": { @@ -2041,6 +2029,9 @@ "$ref": "#/$defs/ExtensionsParam" } ], + "required": [ + "tp" + ], "title": "TypeParam" }, "TypeTypeArg": { @@ -2108,6 +2099,15 @@ "additionalProperties": true, "description": "Simple sum type where all variants are empty tuples.", "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, "s": { "const": "Unit", "default": "Unit", @@ -2199,6 +2199,9 @@ "$ref": "#/$defs/SumValue" } ], + "required": [ + "v" + ], "title": "Value" }, "Variable": { @@ -2324,6 +2327,6 @@ "default": null } }, - "title": "TestingHugr", + "title": "HugrTesting", "type": "object" } \ No newline at end of file