Skip to content

Commit

Permalink
[bugfix] Check for isolated nodes in `ConnectivityPredicate::implies(…
Browse files Browse the repository at this point in the history
…)` (#286)
  • Loading branch information
cqc-alec authored Mar 11, 2022
1 parent 92fc286 commit c9b726b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Minor new features:
architecture constraints.
* ``CircuitStatus`` has several new optional properties such as time-stamps associated with status changes,
queue position or detailed error information.

Fixes:

* ``ConnectivityPredicate.implies()`` checks for existence of isolated nodes as
well as edges in second architecture.

0.19.2 (February 2022)
----------------------
Expand Down
7 changes: 7 additions & 0 deletions tket/src/Predicates/Predicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Gate/Gate.hpp"
#include "Mapping/Verification.hpp"
#include "Placement/Placement.hpp"
#include "Utils/UnitID.hpp"

namespace tket {

Expand Down Expand Up @@ -332,6 +333,12 @@ bool ConnectivityPredicate::implies(const Predicate& other) const {
dynamic_cast<const ConnectivityPredicate&>(other);
const Architecture& arc1 = arch_;
const Architecture& arc2 = other_c.arch_;
// Check that all nodes in arc1 are in arc2:
for (const Node& n : arc1.get_all_nodes_vec()) {
if (!arc2.node_exists(n)) {
return false;
}
}
// Collect all edges in arc1
for (auto [n1, n2] : arc1.get_all_edges_vec()) {
if (!arc2.edge_exists(n1, n2) && !arc2.edge_exists(n2, n1)) {
Expand Down
11 changes: 11 additions & 0 deletions tket/tests/test_Predicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <catch2/catch.hpp>
#include <memory>

#include "Placement/Placement.hpp"
#include "Predicates/CompilationUnit.hpp"
Expand Down Expand Up @@ -186,10 +187,14 @@ SCENARIO("Test routing-related predicates' meet and implication") {
Node n0("test", 0);
Node n1("test", 1);
Node n2("test", 2);
Node n3("test", 3);
Architecture arc1({{n0, n1}, {n1, n2}});
Architecture arc2({{n0, n1}, {n1, n2}, {n0, n2}});
Architecture arc3({{n0, n2}, {n0, n1}});
Architecture arc4({{n2, n0}, {n0, n1}});
Architecture arc5({n0, n1, n2, n3});
arc5.add_connection(n0, n1);
arc5.add_connection(n1, n2);

Circuit circ(3);
circ.add_op<unsigned>(OpType::CX, {0, 1});
Expand All @@ -205,11 +210,17 @@ SCENARIO("Test routing-related predicates' meet and implication") {
PredicatePtr con2 = std::make_shared<ConnectivityPredicate>(arc2);
PredicatePtr con3 = std::make_shared<ConnectivityPredicate>(arc3);
PredicatePtr con4 = std::make_shared<ConnectivityPredicate>(arc4);
PredicatePtr con5 = std::make_shared<ConnectivityPredicate>(arc5);
WHEN("Test implies") {
REQUIRE(con1->implies(*con2));
REQUIRE(con4->implies(*con3)); // directedness doesn't matter
REQUIRE_FALSE(con1->implies(*con3));
}
WHEN("Test implies (isolated nodes)") {
// https://github.com/CQCL/tket/issues/88
REQUIRE(con1->implies(*con5));
REQUIRE_FALSE(con5->implies(*con1));
}
WHEN("Test meet") {
PredicatePtr meet_a = con1->meet(*con2);
REQUIRE(meet_a->verify(circ));
Expand Down

0 comments on commit c9b726b

Please sign in to comment.