From 6c9847f97f89de0abd3202142b86286ef3f330f0 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:40:34 +0000 Subject: [PATCH] Ignore boxes when applying KAK decomposition to a circuit (#1740) --- pytket/conanfile.py | 2 +- pytket/docs/changelog.rst | 1 + pytket/tests/transform_test.py | 7 +++++++ tket/conanfile.py | 2 +- tket/src/Transformations/BasicOptimisation.cpp | 4 +++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index f2ff74f897..fc5a917d6d 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -38,7 +38,7 @@ def requirements(self): self.requires("pybind11_json/0.2.15") self.requires("symengine/0.13.0") self.requires("tkassert/0.3.4@tket/stable") - self.requires("tket/1.3.61@tket/stable") + self.requires("tket/1.3.62@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/docs/changelog.rst b/pytket/docs/changelog.rst index 2e215cb5f1..223b0ff45c 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -11,6 +11,7 @@ Features: Fixes: * Fix issue with custom gates in qasm to circuit conversion. +* Ignore boxes when applying `KAKDecomposition`. 1.38.0 (January 2025) --------------------- diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index 4dfc15116a..0a824fa51c 100644 --- a/pytket/tests/transform_test.py +++ b/pytket/tests/transform_test.py @@ -1237,6 +1237,13 @@ def test_KAK_with_ClassicalExpBox() -> None: assert not kak.apply(circ) +def test_KAK_with_CircBox() -> None: + # https://github.com/CQCL/tket/issues/1553 + cbox = CircBox(Circuit(2)) + c = Circuit(2).add_circbox(cbox, [0, 1]).add_circbox(cbox, [0, 1]) + assert not Transform.KAKDecomposition().apply(c) + + def test_round_angles() -> None: circ0 = Circuit(3).H(0).CRz(0.001, 0, 1).TK2(0.5, 0.499, 0.501, 1, 2) circ1 = Circuit(3).H(0).TK2(0.5, 0.5, 0.5, 1, 2) diff --git a/tket/conanfile.py b/tket/conanfile.py index 2ff3a91a06..a2703a4cd4 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.61" + version = "1.3.62" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" diff --git a/tket/src/Transformations/BasicOptimisation.cpp b/tket/src/Transformations/BasicOptimisation.cpp index 9fa6fe86fd..850fc073b0 100644 --- a/tket/src/Transformations/BasicOptimisation.cpp +++ b/tket/src/Transformations/BasicOptimisation.cpp @@ -267,7 +267,9 @@ Transform two_qubit_squash( circ.get_next_edge(*v, current_edge_on_qb[q]); } } - } else if (circ.n_in_edges_of_type(*v, EdgeType::Quantum) == 2) { + } else if ( + is_gate_type(type) && + circ.n_in_edges_of_type(*v, EdgeType::Quantum) == 2) { // Check for 2qb gate Qubit q0 = v_to_qb.at({*v, 0}); Qubit q1 = v_to_qb.at({*v, 1});