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

Allow barriers when dagger or transpose circuits #1400

Merged
merged 4 commits into from
May 17, 2024
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.126@tket/stable")
self.requires("tket/1.2.127@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")
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:

* Allow barriers when dagger or transpose a circuit.


1.28.0 (May 2024)
-----------------

Expand Down
9 changes: 9 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def test_circuit_dagger() -> None:
assert commands[1].op.get_matrix().all() == u.conj().transpose().all()


def test_circuit_dagger_transpose_with_barriers() -> None:
c = Circuit(2).S(0).add_barrier([0, 1]).CX(0, 1)
c_d = c.dagger()
assert c_d == Circuit(2).CX(0, 1).add_barrier([0, 1]).Sdg(0)
c = Circuit(2).Ry(0.3, 0).add_barrier([0, 1]).CX(0, 1)
c_t = c.transpose()
assert c_t == Circuit(2).CX(0, 1).add_barrier([0, 1]).Ry(-0.3, 0)


# TKET-1365 bug
def test_cnx_dagger() -> None:
c = Circuit(2)
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.126"
version = "1.2.127"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
3 changes: 3 additions & 0 deletions tket/src/Circuit/macro_manipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ void Circuit::_handle_interior(
}
Vertex v = circ.add_vertex(op_type_ptr);
vmap[*vi] = v;
} else if (desc.is_barrier()) {
Vertex v = circ.add_vertex(op);
vmap[*vi] = v;
} else {
throw CircuitInvalidity(
"Cannot dagger or transpose op: " + op->get_name());
Expand Down
26 changes: 26 additions & 0 deletions tket/test/src/Circuit/test_Circ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,19 @@ SCENARIO("Test circuit.transpose() method") {
REQUIRE(matrices_are_equal(ubox_t->get_matrix(), m.transpose()));
REQUIRE(*cx_t_ptr == *get_op_ptr(OpType::CX));
}
GIVEN("Circuit with barriers") {
Circuit circ(2);
circ.add_op<unsigned>(OpType::Y, {0});
circ.add_barrier({0, 1}, {}, "comment");
circ.add_op<unsigned>(OpType::CX, {0, 1});
Circuit correct_transposed(2);
correct_transposed.add_op<unsigned>(OpType::CX, {0, 1});
correct_transposed.add_barrier({0, 1}, {}, "comment");
correct_transposed.add_op<unsigned>(OpType::U3, {3, 0.5, 0.5}, {0});
Circuit transposed = circ.transpose();
REQUIRE(transposed == correct_transposed);
transposed.assert_valid();
}
}

SCENARIO("Test circuit.dagger() method") {
Expand Down Expand Up @@ -1535,6 +1548,19 @@ SCENARIO("Test circuit.dagger() method") {
const Eigen::MatrixXcd udag = tket_sim::get_unitary(daggered);
REQUIRE(u.adjoint().isApprox(udag, ERR_EPS));
}
GIVEN("Circuit with barriers") {
Circuit circ(2);
circ.add_op<unsigned>(OpType::Sdg, {0});
circ.add_barrier({0, 1}, {}, "comment");
circ.add_op<unsigned>(OpType::CX, {0, 1});
Circuit correct_daggered(2);
correct_daggered.add_op<unsigned>(OpType::CX, {0, 1});
correct_daggered.add_barrier({0, 1}, {}, "comment");
correct_daggered.add_op<unsigned>(OpType::S, {0});
Circuit daggered = circ.dagger();
REQUIRE(daggered == correct_daggered);
daggered.assert_valid();
}
}

SCENARIO("Test conditional_circuit method") {
Expand Down
Loading