From 68cfac5f63b35e8d709c5738a8893048240d5706 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Thu, 1 Aug 2024 14:56:45 +0100 Subject: [PATCH] feat: `Package` pydantic model for modules + extensions (#1387) Closes #1358 --- hugr-py/src/hugr/__init__.py | 2 +- hugr-py/src/hugr/serialization/extension.py | 14 +- hugr-py/src/hugr/serialization/serial_hugr.py | 4 +- hugr-py/tests/serialization/test_basic.py | 4 +- hugr-py/tests/serialization/test_extension.py | 26 +++- poetry.lock | 64 ++++----- scripts/generate_schema.py | 4 +- specification/schema/hugr_schema_live.json | 23 +++ .../schema/hugr_schema_strict_live.json | 23 +++ .../schema/testing_hugr_schema_live.json | 133 ++++++++++++++++++ .../testing_hugr_schema_strict_live.json | 133 ++++++++++++++++++ 11 files changed, 388 insertions(+), 42 deletions(-) diff --git a/hugr-py/src/hugr/__init__.py b/hugr-py/src/hugr/__init__.py index 7d7108540..a5aabf025 100644 --- a/hugr-py/src/hugr/__init__.py +++ b/hugr-py/src/hugr/__init__.py @@ -7,6 +7,6 @@ __version__ = "0.5.0" -def get_serialisation_version() -> str: +def get_serialization_version() -> str: """Return the current version of the serialization schema.""" return "live" diff --git a/hugr-py/src/hugr/serialization/extension.py b/hugr-py/src/hugr/serialization/extension.py index faa750cce..337149f49 100644 --- a/hugr-py/src/hugr/serialization/extension.py +++ b/hugr-py/src/hugr/serialization/extension.py @@ -3,9 +3,10 @@ import pydantic as pd from pydantic_extra_types.semantic_version import SemanticVersion -from hugr import get_serialisation_version +from hugr import get_serialization_version from .ops import Value +from .serial_hugr import SerialHugr from .tys import ( ConfiguredBaseModel, ExtensionId, @@ -75,4 +76,13 @@ class Extension(ConfiguredBaseModel): @classmethod def get_version(cls) -> str: - return get_serialisation_version() + return get_serialization_version() + + +class Package(ConfiguredBaseModel): + modules: list[SerialHugr] + extensions: list[Extension] = pd.Field(default_factory=list) + + @classmethod + def get_version(cls) -> str: + return get_serialization_version() diff --git a/hugr-py/src/hugr/serialization/serial_hugr.py b/hugr-py/src/hugr/serialization/serial_hugr.py index 93d6236b6..476d23efc 100644 --- a/hugr-py/src/hugr/serialization/serial_hugr.py +++ b/hugr-py/src/hugr/serialization/serial_hugr.py @@ -3,7 +3,7 @@ from pydantic import ConfigDict, Field import hugr -from hugr import get_serialisation_version +from hugr import get_serialization_version from hugr.node_port import NodeIdx, PortOffset from .ops import OpType @@ -14,7 +14,7 @@ Edge = tuple[Port, Port] VersionField = Field( - default_factory=get_serialisation_version, + default_factory=get_serialization_version, title="Version", description="Serialisation Schema Version", frozen=True, diff --git a/hugr-py/tests/serialization/test_basic.py b/hugr-py/tests/serialization/test_basic.py index ae1815bf2..0f8e9209f 100644 --- a/hugr-py/tests/serialization/test_basic.py +++ b/hugr-py/tests/serialization/test_basic.py @@ -1,11 +1,11 @@ -from hugr import get_serialisation_version +from hugr import get_serialization_version from hugr.serialization.serial_hugr import SerialHugr def test_empty(): h = SerialHugr(nodes=[], edges=[]) assert h.model_dump() == { - "version": get_serialisation_version(), + "version": get_serialization_version(), "nodes": [], "edges": [], "metadata": None, diff --git a/hugr-py/tests/serialization/test_extension.py b/hugr-py/tests/serialization/test_extension.py index 03ab6cbc9..9e03731d0 100644 --- a/hugr-py/tests/serialization/test_extension.py +++ b/hugr-py/tests/serialization/test_extension.py @@ -1,12 +1,15 @@ from semver import Version +from hugr import get_serialization_version from hugr.serialization.extension import ( ExplicitBound, Extension, OpDef, + Package, TypeDef, TypeDefBound, ) +from hugr.serialization.serial_hugr import SerialHugr from hugr.serialization.tys import ( FunctionType, PolyFuncType, @@ -71,7 +74,8 @@ """ -def test_deserialize(): +def test_extension(): + assert get_serialization_version() == Extension.get_version() param = TypeParam(root=TypeTypeParam(b=TypeBound.Copyable)) bound = TypeDefBound(root=ExplicitBound(bound=TypeBound.Copyable)) @@ -106,3 +110,23 @@ def test_deserialize(): dumped_json = ext.model_dump_json() assert Extension.model_validate_json(dumped_json) == ext + + +def test_package(): + assert get_serialization_version() == Package.get_version() + + ext = Extension( + version=Version(0, 1, 0), + name="ext", + extension_reqs=set(), + types={}, + values={}, + operations={}, + ) + ext_load = Extension.model_validate_json(EXAMPLE) + package = Package( + extensions=[ext, ext_load], modules=[SerialHugr(nodes=[], edges=[])] + ) + + package_load = Package.model_validate_json(package.model_dump_json()) + assert package == package_load diff --git a/poetry.lock b/poetry.lock index b0700e73c..0609a6784 100644 --- a/poetry.lock +++ b/poetry.lock @@ -143,7 +143,7 @@ typing = ["typing-extensions (>=4.8)"] [[package]] name = "hugr" -version = "0.4.0" +version = "0.5.0" description = "Quantinuum's common representation for quantum programs" optional = false python-versions = ">=3.10" @@ -186,38 +186,38 @@ files = [ [[package]] name = "mypy" -version = "1.11.0" +version = "1.11.1" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" files = [ - {file = "mypy-1.11.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a3824187c99b893f90c845bab405a585d1ced4ff55421fdf5c84cb7710995229"}, - {file = "mypy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:96f8dbc2c85046c81bcddc246232d500ad729cb720da4e20fce3b542cab91287"}, - {file = "mypy-1.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1a5d8d8dd8613a3e2be3eae829ee891b6b2de6302f24766ff06cb2875f5be9c6"}, - {file = "mypy-1.11.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:72596a79bbfb195fd41405cffa18210af3811beb91ff946dbcb7368240eed6be"}, - {file = "mypy-1.11.0-cp310-cp310-win_amd64.whl", hash = "sha256:35ce88b8ed3a759634cb4eb646d002c4cef0a38f20565ee82b5023558eb90c00"}, - {file = "mypy-1.11.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:98790025861cb2c3db8c2f5ad10fc8c336ed2a55f4daf1b8b3f877826b6ff2eb"}, - {file = "mypy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:25bcfa75b9b5a5f8d67147a54ea97ed63a653995a82798221cca2a315c0238c1"}, - {file = "mypy-1.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0bea2a0e71c2a375c9fa0ede3d98324214d67b3cbbfcbd55ac8f750f85a414e3"}, - {file = "mypy-1.11.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d2b3d36baac48e40e3064d2901f2fbd2a2d6880ec6ce6358825c85031d7c0d4d"}, - {file = "mypy-1.11.0-cp311-cp311-win_amd64.whl", hash = "sha256:d8e2e43977f0e09f149ea69fd0556623919f816764e26d74da0c8a7b48f3e18a"}, - {file = "mypy-1.11.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:1d44c1e44a8be986b54b09f15f2c1a66368eb43861b4e82573026e04c48a9e20"}, - {file = "mypy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:cea3d0fb69637944dd321f41bc896e11d0fb0b0aa531d887a6da70f6e7473aba"}, - {file = "mypy-1.11.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a83ec98ae12d51c252be61521aa5731f5512231d0b738b4cb2498344f0b840cd"}, - {file = "mypy-1.11.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:c7b73a856522417beb78e0fb6d33ef89474e7a622db2653bc1285af36e2e3e3d"}, - {file = "mypy-1.11.0-cp312-cp312-win_amd64.whl", hash = "sha256:f2268d9fcd9686b61ab64f077be7ffbc6fbcdfb4103e5dd0cc5eaab53a8886c2"}, - {file = "mypy-1.11.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:940bfff7283c267ae6522ef926a7887305945f716a7704d3344d6d07f02df850"}, - {file = "mypy-1.11.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:14f9294528b5f5cf96c721f231c9f5b2733164e02c1c018ed1a0eff8a18005ac"}, - {file = "mypy-1.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d7b54c27783991399046837df5c7c9d325d921394757d09dbcbf96aee4649fe9"}, - {file = "mypy-1.11.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:65f190a6349dec29c8d1a1cd4aa71284177aee5949e0502e6379b42873eddbe7"}, - {file = "mypy-1.11.0-cp38-cp38-win_amd64.whl", hash = "sha256:dbe286303241fea8c2ea5466f6e0e6a046a135a7e7609167b07fd4e7baf151bf"}, - {file = "mypy-1.11.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:104e9c1620c2675420abd1f6c44bab7dd33cc85aea751c985006e83dcd001095"}, - {file = "mypy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f006e955718ecd8d159cee9932b64fba8f86ee6f7728ca3ac66c3a54b0062abe"}, - {file = "mypy-1.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:becc9111ca572b04e7e77131bc708480cc88a911adf3d0239f974c034b78085c"}, - {file = "mypy-1.11.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:6801319fe76c3f3a3833f2b5af7bd2c17bb93c00026a2a1b924e6762f5b19e13"}, - {file = "mypy-1.11.0-cp39-cp39-win_amd64.whl", hash = "sha256:c1a184c64521dc549324ec6ef7cbaa6b351912be9cb5edb803c2808a0d7e85ac"}, - {file = "mypy-1.11.0-py3-none-any.whl", hash = "sha256:56913ec8c7638b0091ef4da6fcc9136896914a9d60d54670a75880c3e5b99ace"}, - {file = "mypy-1.11.0.tar.gz", hash = "sha256:93743608c7348772fdc717af4aeee1997293a1ad04bc0ea6efa15bf65385c538"}, + {file = "mypy-1.11.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a32fc80b63de4b5b3e65f4be82b4cfa362a46702672aa6a0f443b4689af7008c"}, + {file = "mypy-1.11.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c1952f5ea8a5a959b05ed5f16452fddadbaae48b5d39235ab4c3fc444d5fd411"}, + {file = "mypy-1.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e1e30dc3bfa4e157e53c1d17a0dad20f89dc433393e7702b813c10e200843b03"}, + {file = "mypy-1.11.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2c63350af88f43a66d3dfeeeb8d77af34a4f07d760b9eb3a8697f0386c7590b4"}, + {file = "mypy-1.11.1-cp310-cp310-win_amd64.whl", hash = "sha256:a831671bad47186603872a3abc19634f3011d7f83b083762c942442d51c58d58"}, + {file = "mypy-1.11.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7b6343d338390bb946d449677726edf60102a1c96079b4f002dedff375953fc5"}, + {file = "mypy-1.11.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e4fe9f4e5e521b458d8feb52547f4bade7ef8c93238dfb5bbc790d9ff2d770ca"}, + {file = "mypy-1.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:886c9dbecc87b9516eff294541bf7f3655722bf22bb898ee06985cd7269898de"}, + {file = "mypy-1.11.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:fca4a60e1dd9fd0193ae0067eaeeb962f2d79e0d9f0f66223a0682f26ffcc809"}, + {file = "mypy-1.11.1-cp311-cp311-win_amd64.whl", hash = "sha256:0bd53faf56de9643336aeea1c925012837432b5faf1701ccca7fde70166ccf72"}, + {file = "mypy-1.11.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f39918a50f74dc5969807dcfaecafa804fa7f90c9d60506835036cc1bc891dc8"}, + {file = "mypy-1.11.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0bc71d1fb27a428139dd78621953effe0d208aed9857cb08d002280b0422003a"}, + {file = "mypy-1.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b868d3bcff720dd7217c383474008ddabaf048fad8d78ed948bb4b624870a417"}, + {file = "mypy-1.11.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a707ec1527ffcdd1c784d0924bf5cb15cd7f22683b919668a04d2b9c34549d2e"}, + {file = "mypy-1.11.1-cp312-cp312-win_amd64.whl", hash = "sha256:64f4a90e3ea07f590c5bcf9029035cf0efeae5ba8be511a8caada1a4893f5525"}, + {file = "mypy-1.11.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:749fd3213916f1751fff995fccf20c6195cae941dc968f3aaadf9bb4e430e5a2"}, + {file = "mypy-1.11.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b639dce63a0b19085213ec5fdd8cffd1d81988f47a2dec7100e93564f3e8fb3b"}, + {file = "mypy-1.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4c956b49c5d865394d62941b109728c5c596a415e9c5b2be663dd26a1ff07bc0"}, + {file = "mypy-1.11.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:45df906e8b6804ef4b666af29a87ad9f5921aad091c79cc38e12198e220beabd"}, + {file = "mypy-1.11.1-cp38-cp38-win_amd64.whl", hash = "sha256:d44be7551689d9d47b7abc27c71257adfdb53f03880841a5db15ddb22dc63edb"}, + {file = "mypy-1.11.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2684d3f693073ab89d76da8e3921883019ea8a3ec20fa5d8ecca6a2db4c54bbe"}, + {file = "mypy-1.11.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:79c07eb282cb457473add5052b63925e5cc97dfab9812ee65a7c7ab5e3cb551c"}, + {file = "mypy-1.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:11965c2f571ded6239977b14deebd3f4c3abd9a92398712d6da3a772974fad69"}, + {file = "mypy-1.11.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a2b43895a0f8154df6519706d9bca8280cda52d3d9d1514b2d9c3e26792a0b74"}, + {file = "mypy-1.11.1-cp39-cp39-win_amd64.whl", hash = "sha256:1a81cf05975fd61aec5ae16501a091cfb9f605dc3e3c878c0da32f250b74760b"}, + {file = "mypy-1.11.1-py3-none-any.whl", hash = "sha256:0624bdb940255d2dd24e829d99a13cfeb72e4e9031f9492148f410ed30bcab54"}, + {file = "mypy-1.11.1.tar.gz", hash = "sha256:f404a0b069709f18bbdb702eb3dcfe51910602995de00bd39cea3050b5772d08"}, ] [package.dependencies] @@ -297,13 +297,13 @@ testing = ["pytest", "pytest-benchmark"] [[package]] name = "pre-commit" -version = "3.7.1" +version = "3.8.0" description = "A framework for managing and maintaining multi-language pre-commit hooks." optional = false python-versions = ">=3.9" files = [ - {file = "pre_commit-3.7.1-py2.py3-none-any.whl", hash = "sha256:fae36fd1d7ad7d6a5a1c0b0d5adb2ed1a3bda5a21bf6c3e5372073d7a11cd4c5"}, - {file = "pre_commit-3.7.1.tar.gz", hash = "sha256:8ca3ad567bc78a4972a3f1a477e94a79d4597e8140a6e0b651c5e33899c3654a"}, + {file = "pre_commit-3.8.0-py2.py3-none-any.whl", hash = "sha256:9a90a53bf82fdd8778d58085faf8d83df56e40dfe18f45b19446e26bf1b3a63f"}, + {file = "pre_commit-3.8.0.tar.gz", hash = "sha256:8bb6494d4a20423842e198980c9ecf9f96607a07ea29549e180eef9ae80fe7af"}, ] [package.dependencies] diff --git a/scripts/generate_schema.py b/scripts/generate_schema.py index 2d66cf837..908bdfa1a 100644 --- a/scripts/generate_schema.py +++ b/scripts/generate_schema.py @@ -16,7 +16,7 @@ from pydantic import ConfigDict from pydantic.json_schema import models_json_schema -from hugr.serialization.extension import Extension +from hugr.serialization.extension import Extension, Package from hugr.serialization.serial_hugr import SerialHugr from hugr.serialization.testing_hugr import TestingHugr @@ -33,7 +33,7 @@ def write_schema( path = out_dir / filename print(f"Rebuilding model with config: {config}") schema._pydantic_rebuild(config or ConfigDict(), force=True, **kwargs) - schemas = [schema, Extension] + schemas = [schema, Extension, Package] print(f"Writing schema to {path}") _, top_level_schema = models_json_schema( [(s, "validation") for s in schemas], title="HUGR schema" diff --git a/specification/schema/hugr_schema_live.json b/specification/schema/hugr_schema_live.json index 95a6b6b8c..9d131adf6 100644 --- a/specification/schema/hugr_schema_live.json +++ b/specification/schema/hugr_schema_live.json @@ -1372,6 +1372,29 @@ "title": "Output", "type": "object" }, + "Package": { + "properties": { + "modules": { + "items": { + "$ref": "#/$defs/SerialHugr" + }, + "title": "Modules", + "type": "array" + }, + "extensions": { + "items": { + "$ref": "#/$defs/Extension" + }, + "title": "Extensions", + "type": "array" + } + }, + "required": [ + "modules" + ], + "title": "Package", + "type": "object" + }, "PolyFuncType": { "additionalProperties": true, "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", diff --git a/specification/schema/hugr_schema_strict_live.json b/specification/schema/hugr_schema_strict_live.json index b95171d95..957493f26 100644 --- a/specification/schema/hugr_schema_strict_live.json +++ b/specification/schema/hugr_schema_strict_live.json @@ -1372,6 +1372,29 @@ "title": "Output", "type": "object" }, + "Package": { + "properties": { + "modules": { + "items": { + "$ref": "#/$defs/SerialHugr" + }, + "title": "Modules", + "type": "array" + }, + "extensions": { + "items": { + "$ref": "#/$defs/Extension" + }, + "title": "Extensions", + "type": "array" + } + }, + "required": [ + "modules" + ], + "title": "Package", + "type": "object" + }, "PolyFuncType": { "additionalProperties": false, "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", diff --git a/specification/schema/testing_hugr_schema_live.json b/specification/schema/testing_hugr_schema_live.json index 632a2c083..c340dc1bd 100644 --- a/specification/schema/testing_hugr_schema_live.json +++ b/specification/schema/testing_hugr_schema_live.json @@ -1372,6 +1372,29 @@ "title": "Output", "type": "object" }, + "Package": { + "properties": { + "modules": { + "items": { + "$ref": "#/$defs/SerialHugr" + }, + "title": "Modules", + "type": "array" + }, + "extensions": { + "items": { + "$ref": "#/$defs/Extension" + }, + "title": "Extensions", + "type": "array" + } + }, + "required": [ + "modules" + ], + "title": "Package", + "type": "object" + }, "PolyFuncType": { "additionalProperties": true, "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", @@ -1465,6 +1488,116 @@ "title": "SequenceArg", "type": "object" }, + "SerialHugr": { + "description": "A serializable representation of a Hugr.", + "properties": { + "version": { + "description": "Serialisation Schema Version", + "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" + }, + "metadata": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "type": "object" + }, + { + "type": "null" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Metadata" + }, + "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" + }, "StringArg": { "additionalProperties": true, "properties": { diff --git a/specification/schema/testing_hugr_schema_strict_live.json b/specification/schema/testing_hugr_schema_strict_live.json index 9fa206355..6e1e6f903 100644 --- a/specification/schema/testing_hugr_schema_strict_live.json +++ b/specification/schema/testing_hugr_schema_strict_live.json @@ -1372,6 +1372,29 @@ "title": "Output", "type": "object" }, + "Package": { + "properties": { + "modules": { + "items": { + "$ref": "#/$defs/SerialHugr" + }, + "title": "Modules", + "type": "array" + }, + "extensions": { + "items": { + "$ref": "#/$defs/Extension" + }, + "title": "Extensions", + "type": "array" + } + }, + "required": [ + "modules" + ], + "title": "Package", + "type": "object" + }, "PolyFuncType": { "additionalProperties": false, "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", @@ -1465,6 +1488,116 @@ "title": "SequenceArg", "type": "object" }, + "SerialHugr": { + "description": "A serializable representation of a Hugr.", + "properties": { + "version": { + "description": "Serialisation Schema Version", + "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" + }, + "metadata": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "type": "object" + }, + { + "type": "null" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Metadata" + }, + "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" + }, "StringArg": { "additionalProperties": false, "properties": {