Skip to content

Commit b82e71e

Browse files
authored
Use correct port when rewiring in DelayMeasures pass (#2230)
1 parent b4fddf8 commit b82e71e

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎TKET_VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.97
1+
2.1.98

‎pytket/docs/changelog.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
Fixes:
6+
- Fix bug in `DelayMeasures` when multi-qubit gate follows final measurement.
7+
38
## 2.18.1 (July 2026)
49

510
## 2.18.0 (May 2026)

‎tket/src/Transformations/MeasurePass.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ std::pair<bool, bool> run_delay_measures(
257257
Vertex v = p.first;
258258
Edge current_edge = p.second;
259259
Vertex current_vertex = circ.target(current_edge);
260+
port_t current_port = circ.get_target_port(current_edge);
260261

261262
Edge in_edge = circ.get_nth_in_edge(v, 0);
262263
Edge out_edge = circ.get_nth_out_edge(v, 0);
@@ -270,7 +271,7 @@ std::pair<bool, bool> run_delay_measures(
270271
circ.add_edge(
271272
{circ.source(current_edge), circ.get_source_port(current_edge)}, {v, 0},
272273
EdgeType::Quantum);
273-
circ.add_edge({v, 0}, {current_vertex, 0}, EdgeType::Quantum);
274+
circ.add_edge({v, 0}, {current_vertex, current_port}, EdgeType::Quantum);
274275
circ.remove_edge(current_edge);
275276
}
276277
return {true, true};

‎tket/test/src/test_CompilerPass.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,16 @@ SCENARIO("Commute measurements to the end of a circuit") {
14761476
CompilationUnit cu(c);
14771477
CHECK_FALSE(try_delay_pass->apply(cu));
14781478
}
1479+
GIVEN("Reuse of measured qubit") {
1480+
// https://github.com/Quantinuum/tket/issues/2229
1481+
Circuit c(2, 1);
1482+
c.add_measure(0, 0);
1483+
c.add_op<unsigned>(OpType::T, {0});
1484+
c.add_op<unsigned>(OpType::CX, {1, 0});
1485+
CompilationUnit cu(c);
1486+
REQUIRE(try_delay_pass->apply(cu));
1487+
Circuit c1 = cu.get_circ_ref();
1488+
}
14791489
}
14801490

14811491
SCENARIO("RemoveRedundancies and phase") {

0 commit comments

Comments
 (0)