Skip to content

Commit 8c005af

Browse files
authored
Handle 0-qubit gates when computing resource data (#2068)
1 parent bccd21a commit 8c005af

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎TKET_VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.61
1+
2.1.62

‎pytket/docs/changelog.md‎

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

3+
## Unreleased
4+
5+
- Fix segfault from `Circuit::get_resources()` with 0-qubit gates.
6+
37
## 2.10.3 (October 2025)
48

59
- Add `tket_squash_phasedx_rz` to c api.

‎tket/src/Circuit/Circuit.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,11 @@ ResourceData Circuit::get_resources() /*const*/ {
406406
op_type_count[pair.first].max += pair.second.max;
407407
}
408408
} else {
409+
unsigned n_qubits = get_Op_ptr_from_Vertex(v)->n_qubits();
410+
if (n_qubits == 0) continue;
409411
data.GateDepth = {1};
410412
data.OpTypeDepth[optype] = {1};
411-
if (OpDesc(optype).is_gate() &&
412-
get_Op_ptr_from_Vertex(v)->n_qubits() == 2) {
413+
if (OpDesc(optype).is_gate() && n_qubits == 2) {
413414
data.TwoQubitGateDepth = {1};
414415
}
415416
op_type_count[optype].min += 1;

‎tket/test/src/Circuit/test_DummyBox.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include <catch2/catch_test_macros.hpp>
16+
#include <tket/OpType/OpType.hpp>
1617

1718
#include "tket/Circuit/Circuit.hpp"
1819
#include "tket/Circuit/DummyBox.hpp"
@@ -50,6 +51,15 @@ SCENARIO("DummyBox") {
5051
ResourceBounds<unsigned>(5, 9)};
5152
CHECK(data == expected);
5253
}
54+
55+
GIVEN("Phase op") {
56+
// https://github.com/CQCL/tket/issues/2066
57+
Circuit c(1);
58+
c.add_op<unsigned>(OpType::Phase, 0.0, {});
59+
ResourceData data = c.get_resources();
60+
ResourceData expected{};
61+
CHECK(data == expected);
62+
}
5363
}
5464

5565
} // namespace tket

0 commit comments

Comments
 (0)