From 779fb7ca8536845611db57b7fb0ecb545f3339a6 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Thu, 14 Sep 2023 17:05:48 +0100 Subject: [PATCH 1/9] Update to boost 1.83, tkwsm 0.3.5, tktokenswap 0.3.5. (#980) --- .github/workflows/build-without-conan.yml | 6 +++--- build-without-conan.md | 6 +++--- pytket/conanfile.py | 6 +++--- tket/conanfile.py | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-without-conan.yml b/.github/workflows/build-without-conan.yml index fd57e6a932..4a96ceb39f 100644 --- a/.github/workflows/build-without-conan.yml +++ b/.github/workflows/build-without-conan.yml @@ -30,9 +30,9 @@ jobs: - name: Install boost run: | cd ${TMP_DIR} - wget -O boost_1_82_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.82.0/boost_1_82_0.tar.gz/download - tar xzvf boost_1_82_0.tar.gz - cd boost_1_82_0/ + wget -O boost_1_83_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.83.0/boost_1_83_0.tar.gz/download + tar xzvf boost_1_83_0.tar.gz + cd boost_1_83_0/ ./bootstrap.sh --prefix=${INSTALL_DIR} ./b2 ./b2 install diff --git a/build-without-conan.md b/build-without-conan.md index eb69d6a0f1..40264ab9d7 100644 --- a/build-without-conan.md +++ b/build-without-conan.md @@ -22,9 +22,9 @@ The versions should match the current requirements as specified in the relevant ``` cd ${TMP_DIR} -wget -O boost_1_82_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.82.0/boost_1_82_0.tar.gz/download -tar xzvf boost_1_82_0.tar.gz -cd boost_1_82_0/ +wget -O boost_1_83_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.83.0/boost_1_83_0.tar.gz/download +tar xzvf boost_1_83_0.tar.gz +cd boost_1_83_0/ ./bootstrap.sh --prefix=${INSTALL_DIR} ./b2 ./b2 install diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 22fe5446e0..5677796e45 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -32,12 +32,12 @@ def package(self): cmake.install() def requirements(self): - self.requires("tket/1.2.40@tket/stable") + self.requires("tket/1.2.41@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tkassert/0.3.3@tket/stable") - self.requires("tkwsm/0.3.4@tket/stable") - self.requires("tktokenswap/0.3.4@tket/stable") + self.requires("tkwsm/0.3.5@tket/stable") + self.requires("tktokenswap/0.3.5@tket/stable") self.requires("symengine/0.10.1") self.requires("gmp/6.2.1") self.requires("pybind11/2.11.1") diff --git a/tket/conanfile.py b/tket/conanfile.py index 97f9578eb3..f08779f778 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.2.40" + version = "1.2.41" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" @@ -111,15 +111,15 @@ def package_info(self): def requirements(self): # libraries installed from remote: # https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs - self.requires("boost/1.82.0", transitive_headers=True) + self.requires("boost/1.83.0", transitive_headers=True) self.requires("symengine/0.10.1", transitive_headers=True) self.requires("eigen/3.4.0", transitive_headers=True) self.requires("nlohmann_json/3.11.2", transitive_headers=True) self.requires("tklog/0.3.3@tket/stable") self.requires("tkassert/0.3.3@tket/stable", transitive_headers=True) self.requires("tkrng/0.3.3@tket/stable") - self.requires("tktokenswap/0.3.4@tket/stable") - self.requires("tkwsm/0.3.4@tket/stable") + self.requires("tktokenswap/0.3.5@tket/stable") + self.requires("tkwsm/0.3.5@tket/stable") if self.build_test(): self.test_requires("catch2/3.3.2") if self.build_proptest(): From aef29d556df3ba93954f59199ce07c43dc6a8020 Mon Sep 17 00:00:00 2001 From: yao-cqc <75305462+yao-cqc@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:21:59 +0100 Subject: [PATCH 2/9] Bugfix/slow cliffordsimp (#1026) * Fix DAG traversal blowup in Clifford reduction * Bump tket version * Add changelog entry --- pytket/conanfile.py | 2 +- pytket/docs/changelog.rst | 7 +++++++ tket/conanfile.py | 2 +- tket/src/Transformations/CliffordReductionPass.cpp | 13 +++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 5677796e45..c9c664b8c0 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.41@tket/stable") + self.requires("tket/1.2.42@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tkassert/0.3.3@tket/stable") diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 8cadaa97c7..9aac8f57be 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +Unreleased +---------- + +Fixes: + +* Fix ``CliffordSimp`` slow runtime issue. + 1.20.0 (September 2023) ----------------------- diff --git a/tket/conanfile.py b/tket/conanfile.py index f08779f778..f67f04c7e0 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.2.41" + version = "1.2.42" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" diff --git a/tket/src/Transformations/CliffordReductionPass.cpp b/tket/src/Transformations/CliffordReductionPass.cpp index 489c33f85c..dbb84cb516 100644 --- a/tket/src/Transformations/CliffordReductionPass.cpp +++ b/tket/src/Transformations/CliffordReductionPass.cpp @@ -410,8 +410,12 @@ Subcircuit CliffordReductionPass::substitute( // edges. EdgeList future_edges; VertexSet v_frontier; + // keep track of visited vertices + VertexSet visited; for (unsigned qi = 0; qi < q_width; ++qi) { - v_frontier.insert(circ.target(out_edges[qi])); + Vertex target = circ.target(out_edges[qi]); + visited.insert(target); + v_frontier.insert(target); } while (!v_frontier.empty()) { EdgeSet out_edges; @@ -424,7 +428,12 @@ Subcircuit CliffordReductionPass::substitute( future_edges.insert(future_edges.end(), out_edges.begin(), out_edges.end()); VertexSet new_v_frontier; for (auto e : out_edges) { - new_v_frontier.insert(circ.target(e)); + Vertex target = circ.target(e); + auto it = visited.insert(target); + if (it.second) { + // add vertex to the next frontier if the vertex has not been visited + new_v_frontier.insert(target); + } } v_frontier = std::move(new_v_frontier); } From 03ee776a06e62a9c513800bf94fef878fa130834 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:43:37 +0100 Subject: [PATCH 3/9] [bugfix] Implement `symbol_substitution()` and `free_symbols()` for `ConjugationBox` (#1027) --- pytket/conanfile.py | 2 +- pytket/docs/changelog.rst | 2 ++ tket/conanfile.py | 2 +- tket/include/tket/Circuit/ConjugationBox.hpp | 8 ++--- tket/src/Circuit/ConjugationBox.cpp | 33 ++++++++++++++++++++ tket/test/src/Circuit/test_Boxes.cpp | 30 ++++++++++++++++++ 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index c9c664b8c0..f6a074d78e 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.42@tket/stable") + self.requires("tket/1.2.43@tket/stable") self.requires("tklog/0.3.3@tket/stable") self.requires("tkrng/0.3.3@tket/stable") self.requires("tkassert/0.3.3@tket/stable") diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 9aac8f57be..1d61caf346 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -7,6 +7,8 @@ Unreleased Fixes: * Fix ``CliffordSimp`` slow runtime issue. +* Correct implementation of ``free_symbols()`` and ``symbol_substitution()`` for + ``ConjugationBox``. 1.20.0 (September 2023) ----------------------- diff --git a/tket/conanfile.py b/tket/conanfile.py index f67f04c7e0..43252ad8c6 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.2.42" + version = "1.2.43" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" diff --git a/tket/include/tket/Circuit/ConjugationBox.hpp b/tket/include/tket/Circuit/ConjugationBox.hpp index 6dc9397ba7..2a8a5347de 100644 --- a/tket/include/tket/Circuit/ConjugationBox.hpp +++ b/tket/include/tket/Circuit/ConjugationBox.hpp @@ -45,13 +45,9 @@ class ConjugationBox : public Box { ConjugationBox(const ConjugationBox &other); ~ConjugationBox() override {} - Op_ptr symbol_substitution( - const SymEngine::map_basic_basic &) const override { - // FIXME https://github.com/CQCL/tket/issues/1007 - return std::make_shared(*this); - } + Op_ptr symbol_substitution(const SymEngine::map_basic_basic &) const override; - SymSet free_symbols() const override { return {}; } + SymSet free_symbols() const override; /** * Equality check between two ConjugationBox instances diff --git a/tket/src/Circuit/ConjugationBox.cpp b/tket/src/Circuit/ConjugationBox.cpp index 293daeefe2..2120189b71 100644 --- a/tket/src/Circuit/ConjugationBox.cpp +++ b/tket/src/Circuit/ConjugationBox.cpp @@ -14,6 +14,10 @@ #include "tket/Circuit/ConjugationBox.hpp" +#include +#include + +#include "Utils/Expression.hpp" #include "tket/Circuit/Circuit.hpp" #include "tket/Ops/OpJsonFactory.hpp" #include "tket/Utils/HelperFunctions.hpp" @@ -89,6 +93,35 @@ void ConjugationBox::generate_circuit() const { circ_ = std::make_shared(circ); } +Op_ptr ConjugationBox::symbol_substitution( + const SymEngine::map_basic_basic &sub_map) const { + if (uncompute_.has_value()) { + return std::make_shared( + compute_->symbol_substitution(sub_map), + action_->symbol_substitution(sub_map), + uncompute_.value()->symbol_substitution(sub_map)); + } else { + return std::make_shared( + compute_->symbol_substitution(sub_map), + action_->symbol_substitution(sub_map)); + } +} + +SymSet ConjugationBox::free_symbols() const { + SymSet compute_syms = compute_->free_symbols(); + SymSet action_syms = action_->free_symbols(); + SymSet uncompute_syms; + if (uncompute_.has_value()) { + SymSet s = uncompute_.value()->free_symbols(); + uncompute_syms.insert(s.begin(), s.end()); + } + SymSet sym_set; + sym_set.insert(compute_syms.begin(), compute_syms.end()); + sym_set.insert(action_syms.begin(), action_syms.end()); + sym_set.insert(uncompute_syms.begin(), uncompute_syms.end()); + return sym_set; +} + bool ConjugationBox::is_equal(const Op &op_other) const { const ConjugationBox &other = dynamic_cast(op_other); if (id_ == other.get_id()) return true; diff --git a/tket/test/src/Circuit/test_Boxes.cpp b/tket/test/src/Circuit/test_Boxes.cpp index ec6b58679e..d963fa6f51 100644 --- a/tket/test/src/Circuit/test_Boxes.cpp +++ b/tket/test/src/Circuit/test_Boxes.cpp @@ -15,7 +15,12 @@ #include #include #include +#include #include +#include +#include +#include +#include #include "../testutil.hpp" #include "tket/Circuit/Boxes.hpp" @@ -1283,6 +1288,31 @@ SCENARIO("Checking equality", "[boxes]") { REQUIRE(box != ConjugationBox(compute_2_op, action_op)); } } + GIVEN("ConjugationBox with symbols") { + Sym asym = SymTable::fresh_symbol("a"); + Expr a(asym); + Sym bsym = SymTable::fresh_symbol("b"); + Expr b(bsym); + Sym csym = SymTable::fresh_symbol("c"); + Expr c(csym); + Op_ptr compute = get_op_ptr(OpType::Rx, {a}); + Op_ptr action = get_op_ptr(OpType::Rz, {b}); + Op_ptr uncompute = get_op_ptr(OpType::Rx, {c}); + ConjugationBox box0(compute, action); + ConjugationBox box1(compute, action, uncompute); + SymSet sym_set0 = box0.free_symbols(); + CHECK(sym_set0.size() == 2); + SymSet sym_set1 = box1.free_symbols(); + CHECK(sym_set1.size() == 3); + SymEngine::map_basic_basic sym_map; + sym_map[asym] = Expr(0.25); + sym_map[bsym] = Expr(0.75); + sym_map[csym] = Expr(-0.25); + Op_ptr sub_box0 = box0.symbol_substitution(sym_map); + CHECK(sub_box0->free_symbols().empty()); + Op_ptr sub_box1 = box1.symbol_substitution(sym_map); + CHECK(sub_box1->free_symbols().empty()); + } } SCENARIO("Checking box names", "[boxes]") { From b0db6ef300b08b4013e6a5ebf28c630d314e9f7a Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Mon, 18 Sep 2023 09:56:48 +0100 Subject: [PATCH 4/9] Revert "[infra] Pin conan to 2.0.9 for the `build_test_tket_windows` job. (#990)" (#1029) This reverts commit 2aec89c027c0e0e402eb88887ba0bec9e6457969. --- .github/workflows/build_and_test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8e018f48b0..0c348251a6 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -147,8 +147,6 @@ jobs: - uses: actions/checkout@v4 - name: Install conan uses: turtlebrowser/get-conan@v1.2 - with: - version: '2.0.9' - name: Set up conan id: conan-setup run: | From 9691dbf71d93f93aa4b1836dcbada081bcb93e11 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:01:33 +0100 Subject: [PATCH 5/9] [infra] Set cppstd to gnu17 in default profile on MacOS. (#1033) --- .github/workflows/build_and_test.yml | 18 ++++++++++++++++++ .github/workflows/build_libs.yml | 9 +++++++++ .github/workflows/packages.yml | 10 ++++++++++ .github/workflows/release.yml | 6 ++++++ .github/workflows/test_libs.yml | 9 +++++++++ .github/workflows/test_libs_all.yml | 9 +++++++++ 6 files changed, 61 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0c348251a6..1ec6bc6271 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -109,6 +109,11 @@ jobs: run: | conan profile detect conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: Install runtime test requirements if: matrix.os == 'ubuntu-22.04' && github.event_name == 'schedule' run: | @@ -219,6 +224,10 @@ jobs: conan profile detect --force conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --force --index 0 conan cache clean + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -371,6 +380,11 @@ jobs: run: | conan profile detect conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -527,6 +541,10 @@ jobs: run: | conan profile detect --force conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --force --index 0 + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: Remove tket package from cache run: conan remove -c 'tket/*' - name: ccache diff --git a/.github/workflows/build_libs.yml b/.github/workflows/build_libs.yml index a4ef33033b..f351e9bb64 100644 --- a/.github/workflows/build_libs.yml +++ b/.github/workflows/build_libs.yml @@ -66,6 +66,11 @@ jobs: uses: turtlebrowser/get-conan@v1.2 - name: create profile run: conan profile detect + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: add remote run: conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: build ${{ matrix.lib }} @@ -98,6 +103,10 @@ jobs: uses: turtlebrowser/get-conan@v1.2 - name: create profile run: conan profile detect --force + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: set remotes run: conan remote add --force tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: build ${{ matrix.lib }} diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index ab1097c560..d2f4bb81f2 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -36,6 +36,11 @@ jobs: run: | conan profile detect conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: authenticate to repository run: conan remote login -p ${{ secrets.JFROG_ARTIFACTORY_TOKEN_3 }} tket-libs ${{ secrets.JFROG_ARTIFACTORY_USER_3 }} @@ -59,6 +64,11 @@ jobs: conan profile detect --force conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --force --index 0 + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} + - name: authenticate to repository run: conan remote login -p ${{ secrets.JFROG_ARTIFACTORY_TOKEN_3 }} tket-libs ${{ secrets.JFROG_ARTIFACTORY_USER_3 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a97a24cac..26afdb1edb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -92,6 +92,10 @@ jobs: run: | conan profile detect conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: Build tket C++ run: conan create tket --user tket --channel stable --build=missing -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True -tf "" - name: Build wheel @@ -128,6 +132,8 @@ jobs: pyenv shell tket-${{ matrix.python-version }} python -m pip install -U conan conan profile detect --force + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --force --index 0 conan remove -c 'tket/*' conan create tket --user tket --channel stable --build=missing -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True -tf "" diff --git a/.github/workflows/test_libs.yml b/.github/workflows/test_libs.yml index cd2e4b29c2..78bf4fc210 100644 --- a/.github/workflows/test_libs.yml +++ b/.github/workflows/test_libs.yml @@ -76,6 +76,11 @@ jobs: uses: turtlebrowser/get-conan@v1.2 - name: create profile run: conan profile detect + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: add remote run: conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: build ${{ matrix.lib }} @@ -104,6 +109,10 @@ jobs: - name: create profile shell: bash run: conan profile detect --force + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: set remotes run: conan remote add --force tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: build ${{ matrix.lib }} diff --git a/.github/workflows/test_libs_all.yml b/.github/workflows/test_libs_all.yml index 31e477d0d1..73349876ca 100644 --- a/.github/workflows/test_libs_all.yml +++ b/.github/workflows/test_libs_all.yml @@ -23,6 +23,11 @@ jobs: uses: turtlebrowser/get-conan@v1.2 - name: create profile run: conan profile detect + - name: Fix conan profile for clang toolchain + if: matrix.os == 'macos-12' + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: add remote run: conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: build ${{ matrix.lib }} @@ -48,6 +53,10 @@ jobs: - name: create profile shell: bash run: conan profile detect --force + - name: Fix conan profile for clang toolchain + run: | + PROFILE_PATH=`conan profile path default` + sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} - name: add remote run: conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --force --index 0 - name: build ${{ matrix.lib }} From c341945d806c032c5611e79b1b3f495441a5241a Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:13:17 +0100 Subject: [PATCH 6/9] Fix fix. (#1035) --- .github/workflows/build_and_test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1ec6bc6271..1ad8b50381 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -381,7 +381,6 @@ jobs: conan profile detect conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0 - name: Fix conan profile for clang toolchain - if: matrix.os == 'macos-12' run: | PROFILE_PATH=`conan profile path default` sed -i -e 's/gnu98/gnu17/' ${PROFILE_PATH} From 61f8194fd83d3f8c9082129faa799a27aaf11ade Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Mon, 18 Sep 2023 15:05:52 +0100 Subject: [PATCH 7/9] [bugfix] Fix pytket-to-QASM conversion when individual bits of registers used in range predicates are later set (#1031) --- pytket/docs/changelog.rst | 2 ++ pytket/pytket/qasm/qasm.py | 1 + pytket/tests/qasm_test.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 1d61caf346..56d4f41703 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -9,6 +9,8 @@ Fixes: * Fix ``CliffordSimp`` slow runtime issue. * Correct implementation of ``free_symbols()`` and ``symbol_substitution()`` for ``ConjugationBox``. +* Fix pytket-to-QASM conversion when individual bits of registers used in + range predicates are later set. 1.20.0 (September 2023) ----------------------- diff --git a/pytket/pytket/qasm/qasm.py b/pytket/pytket/qasm/qasm.py index 48f18a5ba5..bde639855c 100644 --- a/pytket/pytket/qasm/qasm.py +++ b/pytket/pytket/qasm/qasm.py @@ -1261,6 +1261,7 @@ def mark_as_written(self, written_variable: str) -> None: (variable, comparator, value, dest_bit, label) for (variable, comparator, value, dest_bit, label) in self.range_preds if variable == written_variable + or written_variable.startswith(variable + "[") ] for hit in hits: self.range_preds.remove(hit) diff --git a/pytket/tests/qasm_test.py b/pytket/tests/qasm_test.py index 878e794953..0c6817bc6a 100644 --- a/pytket/tests/qasm_test.py +++ b/pytket/tests/qasm_test.py @@ -786,6 +786,38 @@ def test_classical_assignment_order() -> None: assert posns[i] < posns[i + 1] +def test_classical_assignment_order_1() -> None: + circ = Circuit(1) + reg_meas = circ.add_c_register("c0", 1) + reg_cond = circ.add_c_register("c1", 1) + reg_aux = circ.add_c_register("c2", 1) + circ.add_c_setreg(0, reg_cond) + circ.add_c_setreg(1, reg_aux) + circ.add_c_xor(reg_cond[0], reg_aux[0], reg_cond[0]) + circ.X(0, condition=reg_eq(reg_cond, 1)) + circ.add_c_xor(reg_cond[0], reg_aux[0], reg_cond[0]) + circ.Measure(Qubit(0), reg_meas[0]) + qasm = circuit_to_qasm_str(circ, header="hqslib1") + correct_qasm = """OPENQASM 2.0; +include "hqslib1.inc"; + +qreg q[1]; +creg c0[1]; +creg c1[1]; +creg c2[1]; +creg tk_SCRATCH_BIT[1]; +c1 = 0; +c2 = 1; +c1[0] = c2[0] ^ c1[0]; +if(c1==1) tk_SCRATCH_BIT[0] = 1; +if(c1!=1) tk_SCRATCH_BIT[0] = 0; +c1[0] = c2[0] ^ c1[0]; +if(tk_SCRATCH_BIT[0]==1) x q[0]; +measure q[0] -> c0[0]; +""" + assert qasm == correct_qasm + + if __name__ == "__main__": test_qasm_correct() test_qasm_qubit() From 5d0966305833332a7c5f26500c0947ec29f9bb47 Mon Sep 17 00:00:00 2001 From: Travis Thompson <102229498+trvto@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:35:36 +0200 Subject: [PATCH 8/9] remove unnecessary and faulty cast to Gate in op.get_unitary (#1030) * remove unnecessary and faulty cast to Gate in op.get_unitary * add test, and changlog entry * clang + black --- pytket/binders/circuit/main.cpp | 7 +------ pytket/docs/changelog.rst | 1 + pytket/tests/circuit_test.py | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pytket/binders/circuit/main.cpp b/pytket/binders/circuit/main.cpp index 48936c8435..e4d5ce7b83 100644 --- a/pytket/binders/circuit/main.cpp +++ b/pytket/binders/circuit/main.cpp @@ -542,12 +542,7 @@ PYBIND11_MODULE(circuit, m) { .def("__hash__", &deletedHash, deletedHashDocstring) .def("__repr__", [](const Op &op) { return op.get_name(); }) .def("free_symbols", [](const Op &op) { return op.free_symbols(); }) - .def( - "get_unitary", - [](const Op *op) { - const auto &gate = dynamic_cast(*op); - return gate.get_unitary(); - }) + .def("get_unitary", [](const Op *op) { return op->get_unitary(); }) .def( "is_clifford_type", [](const Op &op) { return op.get_desc().is_clifford_gate(); }, diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 56d4f41703..171dab65ec 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -6,6 +6,7 @@ Unreleased Fixes: +* Fix ``Op.get_unitary()`` runtime error for non gate ``Op``s. * Fix ``CliffordSimp`` slow runtime issue. * Correct implementation of ``free_symbols()`` and ``symbol_substitution()`` for ``ConjugationBox``. diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index 8df55b4dd7..e0ec0e37af 100644 --- a/pytket/tests/circuit_test.py +++ b/pytket/tests/circuit_test.py @@ -613,6 +613,10 @@ def test_boxes() -> None: d.add_conjugation_box(conj_box2, [Qubit(0), Qubit(1), Qubit(2)]) assert d.n_gates == 25 assert json_validate(d) + # test op.get_unitary doesn't throw + for command in d.get_commands(): + if len(command.op.free_symbols()) == 0: + command.op.get_unitary() def test_tofollibox_strats() -> None: From 1f27d5354f499b14ffe97196eb83a791e181dd88 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Tue, 19 Sep 2023 08:42:42 +0100 Subject: [PATCH 9/9] Update version and changelog. --- pytket/docs/changelog.rst | 4 ++-- pytket/docs/conf.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 171dab65ec..467a6c5c6f 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,8 +1,8 @@ Changelog ========= -Unreleased ----------- +1.20.1 (September 2023) +----------------------- Fixes: diff --git a/pytket/docs/conf.py b/pytket/docs/conf.py index 6df642e667..10e0d46bd0 100644 --- a/pytket/docs/conf.py +++ b/pytket/docs/conf.py @@ -40,7 +40,7 @@ # The short X.Y version version = "1.20" # The full version, including alpha/beta/rc tags -release = "1.20.0" +release = "1.20.1" # -- General configuration ---------------------------------------------------