From fc89c70dc2c57f6617f6297946ab2935b9f07bbd Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:19:44 +0000 Subject: [PATCH] [bugfix] Don't reuse "stale" Pauli stabilizers when generating Pauli graphs (#1245) --- pytket/conanfile.py | 2 +- pytket/docs/changelog.rst | 5 +++++ tket/conanfile.py | 2 +- tket/src/PauliGraph/PauliGraph.cpp | 5 +++-- tket/test/src/test_CompilerPass.cpp | 13 +++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index cd8d59b8b3..4a3873aa34 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -32,7 +32,7 @@ def package(self): cmake.install() def requirements(self): - self.requires("tket/1.2.89@tket/stable") + self.requires("tket/1.2.90@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tkassert/0.3.4@tket/stable") diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index fa638f0e9c..e7e6e851b5 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -8,6 +8,11 @@ Features: * Add ``WasmFileHandler.bytecode()`` method to retrieve the WASM as bytecode. +Fixes: + +* Fix bug in ``PauliExponentials()`` pass affecting circuits containing + ``PhasedX`` gates containing Clifford angles. + 1.24.0 (January 2024) --------------------- diff --git a/tket/conanfile.py b/tket/conanfile.py index 0864fe494b..0c6e9481f5 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.2.89" + version = "1.2.90" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" diff --git a/tket/src/PauliGraph/PauliGraph.cpp b/tket/src/PauliGraph/PauliGraph.cpp index a6ec0fcae6..abd2a8b42c 100644 --- a/tket/src/PauliGraph/PauliGraph.cpp +++ b/tket/src/PauliGraph/PauliGraph.cpp @@ -163,8 +163,6 @@ void PauliGraph::apply_gate_at_end( case OpType::PhasedX: { Expr alpha = gate.get_params().at(0); Expr beta = gate.get_params().at(1); - SpPauliStabiliser zpauli = cliff_.get_zrow(qbs.at(0)); - SpPauliStabiliser xpauli = cliff_.get_xrow(qbs.at(0)); std::optional cliff_alpha = equiv_Clifford(alpha); std::optional cliff_beta = equiv_Clifford(beta); // Rz(-b) @@ -173,6 +171,7 @@ void PauliGraph::apply_gate_at_end( cliff_.apply_gate_at_end(OpType::Sdg, qbs); } } else { + SpPauliStabiliser zpauli = cliff_.get_zrow(qbs.at(0)); apply_pauli_gadget_at_end(zpauli, -beta); } // Rx(a) @@ -181,6 +180,7 @@ void PauliGraph::apply_gate_at_end( cliff_.apply_gate_at_end(OpType::V, qbs); } } else { + SpPauliStabiliser xpauli = cliff_.get_xrow(qbs.at(0)); apply_pauli_gadget_at_end(xpauli, alpha); } // Rz(b) @@ -189,6 +189,7 @@ void PauliGraph::apply_gate_at_end( cliff_.apply_gate_at_end(OpType::S, qbs); } } else { + SpPauliStabiliser zpauli = cliff_.get_zrow(qbs.at(0)); apply_pauli_gadget_at_end(zpauli, beta); } break; diff --git a/tket/test/src/test_CompilerPass.cpp b/tket/test/src/test_CompilerPass.cpp index 5106e5cfc5..43ed4d4b46 100644 --- a/tket/test/src/test_CompilerPass.cpp +++ b/tket/test/src/test_CompilerPass.cpp @@ -2026,5 +2026,18 @@ SCENARIO( REQUIRE(cu.get_circ_ref().n_gates() == 1); } } + +SCENARIO("PauliExponentials") { + GIVEN("A PhasedX gate") { + // https://github.com/CQCL/tket/issues/1244 + Circuit c(1); + c.add_op(OpType::PhasedX, {0.5, 0.6}, {0}); + c.add_op(OpType::PhasedX, {0.6, 0.5}, {0}); + CompilationUnit cu(c); + CHECK(gen_pauli_exponentials(Transforms::PauliSynthStrat::Individual) + ->apply(cu)); + REQUIRE(test_unitary_comparison(c, cu.get_circ_ref(), true)); + } +} } // namespace test_CompilerPass } // namespace tket