Skip to content

Commit

Permalink
Migrate from deprecated json schema methods (#1098)
Browse files Browse the repository at this point in the history
* Migrate from deprecated json schema methods

* Fix mypy issues
  • Loading branch information
yao-cqc authored Oct 26, 2023
1 parent 9b50e14 commit 631a688
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
21 changes: 11 additions & 10 deletions pytket/tests/architecture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
27 changes: 13 additions & 14 deletions pytket/tests/passes_serialisation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion schemas/compiler_pass_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 631a688

Please sign in to comment.