Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implementations of symbol_substitution() for boxes that cannot contain symbols. #1004

Merged
merged 8 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

Unreleased
----------

Fixes:

* Correct implementation of `symbol_substitution()` for box types that cannot
contain symbols.

0.19.0 (September 2023)
-----------------------

Expand Down
15 changes: 15 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions tket/include/tket/Circuit/Boxes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unitary1qBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down Expand Up @@ -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<Unitary2qBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down Expand Up @@ -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<Unitary3qBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down Expand Up @@ -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<ExpBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down Expand Up @@ -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<ProjectorAssertionBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down Expand Up @@ -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<StabiliserAssertionBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down
3 changes: 2 additions & 1 deletion tket/include/tket/Circuit/ConjugationBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConjugationBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down
4 changes: 3 additions & 1 deletion tket/include/tket/Circuit/DiagonalBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <memory>

#include "Boxes.hpp"
#include "Circuit.hpp"
#include "tket/Utils/Json.hpp"
Expand Down Expand Up @@ -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<DiagonalBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down
4 changes: 3 additions & 1 deletion tket/include/tket/Circuit/StatePreparation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <memory>

#include "Boxes.hpp"
#include "Circuit.hpp"
#include "tket/Utils/Json.hpp"
Expand Down Expand Up @@ -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<StatePreparationBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down
4 changes: 3 additions & 1 deletion tket/include/tket/Circuit/ToffoliBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <memory>

#include "Boxes.hpp"
#include "Circuit.hpp"
#include "tket/Utils/Json.hpp"
Expand Down Expand Up @@ -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<ToffoliBox>(*this);
}

SymSet free_symbols() const override { return {}; }
Expand Down
4 changes: 3 additions & 1 deletion tket/include/tket/Ops/ClassicalOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @brief Classical operations
*/

#include <memory>

#include "Op.hpp"
#include "tket/Utils/Json.hpp"

Expand Down Expand Up @@ -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<ClassicalOp>(*this);
}
SymSet free_symbols() const override { return {}; }
unsigned n_qubits() const override { return 0; }
Expand Down
2 changes: 1 addition & 1 deletion tket/src/Converters/UnitaryTableauBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitaryTableauBox>(*this);
}

SymSet UnitaryTableauBox::free_symbols() const { return SymSet(); }
Expand Down
4 changes: 3 additions & 1 deletion tket/src/Ops/FlowOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "tket/Ops/FlowOp.hpp"

#include <memory>

#include "tket/OpType/OpTypeInfo.hpp"

namespace tket {
Expand All @@ -26,7 +28,7 @@ FlowOp::FlowOp(OpType type, std::optional<std::string> label)
}

Op_ptr FlowOp::symbol_substitution(const SymEngine::map_basic_basic&) const {
return Op_ptr();
return std::make_shared<FlowOp>(*this);
}

SymSet FlowOp::free_symbols() const { return {}; }
Expand Down
3 changes: 2 additions & 1 deletion tket/src/Ops/MetaOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "tket/Ops/MetaOp.hpp"

#include <memory>
#include <typeinfo>

#include "tket/OpType/EdgeType.hpp"
Expand All @@ -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<MetaOp>(*this);
}

SymSet MetaOp::free_symbols() const { return {}; }
Expand Down
Loading