diff --git a/pytket/conanfile.py b/pytket/conanfile.py index cf3933f698..9eccfb041d 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.38@tket/stable") + self.requires("tket/1.2.39@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 0373115641..e27d364c26 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Unreleased +---------- + +Fixes: + +* Correct implementation of `symbol_substitution()` for box types that cannot + contain symbols. + 0.19.0 (September 2023) ----------------------- diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index f9a3e1ea00..13e2b1136c 100644 --- a/pytket/tests/circuit_test.py +++ b/pytket/tests/circuit_test.py @@ -1239,6 +1239,21 @@ def test_error_wrong_parameters() -> None: circ.add_gate(OpType.H, [Bit(0)]) +def test_symbol_subst() -> None: + # https://github.com/CQCL/tket/issues/999 + d = Circuit(4) + rz_op = Op.create(OpType.Rz, 0.3) + pauli_x_op = Op.create(OpType.X) + pauli_z_op = Op.create(OpType.Z) + u = np.asarray([[1.0, 0.0], [0.0, -1.0]]) + ubox = Unitary1qBox(u) + op_map_new = [([_0, _0], [rz_op, pauli_x_op]), ([_1, _1], [ubox, pauli_z_op])] + multiplexU2 = MultiplexedTensoredU2Box(op_map_new) + d.add_multiplexed_tensored_u2(multiplexU2, [0, 1, 2, 3]) + d.symbol_substitution({}) + assert len(d.get_commands()) == 1 + + if __name__ == "__main__": test_circuit_gen() test_symbolic_ops() diff --git a/tket/conanfile.py b/tket/conanfile.py index ad73ac168f..dd7fbc1ad0 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.2.38" + version = "1.2.39" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" diff --git a/tket/include/tket/Circuit/Boxes.hpp b/tket/include/tket/Circuit/Boxes.hpp index 2cb30d80d1..21994d6172 100644 --- a/tket/include/tket/Circuit/Boxes.hpp +++ b/tket/include/tket/Circuit/Boxes.hpp @@ -200,7 +200,7 @@ class Unitary1qBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } @@ -262,7 +262,7 @@ class Unitary2qBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } @@ -321,7 +321,7 @@ class Unitary3qBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } @@ -386,7 +386,7 @@ class ExpBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } @@ -575,7 +575,7 @@ class ProjectorAssertionBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } @@ -627,7 +627,7 @@ class StabiliserAssertionBox : public Box { ~StabiliserAssertionBox() override {} Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } diff --git a/tket/include/tket/Circuit/ConjugationBox.hpp b/tket/include/tket/Circuit/ConjugationBox.hpp index 62fac23ad5..6dc9397ba7 100644 --- a/tket/include/tket/Circuit/ConjugationBox.hpp +++ b/tket/include/tket/Circuit/ConjugationBox.hpp @@ -47,7 +47,8 @@ class ConjugationBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + // FIXME https://github.com/CQCL/tket/issues/1007 + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } diff --git a/tket/include/tket/Circuit/DiagonalBox.hpp b/tket/include/tket/Circuit/DiagonalBox.hpp index 22fbbbbe4f..99839e5b46 100644 --- a/tket/include/tket/Circuit/DiagonalBox.hpp +++ b/tket/include/tket/Circuit/DiagonalBox.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include "Boxes.hpp" #include "Circuit.hpp" #include "tket/Utils/Json.hpp" @@ -44,7 +46,7 @@ class DiagonalBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } diff --git a/tket/include/tket/Circuit/StatePreparation.hpp b/tket/include/tket/Circuit/StatePreparation.hpp index 062568cd25..bcee466f4a 100644 --- a/tket/include/tket/Circuit/StatePreparation.hpp +++ b/tket/include/tket/Circuit/StatePreparation.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include "Boxes.hpp" #include "Circuit.hpp" #include "tket/Utils/Json.hpp" @@ -46,7 +48,7 @@ class StatePreparationBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } diff --git a/tket/include/tket/Circuit/ToffoliBox.hpp b/tket/include/tket/Circuit/ToffoliBox.hpp index 1851ceaed4..fe13ed7703 100644 --- a/tket/include/tket/Circuit/ToffoliBox.hpp +++ b/tket/include/tket/Circuit/ToffoliBox.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include "Boxes.hpp" #include "Circuit.hpp" #include "tket/Utils/Json.hpp" @@ -65,7 +67,7 @@ class ToffoliBox : public Box { Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } diff --git a/tket/include/tket/Ops/ClassicalOps.hpp b/tket/include/tket/Ops/ClassicalOps.hpp index 80df5bb5ba..7d7464b24e 100644 --- a/tket/include/tket/Ops/ClassicalOps.hpp +++ b/tket/include/tket/Ops/ClassicalOps.hpp @@ -19,6 +19,8 @@ * @brief Classical operations */ +#include + #include "Op.hpp" #include "tket/Utils/Json.hpp" @@ -48,7 +50,7 @@ class ClassicalOp : public Op { // Trivial overrides Op_ptr symbol_substitution( const SymEngine::map_basic_basic &) const override { - return Op_ptr(); + return std::make_shared(*this); } SymSet free_symbols() const override { return {}; } unsigned n_qubits() const override { return 0; } diff --git a/tket/src/Converters/UnitaryTableauBox.cpp b/tket/src/Converters/UnitaryTableauBox.cpp index 9fbe895906..66a2451f5a 100644 --- a/tket/src/Converters/UnitaryTableauBox.cpp +++ b/tket/src/Converters/UnitaryTableauBox.cpp @@ -46,7 +46,7 @@ Op_ptr UnitaryTableauBox::transpose() const { Op_ptr UnitaryTableauBox::symbol_substitution( const SymEngine::map_basic_basic&) const { - return Op_ptr(); + return std::make_shared(*this); } SymSet UnitaryTableauBox::free_symbols() const { return SymSet(); } diff --git a/tket/src/Ops/FlowOp.cpp b/tket/src/Ops/FlowOp.cpp index d44cd4c8ce..eb8d1fc03b 100644 --- a/tket/src/Ops/FlowOp.cpp +++ b/tket/src/Ops/FlowOp.cpp @@ -14,6 +14,8 @@ #include "tket/Ops/FlowOp.hpp" +#include + #include "tket/OpType/OpTypeInfo.hpp" namespace tket { @@ -26,7 +28,7 @@ FlowOp::FlowOp(OpType type, std::optional label) } Op_ptr FlowOp::symbol_substitution(const SymEngine::map_basic_basic&) const { - return Op_ptr(); + return std::make_shared(*this); } SymSet FlowOp::free_symbols() const { return {}; } diff --git a/tket/src/Ops/MetaOp.cpp b/tket/src/Ops/MetaOp.cpp index b3f8bc5218..5ec22cb93f 100644 --- a/tket/src/Ops/MetaOp.cpp +++ b/tket/src/Ops/MetaOp.cpp @@ -14,6 +14,7 @@ #include "tket/Ops/MetaOp.hpp" +#include #include #include "tket/OpType/EdgeType.hpp" @@ -28,7 +29,7 @@ MetaOp::MetaOp(OpType type, op_signature_t signature, const std::string& _data) } Op_ptr MetaOp::symbol_substitution(const SymEngine::map_basic_basic&) const { - return Op_ptr(); + return std::make_shared(*this); } SymSet MetaOp::free_symbols() const { return {}; }