Skip to content

Commit

Permalink
Ensure CXMappingPass works on circuits containing barriers or wire …
Browse files Browse the repository at this point in the history
…swaps (#1598)
  • Loading branch information
cqc-alec authored Sep 30, 2024
1 parent 953d3a8 commit f1c1cf2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def requirements(self):
self.requires("pybind11_json/0.2.14")
self.requires("symengine/0.12.0")
self.requires("tkassert/0.3.4@tket/stable")
self.requires("tket/1.3.29@tket/stable")
self.requires("tket/1.3.30@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tktokenswap/0.3.9@tket/stable")
Expand Down
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixes:

* Fix QASM conversion of non-register-aligned `MultiBitOp`.
* Fix `DecomposeClassicalExp()` when target occurs in expression.
* Allow barriers and wire swaps in `DecomposeSwapsToCXs()`.

1.32.0 (September 2024)
-----------------------
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.3.29"
version = "1.3.30"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
3 changes: 1 addition & 2 deletions tket/src/Predicates/PassGenerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,14 @@ PassPtr gen_decompose_routing_gates_to_cxs_pass(
OpTypeSet in_optypes = out_optypes;
in_optypes.insert(OpType::SWAP);
in_optypes.insert(OpType::BRIDGE);
in_optypes.insert(OpType::Barrier);
PredicatePtr twoqbpred = std::make_shared<MaxTwoQubitGatesPredicate>();
PredicatePtr connected = std::make_shared<ConnectivityPredicate>(arc);
PredicatePtr wireswaps = std::make_shared<NoWireSwapsPredicate>();
PredicatePtr directedpred = std::make_shared<DirectednessPredicate>(arc);
PredicatePtr ingates = std::make_shared<GateSetPredicate>(in_optypes);
PredicatePtr outgates = std::make_shared<GateSetPredicate>(out_optypes);
precons = {
CompilationUnit::make_type_pair(connected),
CompilationUnit::make_type_pair(wireswaps),
CompilationUnit::make_type_pair(ingates)};
s_postcons = {
CompilationUnit::make_type_pair(directedpred),
Expand Down
22 changes: 22 additions & 0 deletions tket/test/src/test_CompilerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,28 @@ SCENARIO("CX mapping pass") {
REQUIRE_THROWS_AS(pass->apply(cu), UnsatisfiedPredicate);
}
}
GIVEN("CXMappingPass preconditions") {
// https://github.com/CQCL/tket/issues/1597
// Construct a circuit with a barrier and an implicit wire swap; check that
// we can apply CXMappingPass.
Circuit c(2, 2);
c.add_op<unsigned>(OpType::CX, {0, 1});
c.add_op<unsigned>(OpType::CX, {1, 0});
c.add_barrier({0, 1});
c.add_op<unsigned>(OpType::CX, {0, 1});
c.add_measure(0, 0);
c.add_measure(1, 1);
Transforms::clifford_simp().apply(c);
CHECK(c.has_implicit_wireswaps());
std::vector<std::pair<unsigned, unsigned>> edges = {{0, 1}};
Architecture arc(edges);
Placement::Ptr plptr = std::make_shared<Placement>(arc);
std::vector<RoutingMethodPtr> config = {
std::make_shared<LexiRouteRoutingMethod>()};
PassPtr p = gen_cx_mapping_pass(arc, plptr, config, true, false);
CompilationUnit cu(c);
REQUIRE_NOTHROW(p->apply(cu));
}
}

SCENARIO("ThreeQubitSquah") {
Expand Down

0 comments on commit f1c1cf2

Please sign in to comment.