From e494551ce1afff77158e1bdefc63bcd04cb670b3 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:47:54 +0000 Subject: [PATCH 01/16] Add new methods for getting predicates from python passes --- pytket/binders/passes.cpp | 26 ++++++++++++++++++++++++++ pytket/binders/predicates.cpp | 2 +- pytket/docs/changelog.rst | 7 +++++++ pytket/pytket/_tket/passes.pyi | 10 ++++++++++ pytket/tests/predicates_test.py | 13 +++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index ef398f8a0d..6ffd90bc51 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -268,6 +268,32 @@ PYBIND11_MODULE(passes, m) { return py::cast(serialise(base_pass)); }, ":return: A JSON serializable dictionary representation of the Pass.") + .def( + "get_pre_conditions", + [](const BasePass &base_pass) { + std::vector pre_conditions; + for (const std::pair< + const std::type_index, std::shared_ptr> + &p : base_pass.get_conditions().first) { + pre_conditions.push_back(p.second); + } + return pre_conditions; + }, + "Returns the pre condition Predicates for the given pass." + "\n:return: A list of Predicate") + .def( + "get_post_conditions", + [](const BasePass &base_pass) { + std::vector post_conditions; + for (const std::pair< + const std::type_index, std::shared_ptr> & + p : base_pass.get_conditions().second.specific_postcons_) { + post_conditions.push_back(p.second); + } + return post_conditions; + }, + "Returns the post condition Predicates for the given pass." + "\n:return: A list of Predicate") .def_static( "from_dict", [](const py::dict &base_pass_dict, diff --git a/pytket/binders/predicates.cpp b/pytket/binders/predicates.cpp index 127ef81c20..80bab6e426 100644 --- a/pytket/binders/predicates.cpp +++ b/pytket/binders/predicates.cpp @@ -83,7 +83,7 @@ PYBIND11_MODULE(predicates, m) { "implies", &Predicate::implies, ":return: True if predicate implies another one, else False", py::arg("other")) - .def("__str__", [](const Predicate &) { return ""; }) + .def("__str__", &Predicate::to_string) .def("__repr__", &Predicate::to_string) .def( "to_dict", diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index bd7a814086..6bc3c5b594 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +Unreleased +---------- + +Features: + +* Add `BasePass.get_pre_conditions()` and `BasePass.get_post_conditions()`. + 1.35.0 (November 2024) ---------------------- diff --git a/pytket/pytket/_tket/passes.pyi b/pytket/pytket/_tket/passes.pyi index 9a59fae388..8a9fb789bc 100644 --- a/pytket/pytket/_tket/passes.pyi +++ b/pytket/pytket/_tket/passes.pyi @@ -54,6 +54,16 @@ class BasePass: :param after_apply: Invoked after a pass is applied. The CompilationUnit and a summary of the pass configuration are passed into the callback. :return: True if pass modified the circuit, else False """ + def get_post_conditions(self) -> list[pytket._tket.predicates.Predicate]: + """ + Returns the post condition Predicates for the given pass. + :return: A list of Predicate + """ + def get_pre_conditions(self) -> list[pytket._tket.predicates.Predicate]: + """ + Returns the pre condition Predicates for the given pass. + :return: A list of Predicate + """ def to_dict(self) -> typing.Any: """ :return: A JSON serializable dictionary representation of the Pass. diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 1bda5404cc..837104c1fd 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1107,6 +1107,19 @@ def test_auto_rebase_deprecation(recwarn: Any) -> None: assert "deprecated" in str(w.message) +def test_get_pre_conditions() -> None: + pre_cons = GreedyPauliSimp().get_pre_conditions() + gate_set = pre_cons[0].gate_set + assert OpType.CX in gate_set + assert OpType.Measure in gate_set + + +def test_get_post_conditions() -> None: + gate_set = {OpType.CX, OpType.Rz, OpType.H, OpType.Reset, OpType.Measure} + post_cons = AutoRebase(gate_set).get_post_conditions() + assert post_cons[0].gate_set == gate_set + + if __name__ == "__main__": test_predicate_generation() test_compilation_unit_generation() From da64baad597dc6c10da78a155ee9e81e1b8d21a7 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:48:43 +0000 Subject: [PATCH 02/16] bump --- pytket/conanfile.py | 2 +- tket/conanfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 123ac8339a..86c6f590b0 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -38,7 +38,7 @@ def requirements(self): self.requires("pybind11_json/0.2.14") self.requires("symengine/0.13.0") self.requires("tkassert/0.3.4@tket/stable") - self.requires("tket/1.3.48@tket/stable") + self.requires("tket/1.3.49@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tktokenswap/0.3.9@tket/stable") diff --git a/tket/conanfile.py b/tket/conanfile.py index fa46ab76f8..01a68205a5 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.48" + version = "1.3.49" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" From 135fa3965e634d451a3d7438b5220808cbe70875 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:00:03 +0000 Subject: [PATCH 03/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 837104c1fd..13ca898b7c 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1109,7 +1109,7 @@ def test_auto_rebase_deprecation(recwarn: Any) -> None: def test_get_pre_conditions() -> None: pre_cons = GreedyPauliSimp().get_pre_conditions() - gate_set = pre_cons[0].gate_set + gate_set = pre_cons[0].gate_set # type: ignore assert OpType.CX in gate_set assert OpType.Measure in gate_set @@ -1117,7 +1117,7 @@ def test_get_pre_conditions() -> None: def test_get_post_conditions() -> None: gate_set = {OpType.CX, OpType.Rz, OpType.H, OpType.Reset, OpType.Measure} post_cons = AutoRebase(gate_set).get_post_conditions() - assert post_cons[0].gate_set == gate_set + assert post_cons[0].gate_set == gate_set # type: ignore if __name__ == "__main__": From 801bb2ae3e2b46cadd74a472d2fc89c741c0e137 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:12:42 +0000 Subject: [PATCH 04/16] Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> --- pytket/binders/passes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index 6ffd90bc51..36e0c76337 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -293,7 +293,7 @@ PYBIND11_MODULE(passes, m) { return post_conditions; }, "Returns the post condition Predicates for the given pass." - "\n:return: A list of Predicate") + "\n\n:return: A list of :py:class:`Predicate`") .def_static( "from_dict", [](const py::dict &base_pass_dict, From 297cd4e5449406328e5d9193bcc15a5a76f3db19 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:12:47 +0000 Subject: [PATCH 05/16] Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> --- pytket/binders/passes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index 36e0c76337..5374c8d923 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -269,7 +269,7 @@ PYBIND11_MODULE(passes, m) { }, ":return: A JSON serializable dictionary representation of the Pass.") .def( - "get_pre_conditions", + "get_preconditions", [](const BasePass &base_pass) { std::vector pre_conditions; for (const std::pair< From 34ed2c2b554a541f6f02578c2f72680505ee8461 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:07:55 +0000 Subject: [PATCH 06/16] add get gate_set, check tests --- pytket/binders/passes.cpp | 37 +++++++++++++++++++++++++++++---- pytket/tests/predicates_test.py | 11 ++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index 5374c8d923..5d9b330fcc 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -145,6 +145,31 @@ const PassPtr &DecomposeClassicalExp() { return pp; } +std::optional get_gate_set(const BasePass &base_pass) { + OpTypeSet allowed_ops; + for (const std::pair> + &p : base_pass.get_conditions().first) { + if (p.second->to_string().substr(0, 17) == "GateSetPredicate:") { + std::shared_ptr gsp_ptr = + std::dynamic_pointer_cast(p.second); + if (allowed_ops.empty()) { + allowed_ops = gsp_ptr->get_allowed_types(); + continue; + } + OpTypeSet intersection; + OpTypeSet candidate_allowed_ops = gsp_ptr->get_allowed_types(); + std::set_intersection( + candidate_allowed_ops.begin(), candidate_allowed_ops.end(), + allowed_ops.begin(), allowed_ops.end(), + std::inserter(intersection, intersection.begin())); + allowed_ops = intersection; + } + } + if (allowed_ops.empty()) return {}; + + return allowed_ops; +} + PYBIND11_MODULE(passes, m) { py::module_::import("pytket._tket.predicates"); m.def( @@ -212,7 +237,6 @@ PYBIND11_MODULE(passes, m) { ); } }; - py::class_( m, "BasePass", "Base class for passes.") .def( @@ -279,10 +303,10 @@ PYBIND11_MODULE(passes, m) { } return pre_conditions; }, - "Returns the pre condition Predicates for the given pass." + "Returns the precondition Predicates for the given pass." "\n:return: A list of Predicate") .def( - "get_post_conditions", + "get_postconditions", [](const BasePass &base_pass) { std::vector post_conditions; for (const std::pair< @@ -292,8 +316,13 @@ PYBIND11_MODULE(passes, m) { } return post_conditions; }, - "Returns the post condition Predicates for the given pass." + "Returns the postcondition Predicates for the given pass." "\n\n:return: A list of :py:class:`Predicate`") + .def( + "get_gate_set", &get_gate_set, + "Returns the intersection of all set of OpType for all " + "GateSetPredicate in the `BasePass` preconditions.", + "\n\n:return: A set of allowed OpType") .def_static( "from_dict", [](const py::dict &base_pass_dict, diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 13ca898b7c..ef72d9e290 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1108,7 +1108,7 @@ def test_auto_rebase_deprecation(recwarn: Any) -> None: def test_get_pre_conditions() -> None: - pre_cons = GreedyPauliSimp().get_pre_conditions() + pre_cons = GreedyPauliSimp().get_preconditions() gate_set = pre_cons[0].gate_set # type: ignore assert OpType.CX in gate_set assert OpType.Measure in gate_set @@ -1116,10 +1116,17 @@ def test_get_pre_conditions() -> None: def test_get_post_conditions() -> None: gate_set = {OpType.CX, OpType.Rz, OpType.H, OpType.Reset, OpType.Measure} - post_cons = AutoRebase(gate_set).get_post_conditions() + post_cons = AutoRebase(gate_set).get_postconditions() assert post_cons[0].gate_set == gate_set # type: ignore +def test_get_gate_set() -> None: + gate_set = GreedyPauliSimp().get_gate_set() + assert OpType.CX in gate_set + assert OpType.Measure in gate_set + assert CliffordPushThroughMeasures().get_gate_set() == None + + if __name__ == "__main__": test_predicate_generation() test_compilation_unit_generation() From 04d318b2cebf2a4e0600765d37be8ce268fd1824 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:11:04 +0000 Subject: [PATCH 07/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index ef72d9e290..b2943312ba 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1124,7 +1124,7 @@ def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() assert OpType.CX in gate_set assert OpType.Measure in gate_set - assert CliffordPushThroughMeasures().get_gate_set() == None + assert CliffordPushThroughMeasures().get_gate_set() is None if __name__ == "__main__": From ea9700d1d881e3d29cbca57e6939d2ee1e54a12e Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:11:27 +0000 Subject: [PATCH 08/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index b2943312ba..03e2488a4e 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1124,7 +1124,7 @@ def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() assert OpType.CX in gate_set assert OpType.Measure in gate_set - assert CliffordPushThroughMeasures().get_gate_set() is None + assert CliffordPushThroughMeasures().get_gate_set() is None # type: ignore if __name__ == "__main__": From 3ca27161585aa9eba0494ac5dd6c961aafcc39c1 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:05:49 +0000 Subject: [PATCH 09/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 03e2488a4e..f71c174bef 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1109,7 +1109,7 @@ def test_auto_rebase_deprecation(recwarn: Any) -> None: def test_get_pre_conditions() -> None: pre_cons = GreedyPauliSimp().get_preconditions() - gate_set = pre_cons[0].gate_set # type: ignore + gate_set = pre_cons[0].gate_set assert OpType.CX in gate_set assert OpType.Measure in gate_set @@ -1117,7 +1117,7 @@ def test_get_pre_conditions() -> None: def test_get_post_conditions() -> None: gate_set = {OpType.CX, OpType.Rz, OpType.H, OpType.Reset, OpType.Measure} post_cons = AutoRebase(gate_set).get_postconditions() - assert post_cons[0].gate_set == gate_set # type: ignore + assert post_cons[0].gate_set == gate_set def test_get_gate_set() -> None: From e94838a687c1058256d6e44e59f5726b169444f9 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:10:49 +0000 Subject: [PATCH 10/16] bump, fix ruff issue --- pytket/conanfile.py | 2 +- pytket/tests/zx_diagram_test.py | 2 +- tket/conanfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 86c6f590b0..9bdd4157ce 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -38,7 +38,7 @@ def requirements(self): self.requires("pybind11_json/0.2.14") self.requires("symengine/0.13.0") self.requires("tkassert/0.3.4@tket/stable") - self.requires("tket/1.3.49@tket/stable") + self.requires("tket/1.3.50@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tktokenswap/0.3.9@tket/stable") diff --git a/pytket/tests/zx_diagram_test.py b/pytket/tests/zx_diagram_test.py index ac8e7aebea..17be46a8d5 100644 --- a/pytket/tests/zx_diagram_test.py +++ b/pytket/tests/zx_diagram_test.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from math import isclose, pow +from math import isclose from typing import Tuple import numpy as np diff --git a/tket/conanfile.py b/tket/conanfile.py index 01a68205a5..da3643e863 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.49" + version = "1.3.50" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" From a94fa690d6f55140f91d6b8bb330d92e2a3099f9 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:26:15 +0000 Subject: [PATCH 11/16] regen stubs --- pytket/docs/changelog.rst | 2 +- pytket/pytket/_tket/passes.pyi | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 6bc3c5b594..5d48a46423 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -6,7 +6,7 @@ Unreleased Features: -* Add `BasePass.get_pre_conditions()` and `BasePass.get_post_conditions()`. +* Add `BasePass.get_preconditions()` and `BasePass.getpost_conditions()`. 1.35.0 (November 2024) ---------------------- diff --git a/pytket/pytket/_tket/passes.pyi b/pytket/pytket/_tket/passes.pyi index 8a9fb789bc..c8a35e24e5 100644 --- a/pytket/pytket/_tket/passes.pyi +++ b/pytket/pytket/_tket/passes.pyi @@ -54,14 +54,19 @@ class BasePass: :param after_apply: Invoked after a pass is applied. The CompilationUnit and a summary of the pass configuration are passed into the callback. :return: True if pass modified the circuit, else False """ - def get_post_conditions(self) -> list[pytket._tket.predicates.Predicate]: + def get_gate_set(self) -> set[pytket._tket.circuit.OpType] | None: """ - Returns the post condition Predicates for the given pass. - :return: A list of Predicate + :return: A set of allowed OpType + """ + def get_postconditions(self) -> list[pytket._tket.predicates.Predicate]: + """ + Returns the postcondition Predicates for the given pass. + + :return: A list of :py:class:`Predicate` """ - def get_pre_conditions(self) -> list[pytket._tket.predicates.Predicate]: + def get_preconditions(self) -> list[pytket._tket.predicates.Predicate]: """ - Returns the pre condition Predicates for the given pass. + Returns the precondition Predicates for the given pass. :return: A list of Predicate """ def to_dict(self) -> typing.Any: From 376d87cc1a790f26695bbc6b88a91af47c16a393 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:33:25 +0000 Subject: [PATCH 12/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 00723ce908..f70f3fd38a 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1107,7 +1107,7 @@ def test_auto_rebase_deprecation(recwarn: Any) -> None: def test_get_pre_conditions() -> None: pre_cons = GreedyPauliSimp().get_preconditions() - gate_set = pre_cons[0].gate_set + gate_set = pre_cons[0].gate_set # type: ignore assert OpType.CX in gate_set assert OpType.Measure in gate_set @@ -1115,14 +1115,14 @@ def test_get_pre_conditions() -> None: def test_get_post_conditions() -> None: gate_set = {OpType.CX, OpType.Rz, OpType.H, OpType.Reset, OpType.Measure} post_cons = AutoRebase(gate_set).get_postconditions() - assert post_cons[0].gate_set == gate_set + assert post_cons[0].gate_set == gate_set # type: ignore def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() assert OpType.CX in gate_set assert OpType.Measure in gate_set - assert CliffordPushThroughMeasures().get_gate_set() is None # type: ignore + assert CliffordPushThroughMeasures().get_gate_set() is None if __name__ == "__main__": From d104331472a9fc29b794d674aae41e560674a762 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:43:48 +0000 Subject: [PATCH 13/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index f70f3fd38a..22a90e931f 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1092,19 +1092,6 @@ def test_greedy_pauli_synth() -> None: assert GreedyPauliSimp().apply(c) -def test_auto_rebase_deprecation(recwarn: Any) -> None: - _ = auto_rebase_pass({OpType.TK1, OpType.CX}) - assert len(recwarn) == 1 - w = recwarn.pop(DeprecationWarning) - assert issubclass(w.category, DeprecationWarning) - assert "deprecated" in str(w.message) - _ = auto_squash_pass({OpType.TK1}) - assert len(recwarn) == 1 - w = recwarn.pop(DeprecationWarning) - assert issubclass(w.category, DeprecationWarning) - assert "deprecated" in str(w.message) - - def test_get_pre_conditions() -> None: pre_cons = GreedyPauliSimp().get_preconditions() gate_set = pre_cons[0].gate_set # type: ignore From 2e4ca318355492e22b196864c44e92176368e2f9 Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:02:11 +0000 Subject: [PATCH 14/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 22a90e931f..3b65cc8a65 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1107,8 +1107,8 @@ def test_get_post_conditions() -> None: def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() - assert OpType.CX in gate_set - assert OpType.Measure in gate_set + assert OpType.CX in gate_set # type: ignore + assert OpType.Measure in gate_set # type: ignore assert CliffordPushThroughMeasures().get_gate_set() is None From ed275e6820bd54d64866f005a35fe0c37712dcdd Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:43:39 +0000 Subject: [PATCH 15/16] addresss comments --- pytket/binders/passes.cpp | 26 +++++++++++++------------- pytket/conanfile.py | 2 +- pytket/tests/predicates_test.py | 5 +++-- tket/conanfile.py | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index 5d9b330fcc..634d046845 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -146,27 +146,26 @@ const PassPtr &DecomposeClassicalExp() { } std::optional get_gate_set(const BasePass &base_pass) { - OpTypeSet allowed_ops; + std::optional allowed_ops; for (const std::pair> &p : base_pass.get_conditions().first) { - if (p.second->to_string().substr(0, 17) == "GateSetPredicate:") { - std::shared_ptr gsp_ptr = - std::dynamic_pointer_cast(p.second); - if (allowed_ops.empty()) { - allowed_ops = gsp_ptr->get_allowed_types(); - continue; - } + std::shared_ptr gsp_ptr = + std::dynamic_pointer_cast(p.second); + if (!gsp_ptr) { + continue; + } + OpTypeSet candidate_allowed_ops = gsp_ptr->get_allowed_types(); + if (!allowed_ops) { + allowed_ops = candidate_allowed_ops; + } else { OpTypeSet intersection; - OpTypeSet candidate_allowed_ops = gsp_ptr->get_allowed_types(); std::set_intersection( candidate_allowed_ops.begin(), candidate_allowed_ops.end(), - allowed_ops.begin(), allowed_ops.end(), + allowed_ops->begin(), allowed_ops->end(), std::inserter(intersection, intersection.begin())); allowed_ops = intersection; } } - if (allowed_ops.empty()) return {}; - return allowed_ops; } @@ -321,7 +320,8 @@ PYBIND11_MODULE(passes, m) { .def( "get_gate_set", &get_gate_set, "Returns the intersection of all set of OpType for all " - "GateSetPredicate in the `BasePass` preconditions.", + "GateSetPredicate in the `BasePass` preconditions, or `None` " + "if there are no gate-set predicates.", "\n\n:return: A set of allowed OpType") .def_static( "from_dict", diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 9bdd4157ce..86c6f590b0 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -38,7 +38,7 @@ def requirements(self): self.requires("pybind11_json/0.2.14") self.requires("symengine/0.13.0") self.requires("tkassert/0.3.4@tket/stable") - self.requires("tket/1.3.50@tket/stable") + self.requires("tket/1.3.49@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tktokenswap/0.3.9@tket/stable") diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 3b65cc8a65..5cfcc6aa81 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1107,8 +1107,9 @@ def test_get_post_conditions() -> None: def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() - assert OpType.CX in gate_set # type: ignore - assert OpType.Measure in gate_set # type: ignore + assert gate_set is not None + assert OpType.CX in gate_set + assert OpType.Measure in gate_set assert CliffordPushThroughMeasures().get_gate_set() is None diff --git a/tket/conanfile.py b/tket/conanfile.py index da3643e863..01a68205a5 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.50" + version = "1.3.49" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" From f0fb61751032606378592eb83512d576e5784e0e Mon Sep 17 00:00:00 2001 From: Silas Dilkes <36165522+sjdilkes@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:43:55 +0000 Subject: [PATCH 16/16] Update predicates_test.py --- pytket/tests/predicates_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 5cfcc6aa81..806d3b8551 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -1108,7 +1108,7 @@ def test_get_post_conditions() -> None: def test_get_gate_set() -> None: gate_set = GreedyPauliSimp().get_gate_set() assert gate_set is not None - assert OpType.CX in gate_set + assert OpType.CX in gate_set assert OpType.Measure in gate_set assert CliffordPushThroughMeasures().get_gate_set() is None