From 837acde049d97d119dd236af3538decdbf83dbbe Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Wed, 24 Apr 2024 09:41:19 +0100 Subject: [PATCH] rename Testing Schema, add Value --- hugr-py/src/hugr/serialization/ops.py | 4 +- .../{hugrtype.py => testing_hugr.py} | 13 +- hugr-py/src/hugr/serialization/tys.py | 8 +- hugr/src/hugr/serialize.rs | 2 +- hugr/src/hugr/validate.rs | 3 +- justfile | 4 +- poetry.lock | 121 ++-- scripts/generate_schema.py | 4 +- specification/schema/hugr_schema_v1.json | 50 +- .../schema/testing_hugr_schema_v1.json | 679 ++++++++++++++++++ 10 files changed, 785 insertions(+), 103 deletions(-) rename hugr-py/src/hugr/serialization/{hugrtype.py => testing_hugr.py} (51%) create mode 100644 specification/schema/testing_hugr_schema_v1.json diff --git a/hugr-py/src/hugr/serialization/ops.py b/hugr-py/src/hugr/serialization/ops.py index 5d1c5bfdfd..2c8994fa09 100644 --- a/hugr-py/src/hugr/serialization/ops.py +++ b/hugr-py/src/hugr/serialization/ops.py @@ -13,7 +13,7 @@ PolyFuncType, Type, TypeRow, - SumTypeBase, + SumType, TypeBound, ) @@ -128,7 +128,7 @@ class SumValue(BaseModel): c: Literal["Sum"] = Field("Sum", title="ValueTag") tag: int - typ: SumTypeBase + typ: SumType vs: list["Value"] class Config: diff --git a/hugr-py/src/hugr/serialization/hugrtype.py b/hugr-py/src/hugr/serialization/testing_hugr.py similarity index 51% rename from hugr-py/src/hugr/serialization/hugrtype.py rename to hugr-py/src/hugr/serialization/testing_hugr.py index dc8da79396..e5d62c8852 100644 --- a/hugr-py/src/hugr/serialization/hugrtype.py +++ b/hugr-py/src/hugr/serialization/testing_hugr.py @@ -1,13 +1,14 @@ from typing import Any, Literal from pydantic import BaseModel, Field -from .tys import Type, USize, SumTypeBase +from .tys import Type, USize, SumType +from .ops import Value -class HugrType(BaseModel): - """A serializable representation of a Hugr Type. Intended for testing only.""" +class TestingHugr(BaseModel): + """A serializable representation of a Hugr Type, SumType, or Value. Intended for testing only.""" - typ: Type | SumTypeBase - version: Literal["v1"] = "v1" + typ: Type | SumType | Value + version: Literal["v2"] = "v2" @classmethod def get_version(cls) -> str: @@ -15,7 +16,7 @@ def get_version(cls) -> str: return cls(typ=Type(USize())).version class Config: - title = "HugrType" + title = "HugrTesting" json_schema_extra = { "required": ["typ"], } diff --git a/hugr-py/src/hugr/serialization/tys.py b/hugr-py/src/hugr/serialization/tys.py index 252440847f..7b75003c54 100644 --- a/hugr-py/src/hugr/serialization/tys.py +++ b/hugr-py/src/hugr/serialization/tys.py @@ -158,13 +158,13 @@ class GeneralSum(BaseModel): rows: list["TypeRow"] -class SumTypeBase(RootModel): +class SumType(RootModel): root: Union[UnitSum, GeneralSum] = Field(discriminator="s") -class SumType(BaseModel): +class TaggedSumType(BaseModel): t: Literal["Sum"] = "Sum" - st: SumTypeBase + st: SumType # ---------------------------------------------- @@ -287,7 +287,7 @@ class Type(RootModel): """A HUGR type.""" root: Annotated[ - Qubit | Variable | USize | FunctionType | Array | SumType | Opaque | Alias, + Qubit | Variable | USize | FunctionType | Array | TaggedSumType | Opaque | Alias, WrapValidator(_json_custom_error_validator), ] = Field(discriminator="t") diff --git a/hugr/src/hugr/serialize.rs b/hugr/src/hugr/serialize.rs index a5f28ea5bd..450752b121 100644 --- a/hugr/src/hugr/serialize.rs +++ b/hugr/src/hugr/serialize.rs @@ -310,7 +310,7 @@ pub mod test { }; static ref TYPE_SCHEMA: JSONSchema = { let schema_val: serde_json::Value = serde_json::from_str(include_str!( - "../../../specification/schema/test_hugrtype_schema_v1.json" + "../../../specification/schema/testing_hugr_schema_v1.json" )) .unwrap(); JSONSchema::options() diff --git a/hugr/src/hugr/validate.rs b/hugr/src/hugr/validate.rs index 51027087d5..8fbd16aedd 100644 --- a/hugr/src/hugr/validate.rs +++ b/hugr/src/hugr/validate.rs @@ -101,7 +101,8 @@ impl<'a, 'b> ValidationContext<'a, 'b> { // In tests we take the opportunity to verify that the hugr // serialization round-trips. We verify the schema of the serialisation // format only when an environment variable is set. This allows - // development while the schema is broken. + // a developer to modify the definition of serialised types locally + // without having to change the schema. #[cfg(test)] { let test_schema = std::env::var("HUGR_TEST_SCHEMA").is_ok_and(|x| !x.is_empty()); diff --git a/justfile b/justfile index 2b9217e2de..474ffc1c2b 100644 --- a/justfile +++ b/justfile @@ -13,8 +13,8 @@ check: poetry run pre-commit run --all-files # Run all the tests. -test language="[rust|python]": (_run_lang language \ - "HUGR_TEST_SCHEMA=1 cargo test --all-features" \ +test language="[rust|python]" : (_run_lang language \ + "HUGR_TEST_SCHEMA=\"1\" cargo test --all-features" \ "poetry run pytest" ) diff --git a/poetry.lock b/poetry.lock index 95c28b919c..bc824a84fd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -35,63 +35,63 @@ files = [ [[package]] name = "coverage" -version = "7.4.4" +version = "7.5.0" description = "Code coverage measurement for Python" optional = false python-versions = ">=3.8" files = [ - {file = "coverage-7.4.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e0be5efd5127542ef31f165de269f77560d6cdef525fffa446de6f7e9186cfb2"}, - {file = "coverage-7.4.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ccd341521be3d1b3daeb41960ae94a5e87abe2f46f17224ba5d6f2b8398016cf"}, - {file = "coverage-7.4.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:09fa497a8ab37784fbb20ab699c246053ac294d13fc7eb40ec007a5043ec91f8"}, - {file = "coverage-7.4.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b1a93009cb80730c9bca5d6d4665494b725b6e8e157c1cb7f2db5b4b122ea562"}, - {file = "coverage-7.4.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:690db6517f09336559dc0b5f55342df62370a48f5469fabf502db2c6d1cffcd2"}, - {file = "coverage-7.4.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:09c3255458533cb76ef55da8cc49ffab9e33f083739c8bd4f58e79fecfe288f7"}, - {file = "coverage-7.4.4-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:8ce1415194b4a6bd0cdcc3a1dfbf58b63f910dcb7330fe15bdff542c56949f87"}, - {file = "coverage-7.4.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b91cbc4b195444e7e258ba27ac33769c41b94967919f10037e6355e998af255c"}, - {file = "coverage-7.4.4-cp310-cp310-win32.whl", hash = "sha256:598825b51b81c808cb6f078dcb972f96af96b078faa47af7dfcdf282835baa8d"}, - {file = "coverage-7.4.4-cp310-cp310-win_amd64.whl", hash = "sha256:09ef9199ed6653989ebbcaacc9b62b514bb63ea2f90256e71fea3ed74bd8ff6f"}, - {file = "coverage-7.4.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:0f9f50e7ef2a71e2fae92774c99170eb8304e3fdf9c8c3c7ae9bab3e7229c5cf"}, - {file = "coverage-7.4.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:623512f8ba53c422fcfb2ce68362c97945095b864cda94a92edbaf5994201083"}, - {file = "coverage-7.4.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0513b9508b93da4e1716744ef6ebc507aff016ba115ffe8ecff744d1322a7b63"}, - {file = "coverage-7.4.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40209e141059b9370a2657c9b15607815359ab3ef9918f0196b6fccce8d3230f"}, - {file = "coverage-7.4.4-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8a2b2b78c78293782fd3767d53e6474582f62443d0504b1554370bde86cc8227"}, - {file = "coverage-7.4.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:73bfb9c09951125d06ee473bed216e2c3742f530fc5acc1383883125de76d9cd"}, - {file = "coverage-7.4.4-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:1f384c3cc76aeedce208643697fb3e8437604b512255de6d18dae3f27655a384"}, - {file = "coverage-7.4.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:54eb8d1bf7cacfbf2a3186019bcf01d11c666bd495ed18717162f7eb1e9dd00b"}, - {file = "coverage-7.4.4-cp311-cp311-win32.whl", hash = "sha256:cac99918c7bba15302a2d81f0312c08054a3359eaa1929c7e4b26ebe41e9b286"}, - {file = "coverage-7.4.4-cp311-cp311-win_amd64.whl", hash = "sha256:b14706df8b2de49869ae03a5ccbc211f4041750cd4a66f698df89d44f4bd30ec"}, - {file = "coverage-7.4.4-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:201bef2eea65e0e9c56343115ba3814e896afe6d36ffd37bab783261db430f76"}, - {file = "coverage-7.4.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:41c9c5f3de16b903b610d09650e5e27adbfa7f500302718c9ffd1c12cf9d6818"}, - {file = "coverage-7.4.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d898fe162d26929b5960e4e138651f7427048e72c853607f2b200909794ed978"}, - {file = "coverage-7.4.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3ea79bb50e805cd6ac058dfa3b5c8f6c040cb87fe83de10845857f5535d1db70"}, - {file = "coverage-7.4.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce4b94265ca988c3f8e479e741693d143026632672e3ff924f25fab50518dd51"}, - {file = "coverage-7.4.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:00838a35b882694afda09f85e469c96367daa3f3f2b097d846a7216993d37f4c"}, - {file = "coverage-7.4.4-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:fdfafb32984684eb03c2d83e1e51f64f0906b11e64482df3c5db936ce3839d48"}, - {file = "coverage-7.4.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:69eb372f7e2ece89f14751fbcbe470295d73ed41ecd37ca36ed2eb47512a6ab9"}, - {file = "coverage-7.4.4-cp312-cp312-win32.whl", hash = "sha256:137eb07173141545e07403cca94ab625cc1cc6bc4c1e97b6e3846270e7e1fea0"}, - {file = "coverage-7.4.4-cp312-cp312-win_amd64.whl", hash = "sha256:d71eec7d83298f1af3326ce0ff1d0ea83c7cb98f72b577097f9083b20bdaf05e"}, - {file = "coverage-7.4.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d5ae728ff3b5401cc320d792866987e7e7e880e6ebd24433b70a33b643bb0384"}, - {file = "coverage-7.4.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cc4f1358cb0c78edef3ed237ef2c86056206bb8d9140e73b6b89fbcfcbdd40e1"}, - {file = "coverage-7.4.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8130a2aa2acb8788e0b56938786c33c7c98562697bf9f4c7d6e8e5e3a0501e4a"}, - {file = "coverage-7.4.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cf271892d13e43bc2b51e6908ec9a6a5094a4df1d8af0bfc360088ee6c684409"}, - {file = "coverage-7.4.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a4cdc86d54b5da0df6d3d3a2f0b710949286094c3a6700c21e9015932b81447e"}, - {file = "coverage-7.4.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:ae71e7ddb7a413dd60052e90528f2f65270aad4b509563af6d03d53e979feafd"}, - {file = "coverage-7.4.4-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:38dd60d7bf242c4ed5b38e094baf6401faa114fc09e9e6632374388a404f98e7"}, - {file = "coverage-7.4.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:aa5b1c1bfc28384f1f53b69a023d789f72b2e0ab1b3787aae16992a7ca21056c"}, - {file = "coverage-7.4.4-cp38-cp38-win32.whl", hash = "sha256:dfa8fe35a0bb90382837b238fff375de15f0dcdb9ae68ff85f7a63649c98527e"}, - {file = "coverage-7.4.4-cp38-cp38-win_amd64.whl", hash = "sha256:b2991665420a803495e0b90a79233c1433d6ed77ef282e8e152a324bbbc5e0c8"}, - {file = "coverage-7.4.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3b799445b9f7ee8bf299cfaed6f5b226c0037b74886a4e11515e569b36fe310d"}, - {file = "coverage-7.4.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:b4d33f418f46362995f1e9d4f3a35a1b6322cb959c31d88ae56b0298e1c22357"}, - {file = "coverage-7.4.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aadacf9a2f407a4688d700e4ebab33a7e2e408f2ca04dbf4aef17585389eff3e"}, - {file = "coverage-7.4.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7c95949560050d04d46b919301826525597f07b33beba6187d04fa64d47ac82e"}, - {file = "coverage-7.4.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ff7687ca3d7028d8a5f0ebae95a6e4827c5616b31a4ee1192bdfde697db110d4"}, - {file = "coverage-7.4.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:5fc1de20b2d4a061b3df27ab9b7c7111e9a710f10dc2b84d33a4ab25065994ec"}, - {file = "coverage-7.4.4-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:c74880fc64d4958159fbd537a091d2a585448a8f8508bf248d72112723974cbd"}, - {file = "coverage-7.4.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:742a76a12aa45b44d236815d282b03cfb1de3b4323f3e4ec933acfae08e54ade"}, - {file = "coverage-7.4.4-cp39-cp39-win32.whl", hash = "sha256:d89d7b2974cae412400e88f35d86af72208e1ede1a541954af5d944a8ba46c57"}, - {file = "coverage-7.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:9ca28a302acb19b6af89e90f33ee3e1906961f94b54ea37de6737b7ca9d8827c"}, - {file = "coverage-7.4.4-pp38.pp39.pp310-none-any.whl", hash = "sha256:b2c5edc4ac10a7ef6605a966c58929ec6c1bd0917fb8c15cb3363f65aa40e677"}, - {file = "coverage-7.4.4.tar.gz", hash = "sha256:c901df83d097649e257e803be22592aedfd5182f07b3cc87d640bbb9afd50f49"}, + {file = "coverage-7.5.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:432949a32c3e3f820af808db1833d6d1631664d53dd3ce487aa25d574e18ad1c"}, + {file = "coverage-7.5.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2bd7065249703cbeb6d4ce679c734bef0ee69baa7bff9724361ada04a15b7e3b"}, + {file = "coverage-7.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bbfe6389c5522b99768a93d89aca52ef92310a96b99782973b9d11e80511f932"}, + {file = "coverage-7.5.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:39793731182c4be939b4be0cdecde074b833f6171313cf53481f869937129ed3"}, + {file = "coverage-7.5.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:85a5dbe1ba1bf38d6c63b6d2c42132d45cbee6d9f0c51b52c59aa4afba057517"}, + {file = "coverage-7.5.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:357754dcdfd811462a725e7501a9b4556388e8ecf66e79df6f4b988fa3d0b39a"}, + {file = "coverage-7.5.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:a81eb64feded34f40c8986869a2f764f0fe2db58c0530d3a4afbcde50f314880"}, + {file = "coverage-7.5.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:51431d0abbed3a868e967f8257c5faf283d41ec882f58413cf295a389bb22e58"}, + {file = "coverage-7.5.0-cp310-cp310-win32.whl", hash = "sha256:f609ebcb0242d84b7adeee2b06c11a2ddaec5464d21888b2c8255f5fd6a98ae4"}, + {file = "coverage-7.5.0-cp310-cp310-win_amd64.whl", hash = "sha256:6782cd6216fab5a83216cc39f13ebe30adfac2fa72688c5a4d8d180cd52e8f6a"}, + {file = "coverage-7.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:e768d870801f68c74c2b669fc909839660180c366501d4cc4b87efd6b0eee375"}, + {file = "coverage-7.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:84921b10aeb2dd453247fd10de22907984eaf80901b578a5cf0bb1e279a587cb"}, + {file = "coverage-7.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:710c62b6e35a9a766b99b15cdc56d5aeda0914edae8bb467e9c355f75d14ee95"}, + {file = "coverage-7.5.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c379cdd3efc0658e652a14112d51a7668f6bfca7445c5a10dee7eabecabba19d"}, + {file = "coverage-7.5.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fea9d3ca80bcf17edb2c08a4704259dadac196fe5e9274067e7a20511fad1743"}, + {file = "coverage-7.5.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:41327143c5b1d715f5f98a397608f90ab9ebba606ae4e6f3389c2145410c52b1"}, + {file = "coverage-7.5.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:565b2e82d0968c977e0b0f7cbf25fd06d78d4856289abc79694c8edcce6eb2de"}, + {file = "coverage-7.5.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:cf3539007202ebfe03923128fedfdd245db5860a36810136ad95a564a2fdffff"}, + {file = "coverage-7.5.0-cp311-cp311-win32.whl", hash = "sha256:bf0b4b8d9caa8d64df838e0f8dcf68fb570c5733b726d1494b87f3da85db3a2d"}, + {file = "coverage-7.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:9c6384cc90e37cfb60435bbbe0488444e54b98700f727f16f64d8bfda0b84656"}, + {file = "coverage-7.5.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:fed7a72d54bd52f4aeb6c6e951f363903bd7d70bc1cad64dd1f087980d309ab9"}, + {file = "coverage-7.5.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:cbe6581fcff7c8e262eb574244f81f5faaea539e712a058e6707a9d272fe5b64"}, + {file = "coverage-7.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ad97ec0da94b378e593ef532b980c15e377df9b9608c7c6da3506953182398af"}, + {file = "coverage-7.5.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bd4bacd62aa2f1a1627352fe68885d6ee694bdaebb16038b6e680f2924a9b2cc"}, + {file = "coverage-7.5.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:adf032b6c105881f9d77fa17d9eebe0ad1f9bfb2ad25777811f97c5362aa07f2"}, + {file = "coverage-7.5.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:4ba01d9ba112b55bfa4b24808ec431197bb34f09f66f7cb4fd0258ff9d3711b1"}, + {file = "coverage-7.5.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:f0bfe42523893c188e9616d853c47685e1c575fe25f737adf473d0405dcfa7eb"}, + {file = "coverage-7.5.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a9a7ef30a1b02547c1b23fa9a5564f03c9982fc71eb2ecb7f98c96d7a0db5cf2"}, + {file = "coverage-7.5.0-cp312-cp312-win32.whl", hash = "sha256:3c2b77f295edb9fcdb6a250f83e6481c679335ca7e6e4a955e4290350f2d22a4"}, + {file = "coverage-7.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:427e1e627b0963ac02d7c8730ca6d935df10280d230508c0ba059505e9233475"}, + {file = "coverage-7.5.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9dd88fce54abbdbf4c42fb1fea0e498973d07816f24c0e27a1ecaf91883ce69e"}, + {file = "coverage-7.5.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:a898c11dca8f8c97b467138004a30133974aacd572818c383596f8d5b2eb04a9"}, + {file = "coverage-7.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:07dfdd492d645eea1bd70fb1d6febdcf47db178b0d99161d8e4eed18e7f62fe7"}, + {file = "coverage-7.5.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d3d117890b6eee85887b1eed41eefe2e598ad6e40523d9f94c4c4b213258e4a4"}, + {file = "coverage-7.5.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6afd2e84e7da40fe23ca588379f815fb6dbbb1b757c883935ed11647205111cb"}, + {file = "coverage-7.5.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:a9960dd1891b2ddf13a7fe45339cd59ecee3abb6b8326d8b932d0c5da208104f"}, + {file = "coverage-7.5.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:ced268e82af993d7801a9db2dbc1d2322e786c5dc76295d8e89473d46c6b84d4"}, + {file = "coverage-7.5.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:e7c211f25777746d468d76f11719e64acb40eed410d81c26cefac641975beb88"}, + {file = "coverage-7.5.0-cp38-cp38-win32.whl", hash = "sha256:262fffc1f6c1a26125d5d573e1ec379285a3723363f3bd9c83923c9593a2ac25"}, + {file = "coverage-7.5.0-cp38-cp38-win_amd64.whl", hash = "sha256:eed462b4541c540d63ab57b3fc69e7d8c84d5957668854ee4e408b50e92ce26a"}, + {file = "coverage-7.5.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d0194d654e360b3e6cc9b774e83235bae6b9b2cac3be09040880bb0e8a88f4a1"}, + {file = "coverage-7.5.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:33c020d3322662e74bc507fb11488773a96894aa82a622c35a5a28673c0c26f5"}, + {file = "coverage-7.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0cbdf2cae14a06827bec50bd58e49249452d211d9caddd8bd80e35b53cb04631"}, + {file = "coverage-7.5.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3235d7c781232e525b0761730e052388a01548bd7f67d0067a253887c6e8df46"}, + {file = "coverage-7.5.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2de4e546f0ec4b2787d625e0b16b78e99c3e21bc1722b4977c0dddf11ca84e"}, + {file = "coverage-7.5.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:4d0e206259b73af35c4ec1319fd04003776e11e859936658cb6ceffdeba0f5be"}, + {file = "coverage-7.5.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:2055c4fb9a6ff624253d432aa471a37202cd8f458c033d6d989be4499aed037b"}, + {file = "coverage-7.5.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:075299460948cd12722a970c7eae43d25d37989da682997687b34ae6b87c0ef0"}, + {file = "coverage-7.5.0-cp39-cp39-win32.whl", hash = "sha256:280132aada3bc2f0fac939a5771db4fbb84f245cb35b94fae4994d4c1f80dae7"}, + {file = "coverage-7.5.0-cp39-cp39-win_amd64.whl", hash = "sha256:c58536f6892559e030e6924896a44098bc1290663ea12532c78cef71d0df8493"}, + {file = "coverage-7.5.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:2b57780b51084d5223eee7b59f0d4911c31c16ee5aa12737c7a02455829ff067"}, + {file = "coverage-7.5.0.tar.gz", hash = "sha256:cf62d17310f34084c59c01e027259076479128d11e4661bb6c9acb38c5e19bb8"}, ] [package.dependencies] @@ -267,18 +267,19 @@ files = [ [[package]] name = "platformdirs" -version = "4.2.0" -description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +version = "4.2.1" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." optional = false python-versions = ">=3.8" files = [ - {file = "platformdirs-4.2.0-py3-none-any.whl", hash = "sha256:0614df2a2f37e1a662acbd8e2b25b92ccf8632929bc6d43467e17fe89c75e068"}, - {file = "platformdirs-4.2.0.tar.gz", hash = "sha256:ef0cc731df711022c174543cb70a9b5bd22e5a9337c8624ef2c2ceb8ddad8768"}, + {file = "platformdirs-4.2.1-py3-none-any.whl", hash = "sha256:17d5a1161b3fd67b390023cb2d3b026bbd40abde6fdb052dfbd3a29c3ba22ee1"}, + {file = "platformdirs-4.2.1.tar.gz", hash = "sha256:031cd18d4ec63ec53e82dceaac0417d218a6863f7745dfcc9efe7793b7039bdf"}, ] [package.extras] docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +type = ["mypy (>=1.8)"] [[package]] name = "pluggy" @@ -588,13 +589,13 @@ files = [ [[package]] name = "virtualenv" -version = "20.25.3" +version = "20.26.0" description = "Virtual Python Environment builder" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.25.3-py3-none-any.whl", hash = "sha256:8aac4332f2ea6ef519c648d0bc48a5b1d324994753519919bddbb1aff25a104e"}, - {file = "virtualenv-20.25.3.tar.gz", hash = "sha256:7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"}, + {file = "virtualenv-20.26.0-py3-none-any.whl", hash = "sha256:0846377ea76e818daaa3e00a4365c018bc3ac9760cbb3544de542885aad61fb3"}, + {file = "virtualenv-20.26.0.tar.gz", hash = "sha256:ec25a9671a5102c8d2657f62792a27b48f016664c6873f6beed3800008577210"}, ] [package.dependencies] diff --git a/scripts/generate_schema.py b/scripts/generate_schema.py index de65fc47c1..826abe5daf 100644 --- a/scripts/generate_schema.py +++ b/scripts/generate_schema.py @@ -15,7 +15,7 @@ from pydantic import TypeAdapter from hugr.serialization import SerialHugr -from hugr.serialization.hugrtype import HugrType +from hugr.serialization.testing_hugr import TestingHugr def write_schema(out_dir: Path, name_prefix: str, schema): @@ -37,4 +37,4 @@ def write_schema(out_dir: Path, name_prefix: str, schema): sys.exit(1) write_schema(out_dir, "hugr_schema", SerialHugr) - write_schema(out_dir, "test_hugrtype_schema", HugrType) + write_schema(out_dir, "testing_hugr_schema", TestingHugr) diff --git a/specification/schema/hugr_schema_v1.json b/specification/schema/hugr_schema_v1.json index 3b9e4c6d6e..2a6b1b5648 100644 --- a/specification/schema/hugr_schema_v1.json +++ b/specification/schema/hugr_schema_v1.json @@ -1241,27 +1241,6 @@ "type": "object" }, "SumType": { - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumTypeBase" - } - }, - "required": [ - "st" - ], - "title": "SumType", - "type": "object" - }, - "SumTypeBase": { "discriminator": { "mapping": { "General": "#/$defs/GeneralSum", @@ -1277,7 +1256,7 @@ "$ref": "#/$defs/GeneralSum" } ], - "title": "SumTypeBase" + "title": "SumType" }, "SumValue": { "description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.", @@ -1296,7 +1275,7 @@ "type": "integer" }, "typ": { - "$ref": "#/$defs/SumTypeBase" + "$ref": "#/$defs/SumType" }, "vs": { "items": { @@ -1357,6 +1336,27 @@ "title": "Tag", "type": "object" }, + "TaggedSumType": { + "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, + "st": { + "$ref": "#/$defs/SumType" + } + }, + "required": [ + "st" + ], + "title": "TaggedSumType", + "type": "object" + }, "TailLoop": { "description": "Tail-controlled loop.", "properties": { @@ -1466,7 +1466,7 @@ "I": "#/$defs/USize", "Opaque": "#/$defs/Opaque", "Q": "#/$defs/Qubit", - "Sum": "#/$defs/SumType", + "Sum": "#/$defs/TaggedSumType", "V": "#/$defs/Variable" }, "propertyName": "t" @@ -1488,7 +1488,7 @@ "$ref": "#/$defs/Array" }, { - "$ref": "#/$defs/SumType" + "$ref": "#/$defs/TaggedSumType" }, { "$ref": "#/$defs/Opaque" diff --git a/specification/schema/testing_hugr_schema_v1.json b/specification/schema/testing_hugr_schema_v1.json new file mode 100644 index 0000000000..3e6047af2f --- /dev/null +++ b/specification/schema/testing_hugr_schema_v1.json @@ -0,0 +1,679 @@ +{ + "$defs": { + "Alias": { + "description": "TODO", + "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" + }, + "Array": { + "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": { + "properties": { + "tya": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tya", + "type": "string" + }, + "n": { + "title": "N", + "type": "integer" + } + }, + "required": [ + "n" + ], + "title": "BoundedNatArg", + "type": "object" + }, + "CustomTypeArg": { + "properties": { + "typ": { + "title": "Typ", + "type": "null" + }, + "value": { + "title": "Value", + "type": "string" + } + }, + "required": [ + "typ", + "value" + ], + "title": "CustomTypeArg", + "type": "object" + }, + "ExtensionSet": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "description": "A set of extensions ids.", + "title": "ExtensionSet" + }, + "ExtensionValue": { + "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": [ + "c", + "e" + ], + "title": "ExtensionValue", + "type": "object" + }, + "ExtensionsArg": { + "properties": { + "tya": { + "const": "Extensions", + "default": "Extensions", + "enum": [ + "Extensions" + ], + "title": "Tya", + "type": "string" + }, + "es": { + "$ref": "#/$defs/ExtensionSet" + } + }, + "required": [ + "es" + ], + "title": "ExtensionsArg", + "type": "object" + }, + "FunctionType": { + "description": "A graph encoded as a value. It contains a concrete signature and a set of required 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": { + "description": "A higher-order function value.", + "properties": { + "c": { + "const": "Function", + "default": "Function", + "enum": [ + "Function" + ], + "title": "ValueTag", + "type": "string" + }, + "hugr": { + "title": "Hugr" + } + }, + "required": [ + "c", + "hugr" + ], + "title": "FunctionValue", + "type": "object" + }, + "GeneralSum": { + "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" + }, + "Opaque": { + "description": "An opaque operation 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": { + "properties": { + "tya": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tya", + "type": "string" + }, + "arg": { + "$ref": "#/$defs/CustomTypeArg" + } + }, + "required": [ + "arg" + ], + "title": "OpaqueArg", + "type": "object" + }, + "Qubit": { + "description": "A qubit.", + "properties": { + "t": { + "const": "Q", + "default": "Q", + "enum": [ + "Q" + ], + "title": "T", + "type": "string" + } + }, + "title": "Qubit", + "type": "object" + }, + "SequenceArg": { + "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": { + "description": "A Sum variant For 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": [ + "c", + "tag", + "typ", + "vs" + ], + "title": "SumValue", + "type": "object" + }, + "TaggedSumType": { + "properties": { + "t": { + "const": "Sum", + "default": "Sum", + "enum": [ + "Sum" + ], + "title": "T", + "type": "string" + }, + "st": { + "$ref": "#/$defs/SumType" + } + }, + "required": [ + "st" + ], + "title": "TaggedSumType", + "type": "object" + }, + "TupleValue": { + "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": [ + "c", + "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" + }, + "TypeTypeArg": { + "properties": { + "tya": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tya", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Type" + } + }, + "required": [ + "ty" + ], + "title": "TypeTypeArg", + "type": "object" + }, + "USize": { + "description": "Unsigned integer size type.", + "properties": { + "t": { + "const": "I", + "default": "I", + "enum": [ + "I" + ], + "title": "T", + "type": "string" + } + }, + "title": "USize", + "type": "object" + }, + "UnitSum": { + "description": "Simple predicate 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" + }, + "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": { + "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 Type, SumType, or Value. Intended for testing only.", + "properties": { + "typ": { + "anyOf": [ + { + "$ref": "#/$defs/Type" + }, + { + "$ref": "#/$defs/SumType" + }, + { + "$ref": "#/$defs/Value" + } + ], + "title": "Typ" + }, + "version": { + "const": "v1", + "default": "v1", + "enum": [ + "v1" + ], + "title": "Version", + "type": "string" + } + }, + "required": [ + "typ" + ], + "title": "HugrTesting", + "type": "object" +} \ No newline at end of file