diff --git a/pytket/binders/circuit/Circuit/main.cpp b/pytket/binders/circuit/Circuit/main.cpp index dd02ffb5fc..dbd69b9c67 100644 --- a/pytket/binders/circuit/Circuit/main.cpp +++ b/pytket/binders/circuit/Circuit/main.cpp @@ -544,19 +544,19 @@ void init_circuit(py::module &m) { "element of `types`", py::arg("types")) .def( - "depth_by_2q_gates", &Circuit::depth_by_2q_gates, + "depth_2q", &Circuit::depth_2q, "Returns the number of vertices in the longest path through the " - "sub-DAG consisting of vertices representing 2-qubit quantum gates." - "Note that box types and conditionals are not included." + "sub-DAG consisting of vertices with 2 quantum wires," + "excluding vertices representing barrier operations." "\n\n>>> c = Circuit(3)" "\n>>> c.CZ(0,1)" "\n>>> c.Z(0)" "\n>>> c.Z(1)" "\n>>> c.ZZMax(1,2)" "\n>>> c.CX(1,2)" - "\n>>> c.depth_by_2q_gates()" + "\n>>> c.depth_2q()" "\n3" - "\n:return: the circuit depth with respect to 2-qubit quantum gates.") + "\n:return: the circuit depth with respect to 2-qubit operations.") .def( "_to_graphviz_file", &Circuit::to_graphviz_file, "Saves a visualisation of a circuit's DAG to a \".dot\" file", diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 300b31aab0..eb37244764 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -6,7 +6,7 @@ Unreleased Minor new features: -* Add circuit method ``depth_by_2q_gates`` +* Add circuit method ``depth_2q`` 1.17.1 (July 2023) diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index f4aea8a943..c0ef2434ec 100644 --- a/pytket/tests/circuit_test.py +++ b/pytket/tests/circuit_test.py @@ -1024,7 +1024,7 @@ def test_depth() -> None: assert c.depth_by_type({OpType.CX, OpType.H}) == 6 assert c.depth_by_type({OpType.CZ, OpType.H}) == 6 assert c.depth_by_type(set()) == 0 - assert c.depth_by_2q_gates() == 6 + assert c.depth_2q_gates() == 6 def test_op_dagger_transpose() -> None: diff --git a/tket/include/tket/Circuit/Circuit.hpp b/tket/include/tket/Circuit/Circuit.hpp index 3f70ae38eb..95fcf6822d 100644 --- a/tket/include/tket/Circuit/Circuit.hpp +++ b/tket/include/tket/Circuit/Circuit.hpp @@ -1185,14 +1185,15 @@ class Circuit { unsigned depth_by_types(const OpTypeSet &_types) const; /** - * Depth of circuit restricting to 2-qubit quantum gates. + * Depth of circuit restricting to 2-qubit operations, excluding barriers. * - * This is the number of vertices in the longest path through the sub-DAG - * consisting of vertices representing 2-qubit operations. + * This is the number of vertices in the longest path through the + * sub-DAG consisting of vertices with 2 quantum wires, + * excluding vertices representing barrier operations. * * @return depth */ - unsigned depth_by_2q_gates() const; + unsigned depth_2q() const; std::map vertex_unit_map() const; std::map vertex_depth_map() const; diff --git a/tket/src/Circuit/macro_circ_info.cpp b/tket/src/Circuit/macro_circ_info.cpp index d01e193816..9ff07c7c94 100644 --- a/tket/src/Circuit/macro_circ_info.cpp +++ b/tket/src/Circuit/macro_circ_info.cpp @@ -708,10 +708,10 @@ unsigned Circuit::depth_by_types(const OpTypeSet& _types) const { return count; } -unsigned Circuit::depth_by_2q_gates() const { +unsigned Circuit::depth_2q() const { unsigned count = 0; std::function skip_func = [&](Op_ptr op) { - return (op->n_qubits() != 2 || !is_gate_type(op->get_type())); + return (op->n_qubits() != 2 || op->get_type() == OpType::Barrier); }; Circuit::SliceIterator slice_iter(*this, skip_func); if (!(*slice_iter).empty()) count++; diff --git a/tket/test/src/Circuit/test_Circ.cpp b/tket/test/src/Circuit/test_Circ.cpp index d8cf17857a..04065ed0bc 100644 --- a/tket/test/src/Circuit/test_Circ.cpp +++ b/tket/test/src/Circuit/test_Circ.cpp @@ -1326,7 +1326,7 @@ SCENARIO("Test depth_by_type method") { REQUIRE(circ.depth_by_types({OpType::CX, OpType::CY}) == 2); } } -SCENARIO("Test depth_by_2q_gates method") { +SCENARIO("Test depth_2q_gates method") { GIVEN("2q OpTypes") { Circuit circ(3, 1); circ.add_op(OpType::CX, {0, 1}); @@ -1334,7 +1334,7 @@ SCENARIO("Test depth_by_2q_gates method") { circ.add_op(OpType::Z, {1}); circ.add_op(OpType::CZ, {1, 0}); circ.add_conditional_gate(OpType::CY, {}, {1, 2}, {0}, 0); - REQUIRE(circ.depth_by_2q_gates() == 2); + REQUIRE(circ.depth_2q() == 3); } GIVEN("Boxes") { Circuit circ(3); @@ -1343,7 +1343,7 @@ SCENARIO("Test depth_by_2q_gates method") { CircBox cbox(inner); circ.add_box(cbox, {0, 1}); circ.add_op(OpType::Z, {1}); - REQUIRE(circ.depth_by_2q_gates() == 0); + REQUIRE(circ.depth_2q() == 1); } GIVEN("Multi-q gates") { Circuit circ(5, 2); @@ -1351,14 +1351,14 @@ SCENARIO("Test depth_by_2q_gates method") { circ.add_op(OpType::CnX, {0, 2}); circ.add_op(OpType::CnX, {2, 4, 3}); circ.add_op(OpType::CnX, {3, 4}); - REQUIRE(circ.depth_by_2q_gates() == 2); + REQUIRE(circ.depth_2q() == 2); } GIVEN("A circuit with other causal links") { Circuit circ(4); circ.add_op(OpType::CX, {0, 1}); circ.add_barrier({0, 2}); circ.add_op(OpType::CZ, {2, 3}); - REQUIRE(circ.depth_by_2q_gates() == 2); + REQUIRE(circ.depth_2q() == 2); } }