From 631a688f3f593cabc935ecb987ba7dd003cb204e Mon Sep 17 00:00:00 2001 From: yao-cqc <75305462+yao-cqc@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:02:47 +0100 Subject: [PATCH] Migrate from deprecated json schema methods (#1098) * Migrate from deprecated json schema methods * Fix mypy issues --- pytket/tests/architecture_test.py | 21 +++++++++--------- pytket/tests/passes_serialisation_test.py | 27 +++++++++++------------ schemas/compiler_pass_v1.json | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pytket/tests/architecture_test.py b/pytket/tests/architecture_test.py index 66e413e7a8..a5c0c3972b 100644 --- a/pytket/tests/architecture_test.py +++ b/pytket/tests/architecture_test.py @@ -13,7 +13,9 @@ # limitations under the License. import json -from jsonschema import RefResolver, Draft7Validator # type: ignore +from referencing import Registry +from referencing.jsonschema import DRAFT7 +from jsonschema import Draft7Validator # type: ignore from pathlib import Path from pytket.circuit import Node from pytket.architecture import Architecture, SquareGrid, FullyConnected, RingArch @@ -27,15 +29,14 @@ with open(schema_dir / "fullyconnected_v1.json", "r") as f: fc_schema = json.load(f) -schema_store = { - circ_schema["$id"]: circ_schema, - arch_schema["$id"]: arch_schema, - fc_schema["$id"]: fc_schema, -} -arch_validator_resolver = RefResolver.from_schema(arch_schema, store=schema_store) -arch_validator = Draft7Validator(arch_schema, resolver=arch_validator_resolver) -fc_validator_resolver = RefResolver.from_schema(fc_schema, store=schema_store) -fc_validator = Draft7Validator(fc_schema, resolver=fc_validator_resolver) +schema_store = [ + (circ_schema["$id"], DRAFT7.create_resource(circ_schema)), + (arch_schema["$id"], DRAFT7.create_resource(arch_schema)), + (fc_schema["$id"], DRAFT7.create_resource(fc_schema)), +] +registry: Registry = Registry().with_resources(schema_store) +arch_validator = Draft7Validator(arch_schema, registry=registry) +fc_validator = Draft7Validator(fc_schema, registry=registry) def check_arch_serialisation(arch: Architecture) -> None: diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 51011adda3..9c29262d1c 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -14,7 +14,9 @@ import json import pytest -from jsonschema import RefResolver, Draft7Validator, ValidationError # type: ignore +from referencing import Registry +from referencing.jsonschema import DRAFT7 +from jsonschema import Draft7Validator, ValidationError # type: ignore from pathlib import Path from typing import Any, Dict, List @@ -408,19 +410,16 @@ def nonparam_predicate_dict(name: str) -> Dict[str, Any]: with open(schema_dir / "predicate_v1.json", "r") as f: pred_schema = json.load(f) -schema_store = { - pass_schema["$id"]: pass_schema, - circ_schema["$id"]: circ_schema, - arch_schema["$id"]: arch_schema, - plact_schema["$id"]: plact_schema, - pred_schema["$id"]: pred_schema, -} -pass_validator_resolver = RefResolver.from_schema(pass_schema, store=schema_store) -pass_validator = Draft7Validator(pass_schema, resolver=pass_validator_resolver) -predicate_validator_resolver = RefResolver.from_schema(pred_schema, store=schema_store) -predicate_validator = Draft7Validator( - pred_schema, resolver=predicate_validator_resolver -) +schema_store = [ + (pass_schema["$id"], DRAFT7.create_resource(pass_schema)), + (circ_schema["$id"], DRAFT7.create_resource(circ_schema)), + (arch_schema["$id"], DRAFT7.create_resource(arch_schema)), + (plact_schema["$id"], DRAFT7.create_resource(plact_schema)), + (pred_schema["$id"], DRAFT7.create_resource(pred_schema)), +] +registry: Registry = Registry().with_resources(schema_store) +pass_validator = Draft7Validator(pass_schema, registry=registry) +predicate_validator = Draft7Validator(pred_schema, registry=registry) def check_pass_serialisation( diff --git a/schemas/compiler_pass_v1.json b/schemas/compiler_pass_v1.json index ae73b48e98..b7511d54d2 100644 --- a/schemas/compiler_pass_v1.json +++ b/schemas/compiler_pass_v1.json @@ -296,7 +296,7 @@ "description": "Minimal number of CX gates in each phase in \"ComposePhasePolyBoxes\"." }, "routing_config": { - "$ref": "#definitions/routing_config" + "$ref": "#/definitions/routing_config" }, "fidelities": { "type": "object",