From 954b2cb4e18903b43c6eadc5a5d9f0e0d40d56e5 Mon Sep 17 00:00:00 2001 From: doug-q <141026920+doug-q@users.noreply.github.com> Date: Thu, 2 May 2024 11:49:16 +0100 Subject: [PATCH] test!: test roundtrip serialisation against strict + lax schema (#982) We also include some ops in testing, and apply required fixes. Note that we intend to replace this `rstest::case` style testing with `proptest`. BREAKING CHANGE: serialisation schema --- hugr-py/src/hugr/serialization/ops.py | 41 +- hugr-py/src/hugr/serialization/serial_hugr.py | 11 +- .../src/hugr/serialization/testing_hugr.py | 29 +- hugr-py/src/hugr/serialization/tys.py | 83 +- hugr/src/hugr/serialize.rs | 2 + hugr/src/hugr/serialize/test.rs | 92 +- poetry.lock | 22 +- scripts/generate_schema.py | 24 +- .../schema/hugr_schema_strict_v1.json | 1985 +++++++++++++++++ specification/schema/hugr_schema_v1.json | 128 +- .../schema/testing_hugr_schema_strict_v1.json | 1965 ++++++++++++++++ .../schema/testing_hugr_schema_v1.json | 1215 +++++++++- 12 files changed, 5404 insertions(+), 193 deletions(-) create mode 100644 specification/schema/hugr_schema_strict_v1.json create mode 100644 specification/schema/testing_hugr_schema_strict_v1.json diff --git a/hugr-py/src/hugr/serialization/ops.py b/hugr-py/src/hugr/serialization/ops.py index 9e6f4703c..849c7aff2 100644 --- a/hugr-py/src/hugr/serialization/ops.py +++ b/hugr-py/src/hugr/serialization/ops.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Any, Literal, cast -from pydantic import BaseModel, Field, RootModel +from pydantic import Field, RootModel from . import tys from .tys import ( @@ -15,12 +15,15 @@ TypeRow, SumType, TypeBound, + ConfiguredBaseModel, + classes as tys_classes, + model_rebuild as tys_model_rebuild, ) NodeID = int -class BaseOp(ABC, BaseModel): +class BaseOp(ABC, ConfiguredBaseModel): """Base class for ops that store their node's input/output types""" # Parent node index of node the op belongs to, used only at serialization time @@ -84,7 +87,7 @@ def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None: CustomConst = Any # TODO -class ExtensionValue(BaseModel): +class ExtensionValue(ConfiguredBaseModel): """An extension constant value, that can check it is of a given [CustomType].""" c: Literal["Extension"] = Field("Extension", title="ValueTag") @@ -96,7 +99,7 @@ class Config: } -class FunctionValue(BaseModel): +class FunctionValue(ConfiguredBaseModel): """A higher-order function value.""" c: Literal["Function"] = Field("Function", title="ValueTag") @@ -108,7 +111,7 @@ class Config: } -class TupleValue(BaseModel): +class TupleValue(ConfiguredBaseModel): """A constant tuple value.""" c: Literal["Tuple"] = Field("Tuple", title="ValueTag") @@ -120,7 +123,7 @@ class Config: } -class SumValue(BaseModel): +class SumValue(ConfiguredBaseModel): """A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag @@ -263,10 +266,11 @@ class Call(DataflowOp): """ op: Literal["Call"] = "Call" - signature: FunctionType = Field(default_factory=FunctionType.empty) + func_sig: PolyFuncType = Field(default_factory=FunctionType.empty) + type_args: list[tys.TypeArg] = Field(default_factory=list) + instantiation: FunctionType = Field(default_factory=FunctionType.empty) def insert_port_types(self, in_types: TypeRow, out_types: TypeRow) -> None: - # The constE edge comes after the value inputs fun_ty = in_types[-1] assert isinstance(fun_ty, PolyFuncType) poly_func = cast(PolyFuncType, fun_ty) @@ -495,6 +499,12 @@ class AliasDecl(BaseOp): bound: TypeBound +class AliasDefn(BaseOp): + op: Literal["AliasDefn"] = "AliasDefn" + name: str + definition: Type + + class OpType(RootModel): """A constant operation.""" @@ -523,6 +533,7 @@ class OpType(RootModel): | Lift | DFG | AliasDecl + | AliasDefn ) = Field(discriminator="op") @@ -547,10 +558,12 @@ class OpDef(BaseOp, populate_by_name=True): # Now that all classes are defined, we need to update the ForwardRefs in all type # annotations. We use some inspect magic to find all classes defined in this file. -classes = inspect.getmembers( - sys.modules[__name__], - lambda member: inspect.isclass(member) and member.__module__ == __name__, +classes = ( + inspect.getmembers( + sys.modules[__name__], + lambda member: inspect.isclass(member) and member.__module__ == __name__, + ) + + tys_classes ) -for _, c in classes: - if issubclass(c, BaseModel): - c.model_rebuild() + +tys_model_rebuild(dict(classes)) diff --git a/hugr-py/src/hugr/serialization/serial_hugr.py b/hugr-py/src/hugr/serialization/serial_hugr.py index 28c77eee6..a8c104937 100644 --- a/hugr-py/src/hugr/serialization/serial_hugr.py +++ b/hugr-py/src/hugr/serialization/serial_hugr.py @@ -1,8 +1,9 @@ from typing import Any, Literal -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, ConfigDict -from .ops import NodeID, OpType +from .ops import NodeID, OpType, classes as ops_classes +from .tys import model_rebuild import hugr Port = tuple[NodeID, int | None] # (node, offset) @@ -34,6 +35,12 @@ def get_version(cls) -> str: """Return the version of the schema.""" return cls(nodes=[], edges=[]).version + @classmethod + def _pydantic_rebuild(cls, config: ConfigDict = ConfigDict(), **kwargs): + my_classes = dict(ops_classes) + my_classes[cls.__name__] = cls + model_rebuild(my_classes, config=config, **kwargs) + class Config: title = "Hugr" json_schema_extra = { diff --git a/hugr-py/src/hugr/serialization/testing_hugr.py b/hugr-py/src/hugr/serialization/testing_hugr.py index 37a1a5086..59db4b80d 100644 --- a/hugr-py/src/hugr/serialization/testing_hugr.py +++ b/hugr-py/src/hugr/serialization/testing_hugr.py @@ -1,23 +1,30 @@ -from typing import Literal, Optional -from pydantic import BaseModel -from .tys import Type, SumType, PolyFuncType -from .ops import Value +from pydantic import ConfigDict +from typing import Literal +from .tys import Type, SumType, PolyFuncType, ConfiguredBaseModel, model_rebuild +from .ops import Value, OpType, classes as ops_classes -class TestingHugr(BaseModel): - """A serializable representation of a Hugr Type, SumType, PolyFuncType, or - Value. Intended for testing only.""" +class TestingHugr(ConfiguredBaseModel): + """A serializable representation of a Hugr Type, SumType, PolyFuncType, + Value, OpType. Intended for testing only.""" version: Literal["v1"] = "v1" - typ: Optional[Type] = None - sum_type: Optional[SumType] = None - poly_func_type: Optional[PolyFuncType] = None - value: Optional[Value] = None + typ: Type | None = None + sum_type: SumType | None = None + poly_func_type: PolyFuncType | None = None + value: Value | None = None + optype: OpType | None = None @classmethod def get_version(cls) -> str: """Return the version of the schema.""" return cls().version + @classmethod + def _pydantic_rebuild(cls, config: ConfigDict = ConfigDict(), **kwargs): + my_classes = dict(ops_classes) + my_classes[cls.__name__] = cls + model_rebuild(my_classes, config=config, **kwargs) + class Config: title = "HugrTesting" diff --git a/hugr-py/src/hugr/serialization/tys.py b/hugr-py/src/hugr/serialization/tys.py index eb1bec545..95703861c 100644 --- a/hugr-py/src/hugr/serialization/tys.py +++ b/hugr-py/src/hugr/serialization/tys.py @@ -1,7 +1,7 @@ import inspect import sys from enum import Enum -from typing import Annotated, Any, Literal, Optional, Union +from typing import Annotated, Any, Literal, Optional, Union, Mapping from pydantic import ( BaseModel, @@ -11,6 +11,7 @@ ValidationInfo, ValidatorFunctionWrapHandler, WrapValidator, + ConfigDict, ) from pydantic_core import PydanticCustomError @@ -38,6 +39,16 @@ def _json_custom_error_validator( ExtensionId = str +default_model_config = ConfigDict() + + +class ConfiguredBaseModel(BaseModel): + model_config = default_model_config + + @classmethod + def set_model_config(cls, config: ConfigDict): + cls.model_config = config + class ExtensionSet(RootModel): """A set of extensions ids.""" @@ -50,32 +61,32 @@ class ExtensionSet(RootModel): # -------------------------------------------- -class TypeTypeParam(BaseModel): +class TypeTypeParam(ConfiguredBaseModel): tp: Literal["Type"] = "Type" b: "TypeBound" -class BoundedNatParam(BaseModel): +class BoundedNatParam(ConfiguredBaseModel): tp: Literal["BoundedNat"] = "BoundedNat" bound: int | None -class OpaqueParam(BaseModel): +class OpaqueParam(ConfiguredBaseModel): tp: Literal["Opaque"] = "Opaque" ty: "Opaque" -class ListParam(BaseModel): +class ListParam(ConfiguredBaseModel): tp: Literal["List"] = "List" param: "TypeParam" -class TupleParam(BaseModel): +class TupleParam(ConfiguredBaseModel): tp: Literal["Tuple"] = "Tuple" params: list["TypeParam"] -class ExtensionsParam(BaseModel): +class ExtensionsParam(ConfiguredBaseModel): tp: Literal["Extensions"] = "Extensions" @@ -98,32 +109,32 @@ class TypeParam(RootModel): # ------------------------------------------ -class CustomTypeArg(BaseModel): +class CustomTypeArg(ConfiguredBaseModel): typ: None # TODO value: str -class TypeTypeArg(BaseModel): +class TypeTypeArg(ConfiguredBaseModel): tya: Literal["Type"] = "Type" ty: "Type" -class BoundedNatArg(BaseModel): +class BoundedNatArg(ConfiguredBaseModel): tya: Literal["BoundedNat"] = "BoundedNat" n: int -class OpaqueArg(BaseModel): +class OpaqueArg(ConfiguredBaseModel): tya: Literal["Opaque"] = "Opaque" arg: CustomTypeArg -class SequenceArg(BaseModel): +class SequenceArg(ConfiguredBaseModel): tya: Literal["Sequence"] = "Sequence" args: list["TypeArg"] -class ExtensionsArg(BaseModel): +class ExtensionsArg(ConfiguredBaseModel): tya: Literal["Extensions"] = "Extensions" es: ExtensionSet @@ -142,7 +153,7 @@ class TypeArg(RootModel): # -------------------------------------------- -class MultiContainer(BaseModel): +class MultiContainer(ConfiguredBaseModel): ty: "Type" @@ -153,14 +164,14 @@ class Array(MultiContainer): len: int -class UnitSum(BaseModel): +class UnitSum(ConfiguredBaseModel): """Simple sum type where all variants are empty tuples.""" s: Literal["Unit"] = "Unit" size: int -class GeneralSum(BaseModel): +class GeneralSum(ConfiguredBaseModel): """General sum type that explicitly stores the types of the variants.""" s: Literal["General"] = "General" @@ -171,7 +182,7 @@ class SumType(RootModel): root: Union[UnitSum, GeneralSum] = Field(discriminator="s") -class TaggedSumType(BaseModel): +class TaggedSumType(ConfiguredBaseModel): t: Literal["Sum"] = "Sum" st: SumType @@ -181,7 +192,7 @@ class TaggedSumType(BaseModel): # ---------------------------------------------- -class Variable(BaseModel): +class Variable(ConfiguredBaseModel): """A type variable identified by an index into the array of TypeParams.""" t: Literal["V"] = "V" @@ -189,13 +200,13 @@ class Variable(BaseModel): b: "TypeBound" -class USize(BaseModel): +class USize(ConfiguredBaseModel): """Unsigned integer size type.""" t: Literal["I"] = "I" -class FunctionType(BaseModel): +class FunctionType(ConfiguredBaseModel): """A graph encoded as a value. It contains a concrete signature and a set of required resources.""" @@ -220,7 +231,7 @@ class Config: } -class PolyFuncType(BaseModel): +class PolyFuncType(ConfiguredBaseModel): """A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)""" @@ -263,7 +274,7 @@ def join(*bs: "TypeBound") -> "TypeBound": return res -class Opaque(BaseModel): +class Opaque(ConfiguredBaseModel): """An opaque Type that can be downcasted by the extensions that define it.""" t: Literal["Opaque"] = "Opaque" @@ -273,7 +284,7 @@ class Opaque(BaseModel): bound: TypeBound -class Alias(BaseModel): +class Alias(ConfiguredBaseModel): """An Alias Type""" t: Literal["Alias"] = "Alias" @@ -286,7 +297,7 @@ class Alias(BaseModel): # ---------------------------------------------- -class Qubit(BaseModel): +class Qubit(ConfiguredBaseModel): """A qubit.""" t: Literal["Q"] = "Q" @@ -320,7 +331,7 @@ class Type(RootModel): # ------------------------------------------- -class Signature(BaseModel): +class Signature(ConfiguredBaseModel): """Describes the edges required to/from a node. This includes both the concept of "signature" in the spec, and also the target @@ -334,11 +345,25 @@ class Signature(BaseModel): # Now that all classes are defined, we need to update the ForwardRefs in all type -# annotations. We use some inspect magic to find all classes defined in this file. +# annotations. We use some inspect magic to find all classes defined in this file +# and call model_rebuild() classes = inspect.getmembers( sys.modules[__name__], lambda member: inspect.isclass(member) and member.__module__ == __name__, ) -for _, c in classes: - if issubclass(c, BaseModel): - c.model_rebuild() + + +def model_rebuild( + classes: Mapping[str, type], + 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.model_rebuild(**kwargs) + + +model_rebuild(dict(classes)) diff --git a/hugr/src/hugr/serialize.rs b/hugr/src/hugr/serialize.rs index bc6c54086..89f76b043 100644 --- a/hugr/src/hugr/serialize.rs +++ b/hugr/src/hugr/serialize.rs @@ -79,6 +79,7 @@ struct SerTestingV1 { sum_type: Option, poly_func_type: Option, value: Option, + optype: Option, } macro_rules! impl_sertesting_from { @@ -98,6 +99,7 @@ impl_sertesting_from!(crate::types::Type, typ); impl_sertesting_from!(crate::types::SumType, sum_type); impl_sertesting_from!(crate::types::PolyFuncType, poly_func_type); impl_sertesting_from!(crate::ops::Value, value); +impl_sertesting_from!(NodeSer, optype); /// Errors that can occur while serializing a HUGR. #[derive(Debug, Clone, PartialEq, Error)] diff --git a/hugr/src/hugr/serialize/test.rs b/hugr/src/hugr/serialize/test.rs index cd633676f..2c63e33d7 100644 --- a/hugr/src/hugr/serialize/test.rs +++ b/hugr/src/hugr/serialize/test.rs @@ -3,13 +3,13 @@ use crate::builder::{ test::closed_dfg_root_hugr, Container, DFGBuilder, Dataflow, DataflowHugr, DataflowSubContainer, HugrBuilder, ModuleBuilder, }; -use crate::extension::prelude::{BOOL_T, QB_T, USIZE_T}; +use crate::extension::prelude::{BOOL_T, PRELUDE_ID, QB_T, USIZE_T}; use crate::extension::simple_op::MakeRegisteredOp; use crate::extension::{EMPTY_REG, PRELUDE_REGISTRY}; use crate::hugr::hugrmut::sealed::HugrMutInternals; use crate::hugr::NodeType; use crate::ops::custom::{ExtensionOp, OpaqueOp}; -use crate::ops::Value; +use crate::ops::{self, Value}; use crate::ops::{dataflow::IOTrait, Input, Module, Noop, Output, DFG}; use crate::std_extensions::arithmetic::float_ops::FLOAT_OPS_REGISTRY; use crate::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE}; @@ -32,29 +32,38 @@ const QB: Type = crate::extension::prelude::QB_T; type TestingModel = SerTestingV1; -lazy_static! { - static ref SCHEMA: JSONSchema = { - let schema_val: serde_json::Value = serde_json::from_str(include_str!( - "../../../../specification/schema/hugr_schema_v1.json" - )) - .unwrap(); - JSONSchema::options() - .with_draft(Draft::Draft7) - .compile(&schema_val) - .expect("Schema is invalid.") - }; - static ref TESTING_SCHEMA: JSONSchema = { - let schema_val: serde_json::Value = serde_json::from_str(include_str!( - "../../../../specification/schema/testing_hugr_schema_v1.json" - )) - .unwrap(); - JSONSchema::options() - .with_draft(Draft::Draft7) - .compile(&schema_val) - .expect("Schema is invalid.") +macro_rules! include_schema { + ($name:ident, $path:literal) => { + lazy_static! { + static ref $name: JSONSchema = { + let schema_val: serde_json::Value = + serde_json::from_str(include_str!($path)).unwrap(); + JSONSchema::options() + .with_draft(Draft::Draft7) + .compile(&schema_val) + .expect("Schema is invalid.") + }; + } }; } +include_schema!( + SCHEMA, + "../../../../specification/schema/hugr_schema_v1.json" +); +include_schema!( + SCHEMA_STRICT, + "../../../../specification/schema/hugr_schema_strict_v1.json" +); +include_schema!( + TESTING_SCHEMA, + "../../../../specification/schema/testing_hugr_schema_v1.json" +); +include_schema!( + TESTING_SCHEMA_STRICT, + "../../../../specification/schema/testing_hugr_schema_strict_v1.json" +); + #[test] fn empty_hugr_serialize() { let hg = Hugr::default(); @@ -86,7 +95,7 @@ pub fn ser_roundtrip_validate( panic!("Serialization test failed."); } } - serde_json::from_str(&s).unwrap() + serde_json::from_value(val).unwrap() } /// Serialize and deserialize a HUGR, and check that the result is the same as the original. @@ -104,6 +113,9 @@ pub fn check_hugr_schema_roundtrip(hugr: &Hugr) -> Hugr { /// Returns the deserialized HUGR. pub fn check_hugr_roundtrip(hugr: &Hugr, check_schema: bool) -> Hugr { let new_hugr: Hugr = ser_roundtrip_validate(hugr, check_schema.then_some(&SCHEMA)); + let new_hugr_strict: Hugr = + ser_roundtrip_validate(hugr, check_schema.then_some(&SCHEMA_STRICT)); + assert_eq!(new_hugr, new_hugr_strict); // Original HUGR, with canonicalized node indices // @@ -140,10 +152,12 @@ pub fn check_hugr_roundtrip(hugr: &Hugr, check_schema: bool) -> Hugr { new_hugr } -fn check_testing_roundtrip(t: TestingModel) { - let before = Versioned::new(t); +fn check_testing_roundtrip(t: impl Into) { + let before = Versioned::new(t.into()); + let after_strict = ser_roundtrip_validate(&before, Some(&TESTING_SCHEMA_STRICT)); let after = ser_roundtrip_validate(&before, Some(&TESTING_SCHEMA)); assert_eq!(before, after); + assert_eq!(after, after_strict); } /// Generate an optype for a node with a matching amount of inputs and outputs. @@ -345,14 +359,14 @@ fn serialize_types_roundtrip() { #[case(Type::new_sum([type_row![BOOL_T,QB_T], type_row![Type::new_unit_sum(4)]]))] #[case(Type::new_function(FunctionType::new_endo(type_row![QB_T,BOOL_T,USIZE_T])))] fn roundtrip_type(#[case] typ: Type) { - check_testing_roundtrip(typ.into()) + check_testing_roundtrip(typ); } #[rstest] #[case(SumType::new_unary(2))] #[case(SumType::new([type_row![USIZE_T, QB_T], type_row![]]))] fn roundtrip_sumtype(#[case] sum_type: SumType) { - check_testing_roundtrip(sum_type.into()) + check_testing_roundtrip(sum_type); } #[rstest] @@ -371,7 +385,7 @@ fn roundtrip_sumtype(#[case] sum_type: SumType) { #[case(Value::tuple([Value::false_val(), Value::extension(ConstInt::new_s(2,1).unwrap())]))] #[case(Value::function(crate::builder::test::simple_dfg_hugr()).unwrap())] fn roundtrip_value(#[case] value: Value) { - check_testing_roundtrip(value.into()) + check_testing_roundtrip(value); } fn polyfunctype1() -> PolyFuncType { @@ -389,5 +403,25 @@ fn polyfunctype1() -> PolyFuncType { #[case(PolyFuncType::new([TypeParam::List { param: Box::new(TypeBound::Any.into()) }], FunctionType::new_endo(type_row![])))] #[case(PolyFuncType::new([TypeParam::Tuple { params: [TypeBound::Any.into(), TypeParam::bounded_nat(2.try_into().unwrap())].into() }], FunctionType::new_endo(type_row![])))] fn roundtrip_polyfunctype(#[case] poly_func_type: PolyFuncType) { - check_testing_roundtrip(poly_func_type.into()) + check_testing_roundtrip(poly_func_type) +} + +#[rstest] +#[case(ops::Module)] +#[case(ops::FuncDefn { name: "polyfunc1".into(), signature: polyfunctype1()})] +#[case(ops::FuncDecl { name: "polyfunc2".into(), signature: polyfunctype1()})] +#[case(ops::AliasDefn { name: "aliasdefn".into(), definition: Type::new_unit_sum(4)})] +#[case(ops::AliasDecl { name: "aliasdecl".into(), bound: TypeBound::Any})] +#[case(ops::Const::new(Value::false_val()))] +#[case(ops::Const::new(Value::function(crate::builder::test::simple_dfg_hugr()).unwrap()))] +#[case(ops::Input::new(type_row![Type::new_var_use(3,TypeBound::Eq)]))] +#[case(ops::Output::new(vec![Type::new_function(FunctionType::new_endo(type_row![]))]))] +#[case(ops::Call::try_new(polyfunctype1(), [TypeArg::BoundedNat{n: 1}, TypeArg::Extensions{ es: ExtensionSet::singleton(&PRELUDE_ID)} ], &EMPTY_REG).unwrap())] +#[case(ops::CallIndirect { signature : FunctionType::new_endo(type_row![BOOL_T]) })] +fn roundtrip_optype(#[case] optype: impl Into + std::fmt::Debug) { + check_testing_roundtrip(NodeSer { + parent: portgraph::NodeIndex::new(0).into(), + input_extensions: None, + op: optype.into(), + }); } diff --git a/poetry.lock b/poetry.lock index 13d25cede..c8b22fe46 100644 --- a/poetry.lock +++ b/poetry.lock @@ -127,13 +127,13 @@ test = ["pytest (>=6)"] [[package]] name = "filelock" -version = "3.13.4" +version = "3.14.0" description = "A platform independent file lock." optional = false python-versions = ">=3.8" files = [ - {file = "filelock-3.13.4-py3-none-any.whl", hash = "sha256:404e5e9253aa60ad457cae1be07c0f0ca90a63931200a47d9b6a6af84fd7b45f"}, - {file = "filelock-3.13.4.tar.gz", hash = "sha256:d13f466618bfde72bd2c18255e269f72542c6e70e7bac83a0232d6b1cc5c8cf4"}, + {file = "filelock-3.14.0-py3-none-any.whl", hash = "sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f"}, + {file = "filelock-3.14.0.tar.gz", hash = "sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a"}, ] [package.extras] @@ -426,13 +426,13 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" [[package]] name = "pytest" -version = "8.1.1" +version = "8.2.0" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"}, - {file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"}, + {file = "pytest-8.2.0-py3-none-any.whl", hash = "sha256:1733f0620f6cda4095bbf0d9ff8022486e91892245bb9e7d5542c018f612f233"}, + {file = "pytest-8.2.0.tar.gz", hash = "sha256:d507d4482197eac0ba2bae2e9babf0672eb333017bcedaa5fb1a3d42c1174b3f"}, ] [package.dependencies] @@ -440,11 +440,11 @@ colorama = {version = "*", markers = "sys_platform == \"win32\""} exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" -pluggy = ">=1.4,<2.0" +pluggy = ">=1.5,<2.0" tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] -testing = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] [[package]] name = "pytest-cov" @@ -589,13 +589,13 @@ files = [ [[package]] name = "virtualenv" -version = "20.26.0" +version = "20.26.1" description = "Virtual Python Environment builder" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.26.0-py3-none-any.whl", hash = "sha256:0846377ea76e818daaa3e00a4365c018bc3ac9760cbb3544de542885aad61fb3"}, - {file = "virtualenv-20.26.0.tar.gz", hash = "sha256:ec25a9671a5102c8d2657f62792a27b48f016664c6873f6beed3800008577210"}, + {file = "virtualenv-20.26.1-py3-none-any.whl", hash = "sha256:7aa9982a728ae5892558bff6a2839c00b9ed145523ece2274fad6f414690ae75"}, + {file = "virtualenv-20.26.1.tar.gz", hash = "sha256:604bfdceaeece392802e6ae48e69cec49168b9c5f4a44e483963f9242eb0e78b"}, ] [package.dependencies] diff --git a/scripts/generate_schema.py b/scripts/generate_schema.py index be12fab87..882f0d7e6 100644 --- a/scripts/generate_schema.py +++ b/scripts/generate_schema.py @@ -9,24 +9,30 @@ import json import sys -from typing import Type +from typing import Type, Optional from pathlib import Path -from pydantic import TypeAdapter +from pydantic import ConfigDict from hugr.serialization import SerialHugr from hugr.serialization.testing_hugr import TestingHugr def write_schema( - out_dir: Path, name_prefix: str, schema: Type[SerialHugr] | Type[TestingHugr] + out_dir: Path, + name_prefix: str, + schema: Type[SerialHugr] | Type[TestingHugr], + config: Optional[ConfigDict] = None, + **kwargs, ): version = schema.get_version() filename = f"{name_prefix}_{version}.json" path = out_dir / filename + print(f"Rebuilding model with config: {config}") + schema._pydantic_rebuild(config or ConfigDict(), force=True, **kwargs) print(f"Writing schema to {path}") with path.open("w") as f: - json.dump(TypeAdapter(schema).json_schema(), f, indent=4) + json.dump(schema.model_json_schema(), f, indent=4) if __name__ == "__main__": @@ -38,5 +44,11 @@ def write_schema( print(__doc__) sys.exit(1) - write_schema(out_dir, "hugr_schema", SerialHugr) - write_schema(out_dir, "testing_hugr_schema", TestingHugr) + strict_config = ConfigDict(strict=True, extra="forbid") + lax_config = ConfigDict(strict=False, extra="allow") + write_schema( + out_dir, "testing_hugr_schema_strict", TestingHugr, config=strict_config + ) + write_schema(out_dir, "testing_hugr_schema", TestingHugr, config=lax_config) + write_schema(out_dir, "hugr_schema_strict", SerialHugr, config=strict_config) + write_schema(out_dir, "hugr_schema", SerialHugr, config=lax_config) diff --git a/specification/schema/hugr_schema_strict_v1.json b/specification/schema/hugr_schema_strict_v1.json new file mode 100644 index 000000000..67c5359c2 --- /dev/null +++ b/specification/schema/hugr_schema_strict_v1.json @@ -0,0 +1,1985 @@ +{ + "$defs": { + "Alias": { + "additionalProperties": false, + "description": "An Alias Type", + "properties": { + "t": { + "const": "Alias", + "default": "Alias", + "enum": [ + "Alias" + ], + "title": "T", + "type": "string" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": [ + "bound", + "name" + ], + "title": "Alias", + "type": "object" + }, + "AliasDecl": { + "additionalProperties": false, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDecl", + "default": "AliasDecl", + "enum": [ + "AliasDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "parent", + "name", + "bound" + ], + "title": "AliasDecl", + "type": "object" + }, + "AliasDefn": { + "additionalProperties": false, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDefn", + "default": "AliasDefn", + "enum": [ + "AliasDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "definition": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "name", + "definition" + ], + "title": "AliasDefn", + "type": "object" + }, + "Array": { + "additionalProperties": false, + "description": "Known size array whose elements are of the same type.", + "properties": { + "ty": { + "$ref": "#/$defs/Type" + }, + "t": { + "const": "Array", + "default": "Array", + "enum": [ + "Array" + ], + "title": "T", + "type": "string" + }, + "len": { + "title": "Len", + "type": "integer" + } + }, + "required": [ + "ty", + "len" + ], + "title": "Array", + "type": "object" + }, + "BoundedNatArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tya", + "type": "string" + }, + "n": { + "title": "N", + "type": "integer" + } + }, + "required": [ + "n" + ], + "title": "BoundedNatArg", + "type": "object" + }, + "BoundedNatParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tp", + "type": "string" + }, + "bound": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Bound" + } + }, + "required": [ + "bound" + ], + "title": "BoundedNatParam", + "type": "object" + }, + "CFG": { + "additionalProperties": false, + "description": "A dataflow node which is defined by a child CFG.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CFG", + "default": "CFG", + "enum": [ + "CFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CFG", + "type": "object" + }, + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Call", + "default": "Call", + "enum": [ + "Call" + ], + "title": "Op", + "type": "string" + }, + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "instantiation": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Call", + "type": "object" + }, + "CallIndirect": { + "additionalProperties": false, + "description": "Call a function indirectly.\n\nLike call, but the first input is a standard dataflow graph type.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CallIndirect", + "default": "CallIndirect", + "enum": [ + "CallIndirect" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CallIndirect", + "type": "object" + }, + "Case": { + "additionalProperties": false, + "description": "Case ops - nodes valid inside Conditional nodes.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Case", + "default": "Case", + "enum": [ + "Case" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Case", + "type": "object" + }, + "Conditional": { + "additionalProperties": false, + "description": "Conditional operation, defined by child `Case` nodes for each branch.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Conditional", + "default": "Conditional", + "enum": [ + "Conditional" + ], + "title": "Op", + "type": "string" + }, + "other_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Inputs", + "type": "array" + }, + "outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Outputs", + "type": "array" + }, + "sum_rows": { + "description": "The possible rows of the Sum input", + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "title": "Conditional", + "type": "object" + }, + "Const": { + "additionalProperties": false, + "description": "A Const operation definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Const", + "default": "Const", + "enum": [ + "Const" + ], + "title": "Op", + "type": "string" + }, + "v": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "parent", + "v" + ], + "title": "Const", + "type": "object" + }, + "CustomOp": { + "additionalProperties": false, + "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CustomOp", + "default": "CustomOp", + "enum": [ + "CustomOp" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "op_name": { + "title": "Op 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", + "op_name" + ], + "title": "CustomOp", + "type": "object" + }, + "CustomTypeArg": { + "additionalProperties": false, + "properties": { + "typ": { + "title": "Typ", + "type": "null" + }, + "value": { + "title": "Value", + "type": "string" + } + }, + "required": [ + "typ", + "value" + ], + "title": "CustomTypeArg", + "type": "object" + }, + "DFG": { + "additionalProperties": false, + "description": "A simply nested dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DFG", + "default": "DFG", + "enum": [ + "DFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "DFG", + "type": "object" + }, + "DataflowBlock": { + "additionalProperties": false, + "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DataflowBlock", + "default": "DataflowBlock", + "enum": [ + "DataflowBlock" + ], + "title": "Op", + "type": "string" + }, + "inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Inputs", + "type": "array" + }, + "other_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Outputs", + "type": "array" + }, + "sum_rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "ExitBlock", + "default": "ExitBlock", + "enum": [ + "ExitBlock" + ], + "title": "Op", + "type": "string" + }, + "cfg_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Cfg Outputs", + "type": "array" + } + }, + "required": [ + "parent", + "cfg_outputs" + ], + "title": "ExitBlock", + "type": "object" + }, + "ExtensionSet": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "description": "A set of extensions ids.", + "title": "ExtensionSet" + }, + "ExtensionValue": { + "additionalProperties": false, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "c": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "e": { + "title": "CustomConst" + } + }, + "required": [ + "e" + ], + "title": "ExtensionValue", + "type": "object" + }, + "ExtensionsArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Extensions", + "default": "Extensions", + "enum": [ + "Extensions" + ], + "title": "Tya", + "type": "string" + }, + "es": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "es" + ], + "title": "ExtensionsArg", + "type": "object" + }, + "ExtensionsParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Extensions", + "default": "Extensions", + "enum": [ + "Extensions" + ], + "title": "Tp", + "type": "string" + } + }, + "title": "ExtensionsParam", + "type": "object" + }, + "FuncDecl": { + "additionalProperties": false, + "description": "External function declaration, linked at runtime.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDecl", + "default": "FuncDecl", + "enum": [ + "FuncDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDecl", + "type": "object" + }, + "FuncDefn": { + "additionalProperties": false, + "description": "A function definition. Children nodes are the body of the definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDefn", + "default": "FuncDefn", + "enum": [ + "FuncDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDefn", + "type": "object" + }, + "FunctionType": { + "additionalProperties": false, + "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "properties": { + "t": { + "const": "G", + "default": "G", + "enum": [ + "G" + ], + "title": "T", + "type": "string" + }, + "input": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Input", + "type": "array" + }, + "output": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Output", + "type": "array" + }, + "extension_reqs": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "input", + "output" + ], + "title": "FunctionType", + "type": "object" + }, + "FunctionValue": { + "additionalProperties": false, + "description": "A higher-order function value.", + "properties": { + "c": { + "const": "Function", + "default": "Function", + "enum": [ + "Function" + ], + "title": "ValueTag", + "type": "string" + }, + "hugr": { + "title": "Hugr" + } + }, + "required": [ + "hugr" + ], + "title": "FunctionValue", + "type": "object" + }, + "GeneralSum": { + "additionalProperties": false, + "description": "General sum type that explicitly stores the types of the variants.", + "properties": { + "s": { + "const": "General", + "default": "General", + "enum": [ + "General" + ], + "title": "S", + "type": "string" + }, + "rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Rows", + "type": "array" + } + }, + "required": [ + "rows" + ], + "title": "GeneralSum", + "type": "object" + }, + "Input": { + "additionalProperties": false, + "description": "An input node. The outputs of this node are the inputs to the parent node.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Input", + "default": "Input", + "enum": [ + "Input" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Input", + "type": "object" + }, + "Lift": { + "additionalProperties": false, + "description": "Fixes some TypeParams of a polymorphic type by providing TypeArgs.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Lift", + "default": "Lift", + "enum": [ + "Lift" + ], + "title": "Op", + "type": "string" + }, + "type_row": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Type Row", + "type": "array" + }, + "new_extension": { + "title": "New Extension", + "type": "string" + } + }, + "required": [ + "parent", + "type_row", + "new_extension" + ], + "title": "Lift", + "type": "object" + }, + "ListParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "List", + "default": "List", + "enum": [ + "List" + ], + "title": "Tp", + "type": "string" + }, + "param": { + "$ref": "#/$defs/TypeParam" + } + }, + "required": [ + "param" + ], + "title": "ListParam", + "type": "object" + }, + "LoadConstant": { + "additionalProperties": false, + "description": "An operation that loads a static constant in to the local dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadConstant", + "default": "LoadConstant", + "enum": [ + "LoadConstant" + ], + "title": "Op", + "type": "string" + }, + "datatype": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "datatype" + ], + "title": "LoadConstant", + "type": "object" + }, + "LoadFunction": { + "additionalProperties": false, + "description": "Load a static function in to the local dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadFunction", + "default": "LoadFunction", + "enum": [ + "LoadFunction" + ], + "title": "Op", + "type": "string" + }, + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent", + "func_sig", + "type_args" + ], + "title": "LoadFunction", + "type": "object" + }, + "MakeTuple": { + "additionalProperties": false, + "description": "An operation that packs all its inputs into a tuple.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "MakeTuple", + "default": "MakeTuple", + "enum": [ + "MakeTuple" + ], + "title": "Op", + "type": "string" + }, + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "MakeTuple", + "type": "object" + }, + "Module": { + "additionalProperties": false, + "description": "The root of a module, parent of all other `ModuleOp`s.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Module", + "default": "Module", + "enum": [ + "Module" + ], + "title": "Op", + "type": "string" + } + }, + "required": [ + "parent" + ], + "title": "Module", + "type": "object" + }, + "Noop": { + "additionalProperties": false, + "description": "A no-op operation.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Noop", + "default": "Noop", + "enum": [ + "Noop" + ], + "title": "Op", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "ty" + ], + "title": "Noop", + "type": "object" + }, + "OpType": { + "description": "A constant operation.", + "discriminator": { + "mapping": { + "AliasDecl": "#/$defs/AliasDecl", + "AliasDefn": "#/$defs/AliasDefn", + "CFG": "#/$defs/CFG", + "Call": "#/$defs/Call", + "CallIndirect": "#/$defs/CallIndirect", + "Case": "#/$defs/Case", + "Conditional": "#/$defs/Conditional", + "Const": "#/$defs/Const", + "CustomOp": "#/$defs/CustomOp", + "DFG": "#/$defs/DFG", + "DataflowBlock": "#/$defs/DataflowBlock", + "ExitBlock": "#/$defs/ExitBlock", + "FuncDecl": "#/$defs/FuncDecl", + "FuncDefn": "#/$defs/FuncDefn", + "Input": "#/$defs/Input", + "Lift": "#/$defs/Lift", + "LoadConstant": "#/$defs/LoadConstant", + "LoadFunction": "#/$defs/LoadFunction", + "MakeTuple": "#/$defs/MakeTuple", + "Module": "#/$defs/Module", + "Noop": "#/$defs/Noop", + "Output": "#/$defs/Output", + "Tag": "#/$defs/Tag", + "TailLoop": "#/$defs/TailLoop", + "UnpackTuple": "#/$defs/UnpackTuple" + }, + "propertyName": "op" + }, + "oneOf": [ + { + "$ref": "#/$defs/Module" + }, + { + "$ref": "#/$defs/Case" + }, + { + "$ref": "#/$defs/FuncDefn" + }, + { + "$ref": "#/$defs/FuncDecl" + }, + { + "$ref": "#/$defs/Const" + }, + { + "$ref": "#/$defs/DataflowBlock" + }, + { + "$ref": "#/$defs/ExitBlock" + }, + { + "$ref": "#/$defs/Conditional" + }, + { + "$ref": "#/$defs/TailLoop" + }, + { + "$ref": "#/$defs/CFG" + }, + { + "$ref": "#/$defs/Input" + }, + { + "$ref": "#/$defs/Output" + }, + { + "$ref": "#/$defs/Call" + }, + { + "$ref": "#/$defs/CallIndirect" + }, + { + "$ref": "#/$defs/LoadConstant" + }, + { + "$ref": "#/$defs/LoadFunction" + }, + { + "$ref": "#/$defs/CustomOp" + }, + { + "$ref": "#/$defs/Noop" + }, + { + "$ref": "#/$defs/MakeTuple" + }, + { + "$ref": "#/$defs/UnpackTuple" + }, + { + "$ref": "#/$defs/Tag" + }, + { + "$ref": "#/$defs/Lift" + }, + { + "$ref": "#/$defs/DFG" + }, + { + "$ref": "#/$defs/AliasDecl" + }, + { + "$ref": "#/$defs/AliasDefn" + } + ], + "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" + }, + "id": { + "title": "Id", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "extension", + "id", + "args", + "bound" + ], + "title": "Opaque", + "type": "object" + }, + "OpaqueArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tya", + "type": "string" + }, + "arg": { + "$ref": "#/$defs/CustomTypeArg" + } + }, + "required": [ + "arg" + ], + "title": "OpaqueArg", + "type": "object" + }, + "OpaqueParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tp", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Opaque" + } + }, + "required": [ + "ty" + ], + "title": "OpaqueParam", + "type": "object" + }, + "Output": { + "additionalProperties": false, + "description": "An output node. The inputs are the outputs of the function.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Output", + "default": "Output", + "enum": [ + "Output" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Output", + "type": "object" + }, + "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.)", + "properties": { + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + }, + "body": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "params", + "body" + ], + "title": "PolyFuncType", + "type": "object" + }, + "Qubit": { + "additionalProperties": false, + "description": "A qubit.", + "properties": { + "t": { + "const": "Q", + "default": "Q", + "enum": [ + "Q" + ], + "title": "T", + "type": "string" + } + }, + "title": "Qubit", + "type": "object" + }, + "SequenceArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Sequence", + "default": "Sequence", + "enum": [ + "Sequence" + ], + "title": "Tya", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "args" + ], + "title": "SequenceArg", + "type": "object" + }, + "SumType": { + "discriminator": { + "mapping": { + "General": "#/$defs/GeneralSum", + "Unit": "#/$defs/UnitSum" + }, + "propertyName": "s" + }, + "oneOf": [ + { + "$ref": "#/$defs/UnitSum" + }, + { + "$ref": "#/$defs/GeneralSum" + } + ], + "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", + "properties": { + "c": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "ValueTag", + "type": "string" + }, + "tag": { + "title": "Tag", + "type": "integer" + }, + "typ": { + "$ref": "#/$defs/SumType" + }, + "vs": { + "items": { + "$ref": "#/$defs/Value" + }, + "title": "Vs", + "type": "array" + } + }, + "required": [ + "tag", + "typ", + "vs" + ], + "title": "SumValue", + "type": "object" + }, + "Tag": { + "additionalProperties": false, + "description": "An operation that creates a tagged sum value from one of its variants.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Tag", + "default": "Tag", + "enum": [ + "Tag" + ], + "title": "Op", + "type": "string" + }, + "tag": { + "title": "Tag", + "type": "integer" + }, + "variants": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Variants", + "type": "array" + } + }, + "required": [ + "parent", + "tag", + "variants" + ], + "title": "Tag", + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "TailLoop", + "default": "TailLoop", + "enum": [ + "TailLoop" + ], + "title": "Op", + "type": "string" + }, + "just_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Inputs", + "type": "array" + }, + "just_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Outputs", + "type": "array" + }, + "rest": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Rest", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "TailLoop", + "type": "object" + }, + "TupleParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Tuple", + "default": "Tuple", + "enum": [ + "Tuple" + ], + "title": "Tp", + "type": "string" + }, + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + } + }, + "required": [ + "params" + ], + "title": "TupleParam", + "type": "object" + }, + "TupleValue": { + "additionalProperties": false, + "description": "A constant tuple value.", + "properties": { + "c": { + "const": "Tuple", + "default": "Tuple", + "enum": [ + "Tuple" + ], + "title": "ValueTag", + "type": "string" + }, + "vs": { + "items": { + "$ref": "#/$defs/Value" + }, + "title": "Vs", + "type": "array" + } + }, + "required": [ + "vs" + ], + "title": "TupleValue", + "type": "object" + }, + "Type": { + "description": "A HUGR type.", + "discriminator": { + "mapping": { + "Alias": "#/$defs/Alias", + "Array": "#/$defs/Array", + "G": "#/$defs/FunctionType", + "I": "#/$defs/USize", + "Opaque": "#/$defs/Opaque", + "Q": "#/$defs/Qubit", + "Sum": "#/$defs/TaggedSumType", + "V": "#/$defs/Variable" + }, + "propertyName": "t" + }, + "oneOf": [ + { + "$ref": "#/$defs/Qubit" + }, + { + "$ref": "#/$defs/Variable" + }, + { + "$ref": "#/$defs/USize" + }, + { + "$ref": "#/$defs/FunctionType" + }, + { + "$ref": "#/$defs/Array" + }, + { + "$ref": "#/$defs/TaggedSumType" + }, + { + "$ref": "#/$defs/Opaque" + }, + { + "$ref": "#/$defs/Alias" + } + ], + "title": "Type" + }, + "TypeArg": { + "description": "A type argument.", + "discriminator": { + "mapping": { + "BoundedNat": "#/$defs/BoundedNatArg", + "Extensions": "#/$defs/ExtensionsArg", + "Opaque": "#/$defs/OpaqueArg", + "Sequence": "#/$defs/SequenceArg", + "Type": "#/$defs/TypeTypeArg" + }, + "propertyName": "tya" + }, + "oneOf": [ + { + "$ref": "#/$defs/TypeTypeArg" + }, + { + "$ref": "#/$defs/BoundedNatArg" + }, + { + "$ref": "#/$defs/OpaqueArg" + }, + { + "$ref": "#/$defs/SequenceArg" + }, + { + "$ref": "#/$defs/ExtensionsArg" + } + ], + "title": "TypeArg" + }, + "TypeBound": { + "enum": [ + "E", + "C", + "A" + ], + "title": "TypeBound", + "type": "string" + }, + "TypeParam": { + "description": "A type parameter.", + "discriminator": { + "mapping": { + "BoundedNat": "#/$defs/BoundedNatParam", + "Extensions": "#/$defs/ExtensionsParam", + "List": "#/$defs/ListParam", + "Opaque": "#/$defs/OpaqueParam", + "Tuple": "#/$defs/TupleParam", + "Type": "#/$defs/TypeTypeParam" + }, + "propertyName": "tp" + }, + "oneOf": [ + { + "$ref": "#/$defs/TypeTypeParam" + }, + { + "$ref": "#/$defs/BoundedNatParam" + }, + { + "$ref": "#/$defs/OpaqueParam" + }, + { + "$ref": "#/$defs/ListParam" + }, + { + "$ref": "#/$defs/TupleParam" + }, + { + "$ref": "#/$defs/ExtensionsParam" + } + ], + "title": "TypeParam" + }, + "TypeTypeArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tya", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "ty" + ], + "title": "TypeTypeArg", + "type": "object" + }, + "TypeTypeParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tp", + "type": "string" + }, + "b": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "b" + ], + "title": "TypeTypeParam", + "type": "object" + }, + "USize": { + "additionalProperties": false, + "description": "Unsigned integer size type.", + "properties": { + "t": { + "const": "I", + "default": "I", + "enum": [ + "I" + ], + "title": "T", + "type": "string" + } + }, + "title": "USize", + "type": "object" + }, + "UnitSum": { + "additionalProperties": false, + "description": "Simple sum type where all variants are empty tuples.", + "properties": { + "s": { + "const": "Unit", + "default": "Unit", + "enum": [ + "Unit" + ], + "title": "S", + "type": "string" + }, + "size": { + "title": "Size", + "type": "integer" + } + }, + "required": [ + "size" + ], + "title": "UnitSum", + "type": "object" + }, + "UnpackTuple": { + "additionalProperties": false, + "description": "An operation that packs all its inputs into a tuple.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "UnpackTuple", + "default": "UnpackTuple", + "enum": [ + "UnpackTuple" + ], + "title": "Op", + "type": "string" + }, + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "UnpackTuple", + "type": "object" + }, + "Value": { + "description": "A constant Value.", + "discriminator": { + "mapping": { + "Extension": "#/$defs/ExtensionValue", + "Function": "#/$defs/FunctionValue", + "Sum": "#/$defs/SumValue", + "Tuple": "#/$defs/TupleValue" + }, + "propertyName": "c" + }, + "oneOf": [ + { + "$ref": "#/$defs/ExtensionValue" + }, + { + "$ref": "#/$defs/FunctionValue" + }, + { + "$ref": "#/$defs/TupleValue" + }, + { + "$ref": "#/$defs/SumValue" + } + ], + "title": "Value" + }, + "Variable": { + "additionalProperties": false, + "description": "A type variable identified by an index into the array of TypeParams.", + "properties": { + "t": { + "const": "V", + "default": "V", + "enum": [ + "V" + ], + "title": "T", + "type": "string" + }, + "i": { + "title": "I", + "type": "integer" + }, + "b": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "i", + "b" + ], + "title": "Variable", + "type": "object" + } + }, + "description": "A serializable representation of a Hugr.", + "properties": { + "version": { + "const": "v1", + "default": "v1", + "enum": [ + "v1" + ], + "title": "Version", + "type": "string" + }, + "nodes": { + "items": { + "$ref": "#/$defs/OpType" + }, + "title": "Nodes", + "type": "array" + }, + "edges": { + "items": { + "maxItems": 2, + "minItems": 2, + "prefixItems": [ + { + "maxItems": 2, + "minItems": 2, + "prefixItems": [ + { + "type": "integer" + }, + { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ] + } + ], + "type": "array" + }, + { + "maxItems": 2, + "minItems": 2, + "prefixItems": [ + { + "type": "integer" + }, + { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ] + } + ], + "type": "array" + } + ], + "type": "array" + }, + "title": "Edges", + "type": "array" + }, + "encoder": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The name of the encoder used to generate the Hugr.", + "title": "Encoder" + } + }, + "required": [ + "version", + "nodes", + "edges" + ], + "title": "Hugr", + "type": "object" +} \ No newline at end of file diff --git a/specification/schema/hugr_schema_v1.json b/specification/schema/hugr_schema_v1.json index 2a56c0713..3b4be37c7 100644 --- a/specification/schema/hugr_schema_v1.json +++ b/specification/schema/hugr_schema_v1.json @@ -1,6 +1,7 @@ { "$defs": { "Alias": { + "additionalProperties": true, "description": "An Alias Type", "properties": { "t": { @@ -28,6 +29,7 @@ "type": "object" }, "AliasDecl": { + "additionalProperties": true, "properties": { "parent": { "title": "Parent", @@ -61,7 +63,43 @@ "title": "AliasDecl", "type": "object" }, + "AliasDefn": { + "additionalProperties": true, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDefn", + "default": "AliasDefn", + "enum": [ + "AliasDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "definition": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "name", + "definition" + ], + "title": "AliasDefn", + "type": "object" + }, "Array": { + "additionalProperties": true, "description": "Known size array whose elements are of the same type.", "properties": { "ty": { @@ -89,6 +127,7 @@ "type": "object" }, "BoundedNatArg": { + "additionalProperties": true, "properties": { "tya": { "const": "BoundedNat", @@ -111,6 +150,7 @@ "type": "object" }, "BoundedNatParam": { + "additionalProperties": true, "properties": { "tp": { "const": "BoundedNat", @@ -140,6 +180,7 @@ "type": "object" }, "CFG": { + "additionalProperties": true, "description": "A dataflow node which is defined by a child CFG.", "properties": { "parent": { @@ -169,7 +210,8 @@ "type": "object" }, "Call": { - "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.", + "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.", "properties": { "parent": { "title": "Parent", @@ -187,7 +229,17 @@ "title": "Op", "type": "string" }, - "signature": { + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "instantiation": { "$ref": "#/$defs/FunctionType" } }, @@ -198,6 +250,7 @@ "type": "object" }, "CallIndirect": { + "additionalProperties": true, "description": "Call a function indirectly.\n\nLike call, but the first input is a standard dataflow graph type.", "properties": { "parent": { @@ -227,6 +280,7 @@ "type": "object" }, "Case": { + "additionalProperties": true, "description": "Case ops - nodes valid inside Conditional nodes.", "properties": { "parent": { @@ -256,6 +310,7 @@ "type": "object" }, "Conditional": { + "additionalProperties": true, "description": "Conditional operation, defined by child `Case` nodes for each branch.", "properties": { "parent": { @@ -310,6 +365,7 @@ "type": "object" }, "Const": { + "additionalProperties": true, "description": "A Const operation definition.", "properties": { "parent": { @@ -333,7 +389,6 @@ } }, "required": [ - "op", "parent", "v" ], @@ -341,7 +396,8 @@ "type": "object" }, "CustomOp": { - "description": "A user-defined operation that can be downcasted by the extensions that define it.", + "additionalProperties": true, + "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", "properties": { "parent": { "title": "Parent", @@ -392,6 +448,7 @@ "type": "object" }, "CustomTypeArg": { + "additionalProperties": true, "properties": { "typ": { "title": "Typ", @@ -410,6 +467,7 @@ "type": "object" }, "DFG": { + "additionalProperties": true, "description": "A simply nested dataflow graph.", "properties": { "parent": { @@ -439,7 +497,8 @@ "type": "object" }, "DataflowBlock": { - "description": "A CFG basic block node. The signature is that of the internal Dataflow graph.", + "additionalProperties": true, + "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", "properties": { "parent": { "title": "Parent", @@ -486,18 +545,14 @@ } }, "required": [ - "parent", - "op", - "inputs", - "other_outputs", - "sum_rows", - "extension_delta" + "parent" ], "title": "DataflowBlock", "type": "object" }, "ExitBlock": { - "description": "The single exit node of the CFG, has no children, stores the types of the CFG node output.", + "additionalProperties": true, + "description": "The single exit node of the CFG, has no children, stores the types of\nthe CFG node output.", "properties": { "parent": { "title": "Parent", @@ -547,6 +602,7 @@ "title": "ExtensionSet" }, "ExtensionValue": { + "additionalProperties": true, "description": "An extension constant value, that can check it is of a given [CustomType].", "properties": { "c": { @@ -563,13 +619,13 @@ } }, "required": [ - "c", "e" ], "title": "ExtensionValue", "type": "object" }, "ExtensionsArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Extensions", @@ -591,6 +647,7 @@ "type": "object" }, "ExtensionsParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Extensions", @@ -606,6 +663,7 @@ "type": "object" }, "FuncDecl": { + "additionalProperties": true, "description": "External function declaration, linked at runtime.", "properties": { "parent": { @@ -640,6 +698,7 @@ "type": "object" }, "FuncDefn": { + "additionalProperties": true, "description": "A function definition. Children nodes are the body of the definition.", "properties": { "parent": { @@ -674,7 +733,8 @@ "type": "object" }, "FunctionType": { - "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", + "additionalProperties": true, + "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", "properties": { "t": { "const": "G", @@ -711,6 +771,7 @@ "type": "object" }, "FunctionValue": { + "additionalProperties": true, "description": "A higher-order function value.", "properties": { "c": { @@ -727,13 +788,13 @@ } }, "required": [ - "c", "hugr" ], "title": "FunctionValue", "type": "object" }, "GeneralSum": { + "additionalProperties": true, "description": "General sum type that explicitly stores the types of the variants.", "properties": { "s": { @@ -763,6 +824,7 @@ "type": "object" }, "Input": { + "additionalProperties": true, "description": "An input node. The outputs of this node are the inputs to the parent node.", "properties": { "parent": { @@ -796,6 +858,7 @@ "type": "object" }, "Lift": { + "additionalProperties": true, "description": "Fixes some TypeParams of a polymorphic type by providing TypeArgs.", "properties": { "parent": { @@ -835,6 +898,7 @@ "type": "object" }, "ListParam": { + "additionalProperties": true, "properties": { "tp": { "const": "List", @@ -856,6 +920,7 @@ "type": "object" }, "LoadConstant": { + "additionalProperties": true, "description": "An operation that loads a static constant in to the local dataflow graph.", "properties": { "parent": { @@ -886,6 +951,7 @@ "type": "object" }, "LoadFunction": { + "additionalProperties": true, "description": "Load a static function in to the local dataflow graph.", "properties": { "parent": { @@ -927,6 +993,7 @@ "type": "object" }, "MakeTuple": { + "additionalProperties": true, "description": "An operation that packs all its inputs into a tuple.", "properties": { "parent": { @@ -960,6 +1027,7 @@ "type": "object" }, "Module": { + "additionalProperties": true, "description": "The root of a module, parent of all other `ModuleOp`s.", "properties": { "parent": { @@ -986,6 +1054,7 @@ "type": "object" }, "Noop": { + "additionalProperties": true, "description": "A no-op operation.", "properties": { "parent": { @@ -1020,6 +1089,7 @@ "discriminator": { "mapping": { "AliasDecl": "#/$defs/AliasDecl", + "AliasDefn": "#/$defs/AliasDefn", "CFG": "#/$defs/CFG", "Call": "#/$defs/Call", "CallIndirect": "#/$defs/CallIndirect", @@ -1118,11 +1188,15 @@ }, { "$ref": "#/$defs/AliasDecl" + }, + { + "$ref": "#/$defs/AliasDefn" } ], "title": "OpType" }, "Opaque": { + "additionalProperties": true, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { "t": { @@ -1163,6 +1237,7 @@ "type": "object" }, "OpaqueArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Opaque", @@ -1184,6 +1259,7 @@ "type": "object" }, "OpaqueParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Opaque", @@ -1205,6 +1281,7 @@ "type": "object" }, "Output": { + "additionalProperties": true, "description": "An output node. The inputs are the outputs of the function.", "properties": { "parent": { @@ -1238,7 +1315,8 @@ "type": "object" }, "PolyFuncType": { - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", + "additionalProperties": true, + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -1259,6 +1337,7 @@ "type": "object" }, "Qubit": { + "additionalProperties": true, "description": "A qubit.", "properties": { "t": { @@ -1275,6 +1354,7 @@ "type": "object" }, "SequenceArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Sequence", @@ -1318,7 +1398,8 @@ "title": "SumType" }, "SumValue": { - "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", + "additionalProperties": true, + "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", "properties": { "c": { "const": "Sum", @@ -1345,7 +1426,6 @@ } }, "required": [ - "c", "tag", "typ", "vs" @@ -1354,6 +1434,7 @@ "type": "object" }, "Tag": { + "additionalProperties": true, "description": "An operation that creates a tagged sum value from one of its variants.", "properties": { "parent": { @@ -1396,6 +1477,7 @@ "type": "object" }, "TaggedSumType": { + "additionalProperties": true, "properties": { "t": { "const": "Sum", @@ -1417,6 +1499,7 @@ "type": "object" }, "TailLoop": { + "additionalProperties": true, "description": "Tail-controlled loop.", "properties": { "parent": { @@ -1464,6 +1547,7 @@ "type": "object" }, "TupleParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Tuple", @@ -1489,6 +1573,7 @@ "type": "object" }, "TupleValue": { + "additionalProperties": true, "description": "A constant tuple value.", "properties": { "c": { @@ -1509,7 +1594,6 @@ } }, "required": [ - "c", "vs" ], "title": "TupleValue", @@ -1634,6 +1718,7 @@ "title": "TypeParam" }, "TypeTypeArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Type", @@ -1655,6 +1740,7 @@ "type": "object" }, "TypeTypeParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Type", @@ -1676,6 +1762,7 @@ "type": "object" }, "USize": { + "additionalProperties": true, "description": "Unsigned integer size type.", "properties": { "t": { @@ -1692,6 +1779,7 @@ "type": "object" }, "UnitSum": { + "additionalProperties": true, "description": "Simple sum type where all variants are empty tuples.", "properties": { "s": { @@ -1715,6 +1803,7 @@ "type": "object" }, "UnpackTuple": { + "additionalProperties": true, "description": "An operation that packs all its inputs into a tuple.", "properties": { "parent": { @@ -1775,6 +1864,7 @@ "title": "Value" }, "Variable": { + "additionalProperties": true, "description": "A type variable identified by an index into the array of TypeParams.", "properties": { "t": { diff --git a/specification/schema/testing_hugr_schema_strict_v1.json b/specification/schema/testing_hugr_schema_strict_v1.json new file mode 100644 index 000000000..0af373dad --- /dev/null +++ b/specification/schema/testing_hugr_schema_strict_v1.json @@ -0,0 +1,1965 @@ +{ + "$defs": { + "Alias": { + "additionalProperties": false, + "description": "An Alias Type", + "properties": { + "t": { + "const": "Alias", + "default": "Alias", + "enum": [ + "Alias" + ], + "title": "T", + "type": "string" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": [ + "bound", + "name" + ], + "title": "Alias", + "type": "object" + }, + "AliasDecl": { + "additionalProperties": false, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDecl", + "default": "AliasDecl", + "enum": [ + "AliasDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "parent", + "name", + "bound" + ], + "title": "AliasDecl", + "type": "object" + }, + "AliasDefn": { + "additionalProperties": false, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDefn", + "default": "AliasDefn", + "enum": [ + "AliasDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "definition": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "name", + "definition" + ], + "title": "AliasDefn", + "type": "object" + }, + "Array": { + "additionalProperties": false, + "description": "Known size array whose elements are of the same type.", + "properties": { + "ty": { + "$ref": "#/$defs/Type" + }, + "t": { + "const": "Array", + "default": "Array", + "enum": [ + "Array" + ], + "title": "T", + "type": "string" + }, + "len": { + "title": "Len", + "type": "integer" + } + }, + "required": [ + "ty", + "len" + ], + "title": "Array", + "type": "object" + }, + "BoundedNatArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tya", + "type": "string" + }, + "n": { + "title": "N", + "type": "integer" + } + }, + "required": [ + "n" + ], + "title": "BoundedNatArg", + "type": "object" + }, + "BoundedNatParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tp", + "type": "string" + }, + "bound": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Bound" + } + }, + "required": [ + "bound" + ], + "title": "BoundedNatParam", + "type": "object" + }, + "CFG": { + "additionalProperties": false, + "description": "A dataflow node which is defined by a child CFG.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CFG", + "default": "CFG", + "enum": [ + "CFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CFG", + "type": "object" + }, + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Call", + "default": "Call", + "enum": [ + "Call" + ], + "title": "Op", + "type": "string" + }, + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "instantiation": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Call", + "type": "object" + }, + "CallIndirect": { + "additionalProperties": false, + "description": "Call a function indirectly.\n\nLike call, but the first input is a standard dataflow graph type.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CallIndirect", + "default": "CallIndirect", + "enum": [ + "CallIndirect" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CallIndirect", + "type": "object" + }, + "Case": { + "additionalProperties": false, + "description": "Case ops - nodes valid inside Conditional nodes.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Case", + "default": "Case", + "enum": [ + "Case" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Case", + "type": "object" + }, + "Conditional": { + "additionalProperties": false, + "description": "Conditional operation, defined by child `Case` nodes for each branch.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Conditional", + "default": "Conditional", + "enum": [ + "Conditional" + ], + "title": "Op", + "type": "string" + }, + "other_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Inputs", + "type": "array" + }, + "outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Outputs", + "type": "array" + }, + "sum_rows": { + "description": "The possible rows of the Sum input", + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "title": "Conditional", + "type": "object" + }, + "Const": { + "additionalProperties": false, + "description": "A Const operation definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Const", + "default": "Const", + "enum": [ + "Const" + ], + "title": "Op", + "type": "string" + }, + "v": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "parent", + "v" + ], + "title": "Const", + "type": "object" + }, + "CustomOp": { + "additionalProperties": false, + "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CustomOp", + "default": "CustomOp", + "enum": [ + "CustomOp" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "op_name": { + "title": "Op 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", + "op_name" + ], + "title": "CustomOp", + "type": "object" + }, + "CustomTypeArg": { + "additionalProperties": false, + "properties": { + "typ": { + "title": "Typ", + "type": "null" + }, + "value": { + "title": "Value", + "type": "string" + } + }, + "required": [ + "typ", + "value" + ], + "title": "CustomTypeArg", + "type": "object" + }, + "DFG": { + "additionalProperties": false, + "description": "A simply nested dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DFG", + "default": "DFG", + "enum": [ + "DFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "DFG", + "type": "object" + }, + "DataflowBlock": { + "additionalProperties": false, + "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DataflowBlock", + "default": "DataflowBlock", + "enum": [ + "DataflowBlock" + ], + "title": "Op", + "type": "string" + }, + "inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Inputs", + "type": "array" + }, + "other_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Outputs", + "type": "array" + }, + "sum_rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "ExitBlock", + "default": "ExitBlock", + "enum": [ + "ExitBlock" + ], + "title": "Op", + "type": "string" + }, + "cfg_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Cfg Outputs", + "type": "array" + } + }, + "required": [ + "parent", + "cfg_outputs" + ], + "title": "ExitBlock", + "type": "object" + }, + "ExtensionSet": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "description": "A set of extensions ids.", + "title": "ExtensionSet" + }, + "ExtensionValue": { + "additionalProperties": false, + "description": "An extension constant value, that can check it is of a given [CustomType].", + "properties": { + "c": { + "const": "Extension", + "default": "Extension", + "enum": [ + "Extension" + ], + "title": "ValueTag", + "type": "string" + }, + "e": { + "title": "CustomConst" + } + }, + "required": [ + "e" + ], + "title": "ExtensionValue", + "type": "object" + }, + "ExtensionsArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Extensions", + "default": "Extensions", + "enum": [ + "Extensions" + ], + "title": "Tya", + "type": "string" + }, + "es": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "es" + ], + "title": "ExtensionsArg", + "type": "object" + }, + "ExtensionsParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Extensions", + "default": "Extensions", + "enum": [ + "Extensions" + ], + "title": "Tp", + "type": "string" + } + }, + "title": "ExtensionsParam", + "type": "object" + }, + "FuncDecl": { + "additionalProperties": false, + "description": "External function declaration, linked at runtime.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDecl", + "default": "FuncDecl", + "enum": [ + "FuncDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDecl", + "type": "object" + }, + "FuncDefn": { + "additionalProperties": false, + "description": "A function definition. Children nodes are the body of the definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDefn", + "default": "FuncDefn", + "enum": [ + "FuncDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDefn", + "type": "object" + }, + "FunctionType": { + "additionalProperties": false, + "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "properties": { + "t": { + "const": "G", + "default": "G", + "enum": [ + "G" + ], + "title": "T", + "type": "string" + }, + "input": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Input", + "type": "array" + }, + "output": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Output", + "type": "array" + }, + "extension_reqs": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "input", + "output" + ], + "title": "FunctionType", + "type": "object" + }, + "FunctionValue": { + "additionalProperties": false, + "description": "A higher-order function value.", + "properties": { + "c": { + "const": "Function", + "default": "Function", + "enum": [ + "Function" + ], + "title": "ValueTag", + "type": "string" + }, + "hugr": { + "title": "Hugr" + } + }, + "required": [ + "hugr" + ], + "title": "FunctionValue", + "type": "object" + }, + "GeneralSum": { + "additionalProperties": false, + "description": "General sum type that explicitly stores the types of the variants.", + "properties": { + "s": { + "const": "General", + "default": "General", + "enum": [ + "General" + ], + "title": "S", + "type": "string" + }, + "rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Rows", + "type": "array" + } + }, + "required": [ + "rows" + ], + "title": "GeneralSum", + "type": "object" + }, + "Input": { + "additionalProperties": false, + "description": "An input node. The outputs of this node are the inputs to the parent node.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Input", + "default": "Input", + "enum": [ + "Input" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Input", + "type": "object" + }, + "Lift": { + "additionalProperties": false, + "description": "Fixes some TypeParams of a polymorphic type by providing TypeArgs.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Lift", + "default": "Lift", + "enum": [ + "Lift" + ], + "title": "Op", + "type": "string" + }, + "type_row": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Type Row", + "type": "array" + }, + "new_extension": { + "title": "New Extension", + "type": "string" + } + }, + "required": [ + "parent", + "type_row", + "new_extension" + ], + "title": "Lift", + "type": "object" + }, + "ListParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "List", + "default": "List", + "enum": [ + "List" + ], + "title": "Tp", + "type": "string" + }, + "param": { + "$ref": "#/$defs/TypeParam" + } + }, + "required": [ + "param" + ], + "title": "ListParam", + "type": "object" + }, + "LoadConstant": { + "additionalProperties": false, + "description": "An operation that loads a static constant in to the local dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadConstant", + "default": "LoadConstant", + "enum": [ + "LoadConstant" + ], + "title": "Op", + "type": "string" + }, + "datatype": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "datatype" + ], + "title": "LoadConstant", + "type": "object" + }, + "LoadFunction": { + "additionalProperties": false, + "description": "Load a static function in to the local dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadFunction", + "default": "LoadFunction", + "enum": [ + "LoadFunction" + ], + "title": "Op", + "type": "string" + }, + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent", + "func_sig", + "type_args" + ], + "title": "LoadFunction", + "type": "object" + }, + "MakeTuple": { + "additionalProperties": false, + "description": "An operation that packs all its inputs into a tuple.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "MakeTuple", + "default": "MakeTuple", + "enum": [ + "MakeTuple" + ], + "title": "Op", + "type": "string" + }, + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "MakeTuple", + "type": "object" + }, + "Module": { + "additionalProperties": false, + "description": "The root of a module, parent of all other `ModuleOp`s.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Module", + "default": "Module", + "enum": [ + "Module" + ], + "title": "Op", + "type": "string" + } + }, + "required": [ + "parent" + ], + "title": "Module", + "type": "object" + }, + "Noop": { + "additionalProperties": false, + "description": "A no-op operation.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Noop", + "default": "Noop", + "enum": [ + "Noop" + ], + "title": "Op", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "ty" + ], + "title": "Noop", + "type": "object" + }, + "OpType": { + "description": "A constant operation.", + "discriminator": { + "mapping": { + "AliasDecl": "#/$defs/AliasDecl", + "AliasDefn": "#/$defs/AliasDefn", + "CFG": "#/$defs/CFG", + "Call": "#/$defs/Call", + "CallIndirect": "#/$defs/CallIndirect", + "Case": "#/$defs/Case", + "Conditional": "#/$defs/Conditional", + "Const": "#/$defs/Const", + "CustomOp": "#/$defs/CustomOp", + "DFG": "#/$defs/DFG", + "DataflowBlock": "#/$defs/DataflowBlock", + "ExitBlock": "#/$defs/ExitBlock", + "FuncDecl": "#/$defs/FuncDecl", + "FuncDefn": "#/$defs/FuncDefn", + "Input": "#/$defs/Input", + "Lift": "#/$defs/Lift", + "LoadConstant": "#/$defs/LoadConstant", + "LoadFunction": "#/$defs/LoadFunction", + "MakeTuple": "#/$defs/MakeTuple", + "Module": "#/$defs/Module", + "Noop": "#/$defs/Noop", + "Output": "#/$defs/Output", + "Tag": "#/$defs/Tag", + "TailLoop": "#/$defs/TailLoop", + "UnpackTuple": "#/$defs/UnpackTuple" + }, + "propertyName": "op" + }, + "oneOf": [ + { + "$ref": "#/$defs/Module" + }, + { + "$ref": "#/$defs/Case" + }, + { + "$ref": "#/$defs/FuncDefn" + }, + { + "$ref": "#/$defs/FuncDecl" + }, + { + "$ref": "#/$defs/Const" + }, + { + "$ref": "#/$defs/DataflowBlock" + }, + { + "$ref": "#/$defs/ExitBlock" + }, + { + "$ref": "#/$defs/Conditional" + }, + { + "$ref": "#/$defs/TailLoop" + }, + { + "$ref": "#/$defs/CFG" + }, + { + "$ref": "#/$defs/Input" + }, + { + "$ref": "#/$defs/Output" + }, + { + "$ref": "#/$defs/Call" + }, + { + "$ref": "#/$defs/CallIndirect" + }, + { + "$ref": "#/$defs/LoadConstant" + }, + { + "$ref": "#/$defs/LoadFunction" + }, + { + "$ref": "#/$defs/CustomOp" + }, + { + "$ref": "#/$defs/Noop" + }, + { + "$ref": "#/$defs/MakeTuple" + }, + { + "$ref": "#/$defs/UnpackTuple" + }, + { + "$ref": "#/$defs/Tag" + }, + { + "$ref": "#/$defs/Lift" + }, + { + "$ref": "#/$defs/DFG" + }, + { + "$ref": "#/$defs/AliasDecl" + }, + { + "$ref": "#/$defs/AliasDefn" + } + ], + "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" + }, + "id": { + "title": "Id", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "extension", + "id", + "args", + "bound" + ], + "title": "Opaque", + "type": "object" + }, + "OpaqueArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tya", + "type": "string" + }, + "arg": { + "$ref": "#/$defs/CustomTypeArg" + } + }, + "required": [ + "arg" + ], + "title": "OpaqueArg", + "type": "object" + }, + "OpaqueParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tp", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Opaque" + } + }, + "required": [ + "ty" + ], + "title": "OpaqueParam", + "type": "object" + }, + "Output": { + "additionalProperties": false, + "description": "An output node. The inputs are the outputs of the function.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Output", + "default": "Output", + "enum": [ + "Output" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Output", + "type": "object" + }, + "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.)", + "properties": { + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + }, + "body": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "params", + "body" + ], + "title": "PolyFuncType", + "type": "object" + }, + "Qubit": { + "additionalProperties": false, + "description": "A qubit.", + "properties": { + "t": { + "const": "Q", + "default": "Q", + "enum": [ + "Q" + ], + "title": "T", + "type": "string" + } + }, + "title": "Qubit", + "type": "object" + }, + "SequenceArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Sequence", + "default": "Sequence", + "enum": [ + "Sequence" + ], + "title": "Tya", + "type": "string" + }, + "args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Args", + "type": "array" + } + }, + "required": [ + "args" + ], + "title": "SequenceArg", + "type": "object" + }, + "SumType": { + "discriminator": { + "mapping": { + "General": "#/$defs/GeneralSum", + "Unit": "#/$defs/UnitSum" + }, + "propertyName": "s" + }, + "oneOf": [ + { + "$ref": "#/$defs/UnitSum" + }, + { + "$ref": "#/$defs/GeneralSum" + } + ], + "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", + "properties": { + "c": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "ValueTag", + "type": "string" + }, + "tag": { + "title": "Tag", + "type": "integer" + }, + "typ": { + "$ref": "#/$defs/SumType" + }, + "vs": { + "items": { + "$ref": "#/$defs/Value" + }, + "title": "Vs", + "type": "array" + } + }, + "required": [ + "tag", + "typ", + "vs" + ], + "title": "SumValue", + "type": "object" + }, + "Tag": { + "additionalProperties": false, + "description": "An operation that creates a tagged sum value from one of its variants.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Tag", + "default": "Tag", + "enum": [ + "Tag" + ], + "title": "Op", + "type": "string" + }, + "tag": { + "title": "Tag", + "type": "integer" + }, + "variants": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Variants", + "type": "array" + } + }, + "required": [ + "parent", + "tag", + "variants" + ], + "title": "Tag", + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "TailLoop", + "default": "TailLoop", + "enum": [ + "TailLoop" + ], + "title": "Op", + "type": "string" + }, + "just_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Inputs", + "type": "array" + }, + "just_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Outputs", + "type": "array" + }, + "rest": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Rest", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "TailLoop", + "type": "object" + }, + "TupleParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Tuple", + "default": "Tuple", + "enum": [ + "Tuple" + ], + "title": "Tp", + "type": "string" + }, + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + } + }, + "required": [ + "params" + ], + "title": "TupleParam", + "type": "object" + }, + "TupleValue": { + "additionalProperties": false, + "description": "A constant tuple value.", + "properties": { + "c": { + "const": "Tuple", + "default": "Tuple", + "enum": [ + "Tuple" + ], + "title": "ValueTag", + "type": "string" + }, + "vs": { + "items": { + "$ref": "#/$defs/Value" + }, + "title": "Vs", + "type": "array" + } + }, + "required": [ + "vs" + ], + "title": "TupleValue", + "type": "object" + }, + "Type": { + "description": "A HUGR type.", + "discriminator": { + "mapping": { + "Alias": "#/$defs/Alias", + "Array": "#/$defs/Array", + "G": "#/$defs/FunctionType", + "I": "#/$defs/USize", + "Opaque": "#/$defs/Opaque", + "Q": "#/$defs/Qubit", + "Sum": "#/$defs/TaggedSumType", + "V": "#/$defs/Variable" + }, + "propertyName": "t" + }, + "oneOf": [ + { + "$ref": "#/$defs/Qubit" + }, + { + "$ref": "#/$defs/Variable" + }, + { + "$ref": "#/$defs/USize" + }, + { + "$ref": "#/$defs/FunctionType" + }, + { + "$ref": "#/$defs/Array" + }, + { + "$ref": "#/$defs/TaggedSumType" + }, + { + "$ref": "#/$defs/Opaque" + }, + { + "$ref": "#/$defs/Alias" + } + ], + "title": "Type" + }, + "TypeArg": { + "description": "A type argument.", + "discriminator": { + "mapping": { + "BoundedNat": "#/$defs/BoundedNatArg", + "Extensions": "#/$defs/ExtensionsArg", + "Opaque": "#/$defs/OpaqueArg", + "Sequence": "#/$defs/SequenceArg", + "Type": "#/$defs/TypeTypeArg" + }, + "propertyName": "tya" + }, + "oneOf": [ + { + "$ref": "#/$defs/TypeTypeArg" + }, + { + "$ref": "#/$defs/BoundedNatArg" + }, + { + "$ref": "#/$defs/OpaqueArg" + }, + { + "$ref": "#/$defs/SequenceArg" + }, + { + "$ref": "#/$defs/ExtensionsArg" + } + ], + "title": "TypeArg" + }, + "TypeBound": { + "enum": [ + "E", + "C", + "A" + ], + "title": "TypeBound", + "type": "string" + }, + "TypeParam": { + "description": "A type parameter.", + "discriminator": { + "mapping": { + "BoundedNat": "#/$defs/BoundedNatParam", + "Extensions": "#/$defs/ExtensionsParam", + "List": "#/$defs/ListParam", + "Opaque": "#/$defs/OpaqueParam", + "Tuple": "#/$defs/TupleParam", + "Type": "#/$defs/TypeTypeParam" + }, + "propertyName": "tp" + }, + "oneOf": [ + { + "$ref": "#/$defs/TypeTypeParam" + }, + { + "$ref": "#/$defs/BoundedNatParam" + }, + { + "$ref": "#/$defs/OpaqueParam" + }, + { + "$ref": "#/$defs/ListParam" + }, + { + "$ref": "#/$defs/TupleParam" + }, + { + "$ref": "#/$defs/ExtensionsParam" + } + ], + "title": "TypeParam" + }, + "TypeTypeArg": { + "additionalProperties": false, + "properties": { + "tya": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tya", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "ty" + ], + "title": "TypeTypeArg", + "type": "object" + }, + "TypeTypeParam": { + "additionalProperties": false, + "properties": { + "tp": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tp", + "type": "string" + }, + "b": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "b" + ], + "title": "TypeTypeParam", + "type": "object" + }, + "USize": { + "additionalProperties": false, + "description": "Unsigned integer size type.", + "properties": { + "t": { + "const": "I", + "default": "I", + "enum": [ + "I" + ], + "title": "T", + "type": "string" + } + }, + "title": "USize", + "type": "object" + }, + "UnitSum": { + "additionalProperties": false, + "description": "Simple sum type where all variants are empty tuples.", + "properties": { + "s": { + "const": "Unit", + "default": "Unit", + "enum": [ + "Unit" + ], + "title": "S", + "type": "string" + }, + "size": { + "title": "Size", + "type": "integer" + } + }, + "required": [ + "size" + ], + "title": "UnitSum", + "type": "object" + }, + "UnpackTuple": { + "additionalProperties": false, + "description": "An operation that packs all its inputs into a tuple.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "UnpackTuple", + "default": "UnpackTuple", + "enum": [ + "UnpackTuple" + ], + "title": "Op", + "type": "string" + }, + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "UnpackTuple", + "type": "object" + }, + "Value": { + "description": "A constant Value.", + "discriminator": { + "mapping": { + "Extension": "#/$defs/ExtensionValue", + "Function": "#/$defs/FunctionValue", + "Sum": "#/$defs/SumValue", + "Tuple": "#/$defs/TupleValue" + }, + "propertyName": "c" + }, + "oneOf": [ + { + "$ref": "#/$defs/ExtensionValue" + }, + { + "$ref": "#/$defs/FunctionValue" + }, + { + "$ref": "#/$defs/TupleValue" + }, + { + "$ref": "#/$defs/SumValue" + } + ], + "title": "Value" + }, + "Variable": { + "additionalProperties": false, + "description": "A type variable identified by an index into the array of TypeParams.", + "properties": { + "t": { + "const": "V", + "default": "V", + "enum": [ + "V" + ], + "title": "T", + "type": "string" + }, + "i": { + "title": "I", + "type": "integer" + }, + "b": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "i", + "b" + ], + "title": "Variable", + "type": "object" + } + }, + "additionalProperties": false, + "description": "A serializable representation of a Hugr Type, SumType, PolyFuncType,\nValue, OpType. Intended for testing only.", + "properties": { + "version": { + "const": "v1", + "default": "v1", + "enum": [ + "v1" + ], + "title": "Version", + "type": "string" + }, + "typ": { + "anyOf": [ + { + "$ref": "#/$defs/Type" + }, + { + "type": "null" + } + ], + "default": null + }, + "sum_type": { + "anyOf": [ + { + "$ref": "#/$defs/SumType" + }, + { + "type": "null" + } + ], + "default": null + }, + "poly_func_type": { + "anyOf": [ + { + "$ref": "#/$defs/PolyFuncType" + }, + { + "type": "null" + } + ], + "default": null + }, + "value": { + "anyOf": [ + { + "$ref": "#/$defs/Value" + }, + { + "type": "null" + } + ], + "default": null + }, + "optype": { + "anyOf": [ + { + "$ref": "#/$defs/OpType" + }, + { + "type": "null" + } + ], + "default": null + } + }, + "title": "TestingHugr", + "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 49240bcfd..4628c337b 100644 --- a/specification/schema/testing_hugr_schema_v1.json +++ b/specification/schema/testing_hugr_schema_v1.json @@ -1,6 +1,7 @@ { "$defs": { "Alias": { + "additionalProperties": true, "description": "An Alias Type", "properties": { "t": { @@ -27,7 +28,78 @@ "title": "Alias", "type": "object" }, + "AliasDecl": { + "additionalProperties": true, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDecl", + "default": "AliasDecl", + "enum": [ + "AliasDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "bound": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "parent", + "name", + "bound" + ], + "title": "AliasDecl", + "type": "object" + }, + "AliasDefn": { + "additionalProperties": true, + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "AliasDefn", + "default": "AliasDefn", + "enum": [ + "AliasDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "definition": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "parent", + "name", + "definition" + ], + "title": "AliasDefn", + "type": "object" + }, "Array": { + "additionalProperties": true, "description": "Known size array whose elements are of the same type.", "properties": { "ty": { @@ -55,6 +127,7 @@ "type": "object" }, "BoundedNatArg": { + "additionalProperties": true, "properties": { "tya": { "const": "BoundedNat", @@ -77,6 +150,7 @@ "type": "object" }, "BoundedNatParam": { + "additionalProperties": true, "properties": { "tp": { "const": "BoundedNat", @@ -105,7 +179,276 @@ "title": "BoundedNatParam", "type": "object" }, + "CFG": { + "additionalProperties": true, + "description": "A dataflow node which is defined by a child CFG.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CFG", + "default": "CFG", + "enum": [ + "CFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CFG", + "type": "object" + }, + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Call", + "default": "Call", + "enum": [ + "Call" + ], + "title": "Op", + "type": "string" + }, + "func_sig": { + "$ref": "#/$defs/PolyFuncType" + }, + "type_args": { + "items": { + "$ref": "#/$defs/TypeArg" + }, + "title": "Type Args", + "type": "array" + }, + "instantiation": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Call", + "type": "object" + }, + "CallIndirect": { + "additionalProperties": true, + "description": "Call a function indirectly.\n\nLike call, but the first input is a standard dataflow graph type.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CallIndirect", + "default": "CallIndirect", + "enum": [ + "CallIndirect" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "CallIndirect", + "type": "object" + }, + "Case": { + "additionalProperties": true, + "description": "Case ops - nodes valid inside Conditional nodes.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Case", + "default": "Case", + "enum": [ + "Case" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "Case", + "type": "object" + }, + "Conditional": { + "additionalProperties": true, + "description": "Conditional operation, defined by child `Case` nodes for each branch.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Conditional", + "default": "Conditional", + "enum": [ + "Conditional" + ], + "title": "Op", + "type": "string" + }, + "other_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Inputs", + "type": "array" + }, + "outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Outputs", + "type": "array" + }, + "sum_rows": { + "description": "The possible rows of the Sum input", + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "title": "Conditional", + "type": "object" + }, + "Const": { + "additionalProperties": true, + "description": "A Const operation definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Const", + "default": "Const", + "enum": [ + "Const" + ], + "title": "Op", + "type": "string" + }, + "v": { + "$ref": "#/$defs/Value" + } + }, + "required": [ + "parent", + "v" + ], + "title": "Const", + "type": "object" + }, + "CustomOp": { + "additionalProperties": true, + "description": "A user-defined operation that can be downcasted by the extensions that define\nit.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "CustomOp", + "default": "CustomOp", + "enum": [ + "CustomOp" + ], + "title": "Op", + "type": "string" + }, + "extension": { + "title": "Extension", + "type": "string" + }, + "op_name": { + "title": "Op 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", + "op_name" + ], + "title": "CustomOp", + "type": "object" + }, "CustomTypeArg": { + "additionalProperties": true, "properties": { "typ": { "title": "Typ", @@ -123,6 +466,125 @@ "title": "CustomTypeArg", "type": "object" }, + "DFG": { + "additionalProperties": true, + "description": "A simply nested dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DFG", + "default": "DFG", + "enum": [ + "DFG" + ], + "title": "Op", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "parent" + ], + "title": "DFG", + "type": "object" + }, + "DataflowBlock": { + "additionalProperties": true, + "description": "A CFG basic block node. The signature is that of the internal Dataflow\ngraph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "DataflowBlock", + "default": "DataflowBlock", + "enum": [ + "DataflowBlock" + ], + "title": "Op", + "type": "string" + }, + "inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Inputs", + "type": "array" + }, + "other_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Other Outputs", + "type": "array" + }, + "sum_rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Sum Rows", + "type": "array" + }, + "extension_delta": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "parent" + ], + "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.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "ExitBlock", + "default": "ExitBlock", + "enum": [ + "ExitBlock" + ], + "title": "Op", + "type": "string" + }, + "cfg_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Cfg Outputs", + "type": "array" + } + }, + "required": [ + "parent", + "cfg_outputs" + ], + "title": "ExitBlock", + "type": "object" + }, "ExtensionSet": { "anyOf": [ { @@ -140,6 +602,7 @@ "title": "ExtensionSet" }, "ExtensionValue": { + "additionalProperties": true, "description": "An extension constant value, that can check it is of a given [CustomType].", "properties": { "c": { @@ -156,13 +619,13 @@ } }, "required": [ - "c", "e" ], "title": "ExtensionValue", "type": "object" }, "ExtensionsArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Extensions", @@ -184,131 +647,556 @@ "type": "object" }, "ExtensionsParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Extensions", "default": "Extensions", "enum": [ - "Extensions" + "Extensions" + ], + "title": "Tp", + "type": "string" + } + }, + "title": "ExtensionsParam", + "type": "object" + }, + "FuncDecl": { + "additionalProperties": true, + "description": "External function declaration, linked at runtime.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDecl", + "default": "FuncDecl", + "enum": [ + "FuncDecl" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDecl", + "type": "object" + }, + "FuncDefn": { + "additionalProperties": true, + "description": "A function definition. Children nodes are the body of the definition.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "FuncDefn", + "default": "FuncDefn", + "enum": [ + "FuncDefn" + ], + "title": "Op", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "signature": { + "$ref": "#/$defs/PolyFuncType" + } + }, + "required": [ + "parent", + "name" + ], + "title": "FuncDefn", + "type": "object" + }, + "FunctionType": { + "additionalProperties": true, + "description": "A graph encoded as a value. It contains a concrete signature and a set of\nrequired resources.", + "properties": { + "t": { + "const": "G", + "default": "G", + "enum": [ + "G" + ], + "title": "T", + "type": "string" + }, + "input": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Input", + "type": "array" + }, + "output": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Output", + "type": "array" + }, + "extension_reqs": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "input", + "output" + ], + "title": "FunctionType", + "type": "object" + }, + "FunctionValue": { + "additionalProperties": true, + "description": "A higher-order function value.", + "properties": { + "c": { + "const": "Function", + "default": "Function", + "enum": [ + "Function" + ], + "title": "ValueTag", + "type": "string" + }, + "hugr": { + "title": "Hugr" + } + }, + "required": [ + "hugr" + ], + "title": "FunctionValue", + "type": "object" + }, + "GeneralSum": { + "additionalProperties": true, + "description": "General sum type that explicitly stores the types of the variants.", + "properties": { + "s": { + "const": "General", + "default": "General", + "enum": [ + "General" + ], + "title": "S", + "type": "string" + }, + "rows": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Rows", + "type": "array" + } + }, + "required": [ + "rows" + ], + "title": "GeneralSum", + "type": "object" + }, + "Input": { + "additionalProperties": true, + "description": "An input node. The outputs of this node are the inputs to the parent node.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Input", + "default": "Input", + "enum": [ + "Input" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Input", + "type": "object" + }, + "Lift": { + "additionalProperties": true, + "description": "Fixes some TypeParams of a polymorphic type by providing TypeArgs.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Lift", + "default": "Lift", + "enum": [ + "Lift" + ], + "title": "Op", + "type": "string" + }, + "type_row": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Type Row", + "type": "array" + }, + "new_extension": { + "title": "New Extension", + "type": "string" + } + }, + "required": [ + "parent", + "type_row", + "new_extension" + ], + "title": "Lift", + "type": "object" + }, + "ListParam": { + "additionalProperties": true, + "properties": { + "tp": { + "const": "List", + "default": "List", + "enum": [ + "List" + ], + "title": "Tp", + "type": "string" + }, + "param": { + "$ref": "#/$defs/TypeParam" + } + }, + "required": [ + "param" + ], + "title": "ListParam", + "type": "object" + }, + "LoadConstant": { + "additionalProperties": true, + "description": "An operation that loads a static constant in to the local dataflow graph.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadConstant", + "default": "LoadConstant", + "enum": [ + "LoadConstant" ], - "title": "Tp", + "title": "Op", "type": "string" + }, + "datatype": { + "$ref": "#/$defs/Type" } }, - "title": "ExtensionsParam", + "required": [ + "parent", + "datatype" + ], + "title": "LoadConstant", "type": "object" }, - "FunctionType": { - "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", + "LoadFunction": { + "additionalProperties": true, + "description": "Load a static function in to the local dataflow graph.", "properties": { - "t": { - "const": "G", - "default": "G", + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "LoadFunction", + "default": "LoadFunction", "enum": [ - "G" + "LoadFunction" ], - "title": "T", + "title": "Op", "type": "string" }, - "input": { - "items": { - "$ref": "#/$defs/Type" - }, - "title": "Input", - "type": "array" + "func_sig": { + "$ref": "#/$defs/PolyFuncType" }, - "output": { + "type_args": { "items": { - "$ref": "#/$defs/Type" + "$ref": "#/$defs/TypeArg" }, - "title": "Output", + "title": "Type Args", "type": "array" }, - "extension_reqs": { - "$ref": "#/$defs/ExtensionSet" + "signature": { + "$ref": "#/$defs/FunctionType" } }, "required": [ - "input", - "output" + "parent", + "func_sig", + "type_args" ], - "title": "FunctionType", + "title": "LoadFunction", "type": "object" }, - "FunctionValue": { - "description": "A higher-order function value.", + "MakeTuple": { + "additionalProperties": true, + "description": "An operation that packs all its inputs into a tuple.", "properties": { - "c": { - "const": "Function", - "default": "Function", + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "MakeTuple", + "default": "MakeTuple", "enum": [ - "Function" + "MakeTuple" ], - "title": "ValueTag", + "title": "Op", "type": "string" }, - "hugr": { - "title": "Hugr" + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" } }, "required": [ - "c", - "hugr" + "parent" ], - "title": "FunctionValue", + "title": "MakeTuple", "type": "object" }, - "GeneralSum": { - "description": "General sum type that explicitly stores the types of the variants.", + "Module": { + "additionalProperties": true, + "description": "The root of a module, parent of all other `ModuleOp`s.", "properties": { - "s": { - "const": "General", - "default": "General", + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Module", + "default": "Module", "enum": [ - "General" + "Module" ], - "title": "S", + "title": "Op", "type": "string" - }, - "rows": { - "items": { - "items": { - "$ref": "#/$defs/Type" - }, - "type": "array" - }, - "title": "Rows", - "type": "array" } }, "required": [ - "rows" + "parent" ], - "title": "GeneralSum", + "title": "Module", "type": "object" }, - "ListParam": { + "Noop": { + "additionalProperties": true, + "description": "A no-op operation.", "properties": { - "tp": { - "const": "List", - "default": "List", + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Noop", + "default": "Noop", "enum": [ - "List" + "Noop" ], - "title": "Tp", + "title": "Op", "type": "string" }, - "param": { - "$ref": "#/$defs/TypeParam" + "ty": { + "$ref": "#/$defs/Type" } }, "required": [ - "param" + "parent", + "ty" ], - "title": "ListParam", + "title": "Noop", "type": "object" }, + "OpType": { + "description": "A constant operation.", + "discriminator": { + "mapping": { + "AliasDecl": "#/$defs/AliasDecl", + "AliasDefn": "#/$defs/AliasDefn", + "CFG": "#/$defs/CFG", + "Call": "#/$defs/Call", + "CallIndirect": "#/$defs/CallIndirect", + "Case": "#/$defs/Case", + "Conditional": "#/$defs/Conditional", + "Const": "#/$defs/Const", + "CustomOp": "#/$defs/CustomOp", + "DFG": "#/$defs/DFG", + "DataflowBlock": "#/$defs/DataflowBlock", + "ExitBlock": "#/$defs/ExitBlock", + "FuncDecl": "#/$defs/FuncDecl", + "FuncDefn": "#/$defs/FuncDefn", + "Input": "#/$defs/Input", + "Lift": "#/$defs/Lift", + "LoadConstant": "#/$defs/LoadConstant", + "LoadFunction": "#/$defs/LoadFunction", + "MakeTuple": "#/$defs/MakeTuple", + "Module": "#/$defs/Module", + "Noop": "#/$defs/Noop", + "Output": "#/$defs/Output", + "Tag": "#/$defs/Tag", + "TailLoop": "#/$defs/TailLoop", + "UnpackTuple": "#/$defs/UnpackTuple" + }, + "propertyName": "op" + }, + "oneOf": [ + { + "$ref": "#/$defs/Module" + }, + { + "$ref": "#/$defs/Case" + }, + { + "$ref": "#/$defs/FuncDefn" + }, + { + "$ref": "#/$defs/FuncDecl" + }, + { + "$ref": "#/$defs/Const" + }, + { + "$ref": "#/$defs/DataflowBlock" + }, + { + "$ref": "#/$defs/ExitBlock" + }, + { + "$ref": "#/$defs/Conditional" + }, + { + "$ref": "#/$defs/TailLoop" + }, + { + "$ref": "#/$defs/CFG" + }, + { + "$ref": "#/$defs/Input" + }, + { + "$ref": "#/$defs/Output" + }, + { + "$ref": "#/$defs/Call" + }, + { + "$ref": "#/$defs/CallIndirect" + }, + { + "$ref": "#/$defs/LoadConstant" + }, + { + "$ref": "#/$defs/LoadFunction" + }, + { + "$ref": "#/$defs/CustomOp" + }, + { + "$ref": "#/$defs/Noop" + }, + { + "$ref": "#/$defs/MakeTuple" + }, + { + "$ref": "#/$defs/UnpackTuple" + }, + { + "$ref": "#/$defs/Tag" + }, + { + "$ref": "#/$defs/Lift" + }, + { + "$ref": "#/$defs/DFG" + }, + { + "$ref": "#/$defs/AliasDecl" + }, + { + "$ref": "#/$defs/AliasDefn" + } + ], + "title": "OpType" + }, "Opaque": { + "additionalProperties": true, "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { "t": { @@ -349,6 +1237,7 @@ "type": "object" }, "OpaqueArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Opaque", @@ -370,6 +1259,7 @@ "type": "object" }, "OpaqueParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Opaque", @@ -390,8 +1280,43 @@ "title": "OpaqueParam", "type": "object" }, + "Output": { + "additionalProperties": true, + "description": "An output node. The inputs are the outputs of the function.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Output", + "default": "Output", + "enum": [ + "Output" + ], + "title": "Op", + "type": "string" + }, + "types": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Types", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "Output", + "type": "object" + }, "PolyFuncType": { - "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", + "additionalProperties": true, + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef.\n(Nodes/operations in the Hugr are not polymorphic.)", "properties": { "params": { "items": { @@ -412,6 +1337,7 @@ "type": "object" }, "Qubit": { + "additionalProperties": true, "description": "A qubit.", "properties": { "t": { @@ -428,6 +1354,7 @@ "type": "object" }, "SequenceArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Sequence", @@ -471,7 +1398,8 @@ "title": "SumType" }, "SumValue": { - "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", + "additionalProperties": true, + "description": "A Sum variant\n\nFor any Sum type where this value meets the type of the variant indicated by the tag", "properties": { "c": { "const": "Sum", @@ -498,7 +1426,6 @@ } }, "required": [ - "c", "tag", "typ", "vs" @@ -506,7 +1433,51 @@ "title": "SumValue", "type": "object" }, + "Tag": { + "additionalProperties": true, + "description": "An operation that creates a tagged sum value from one of its variants.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "Tag", + "default": "Tag", + "enum": [ + "Tag" + ], + "title": "Op", + "type": "string" + }, + "tag": { + "title": "Tag", + "type": "integer" + }, + "variants": { + "items": { + "items": { + "$ref": "#/$defs/Type" + }, + "type": "array" + }, + "title": "Variants", + "type": "array" + } + }, + "required": [ + "parent", + "tag", + "variants" + ], + "title": "Tag", + "type": "object" + }, "TaggedSumType": { + "additionalProperties": true, "properties": { "t": { "const": "Sum", @@ -527,7 +1498,56 @@ "title": "TaggedSumType", "type": "object" }, + "TailLoop": { + "additionalProperties": true, + "description": "Tail-controlled loop.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "TailLoop", + "default": "TailLoop", + "enum": [ + "TailLoop" + ], + "title": "Op", + "type": "string" + }, + "just_inputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Inputs", + "type": "array" + }, + "just_outputs": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Just Outputs", + "type": "array" + }, + "rest": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Rest", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "TailLoop", + "type": "object" + }, "TupleParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Tuple", @@ -553,6 +1573,7 @@ "type": "object" }, "TupleValue": { + "additionalProperties": true, "description": "A constant tuple value.", "properties": { "c": { @@ -573,7 +1594,6 @@ } }, "required": [ - "c", "vs" ], "title": "TupleValue", @@ -698,6 +1718,7 @@ "title": "TypeParam" }, "TypeTypeArg": { + "additionalProperties": true, "properties": { "tya": { "const": "Type", @@ -719,6 +1740,7 @@ "type": "object" }, "TypeTypeParam": { + "additionalProperties": true, "properties": { "tp": { "const": "Type", @@ -740,6 +1762,7 @@ "type": "object" }, "USize": { + "additionalProperties": true, "description": "Unsigned integer size type.", "properties": { "t": { @@ -756,6 +1779,7 @@ "type": "object" }, "UnitSum": { + "additionalProperties": true, "description": "Simple sum type where all variants are empty tuples.", "properties": { "s": { @@ -778,6 +1802,40 @@ "title": "UnitSum", "type": "object" }, + "UnpackTuple": { + "additionalProperties": true, + "description": "An operation that packs all its inputs into a tuple.", + "properties": { + "parent": { + "title": "Parent", + "type": "integer" + }, + "input_extensions": { + "$ref": "#/$defs/ExtensionSet" + }, + "op": { + "const": "UnpackTuple", + "default": "UnpackTuple", + "enum": [ + "UnpackTuple" + ], + "title": "Op", + "type": "string" + }, + "tys": { + "items": { + "$ref": "#/$defs/Type" + }, + "title": "Tys", + "type": "array" + } + }, + "required": [ + "parent" + ], + "title": "UnpackTuple", + "type": "object" + }, "Value": { "description": "A constant Value.", "discriminator": { @@ -806,6 +1864,7 @@ "title": "Value" }, "Variable": { + "additionalProperties": true, "description": "A type variable identified by an index into the array of TypeParams.", "properties": { "t": { @@ -833,7 +1892,8 @@ "type": "object" } }, - "description": "A serializable representation of a Hugr Type, SumType, PolyFuncType, or\nValue. Intended for testing only.", + "additionalProperties": true, + "description": "A serializable representation of a Hugr Type, SumType, PolyFuncType,\nValue, OpType. Intended for testing only.", "properties": { "version": { "const": "v1", @@ -887,8 +1947,19 @@ } ], "default": null + }, + "optype": { + "anyOf": [ + { + "$ref": "#/$defs/OpType" + }, + { + "type": "null" + } + ], + "default": null } }, - "title": "HugrTesting", + "title": "TestingHugr", "type": "object" } \ No newline at end of file