Skip to content

Commit

Permalink
Merge branch 'develop' into allow-swap-in-auto-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdilkes committed Aug 1, 2023
2 parents a315e95 + 9eb7c06 commit 9a65b83
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 5 deletions.
14 changes: 14 additions & 0 deletions pytket/binders/circuit/Circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,20 @@ void init_circuit(py::module &m) {
"\n:return: the circuit depth with respect to operations matching an "
"element of `types`",
py::arg("types"))
.def(
"depth_2q", &Circuit::depth_2q,
"Returns the number of vertices in the longest path through the "
"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_2q()"
"\n3"
"\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",
Expand Down
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.29@tket/stable")
self.requires("tket/1.2.31@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.3@tket/stable")
Expand Down
12 changes: 12 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

Unreleased
----------

Minor new features:

* Add circuit method ``depth_2q``.

Fixes:

* Fix slow ``Circuit.get_statevector()``.


1.17.1 (July 2023)
------------------

Expand Down
7 changes: 5 additions & 2 deletions pytket/docs/opensource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ Symengine
---------

© 2013-2017 SymEngine Development Team

Licence: https://github.com/symengine/symengine/blob/master/LICENSE
Package and documentation: https://github.com/symengine/symengine

Package and documentation: https://github.com/symengine/symengine

Eigen
-----

Licence: https://www.mozilla.org/en-US/MPL/2.0/
Package and documentation: https://bitbucket.org/eigen/eigen

Package and documentation: https://eigen.tuxfamily.org/
1 change: 1 addition & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +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_2q() == 6


def test_op_dagger_transpose() -> None:
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.2.29"
version = "1.2.31"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
11 changes: 11 additions & 0 deletions tket/include/tket/Circuit/Circuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,17 @@ class Circuit {
*/
unsigned depth_by_types(const OpTypeSet &_types) const;

/**
* 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 with 2 quantum wires,
* excluding vertices representing barrier operations.
*
* @return depth
*/
unsigned depth_2q() const;

std::map<Vertex, unit_set_t> vertex_unit_map() const;
std::map<Vertex, unsigned> vertex_depth_map() const;
std::map<Vertex, unsigned> vertex_rev_depth_map() const;
Expand Down
2 changes: 1 addition & 1 deletion tket/src/Circuit/Simulation/DecomposeCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static QMap get_qmap_no_checks(
static bool fill_triplets_directly_from_box(
GateNode& node, const std::shared_ptr<const Box>& box_ptr,
double abs_epsilon) {
std::optional<Eigen::MatrixXcd> u = box_ptr->get_unitary();
std::optional<Eigen::MatrixXcd> u = box_ptr->get_box_unitary();
if (!u.has_value()) {
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions tket/src/Circuit/macro_circ_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,21 @@ unsigned Circuit::depth_by_types(const OpTypeSet& _types) const {
return count;
}

unsigned Circuit::depth_2q() const {
unsigned count = 0;
std::function<bool(Op_ptr)> skip_func = [&](Op_ptr op) {
return (op->n_qubits() != 2 || op->get_type() == OpType::Barrier);
};
Circuit::SliceIterator slice_iter(*this, skip_func);
if (!(*slice_iter).empty()) count++;
while (!slice_iter.finished()) {
slice_iter.cut_ = this->next_cut(
slice_iter.cut_.u_frontier, slice_iter.cut_.b_frontier, skip_func);
if (!(*slice_iter).empty()) count++;
}
return count;
}

std::map<Vertex, unit_set_t> Circuit::vertex_unit_map() const {
std::map<Vertex, unit_set_t> map;
BGL_FORALL_VERTICES(v, dag, DAG) { map[v] = {}; }
Expand Down
35 changes: 35 additions & 0 deletions tket/test/src/Circuit/test_Circ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,41 @@ SCENARIO("Test depth_by_type method") {
REQUIRE(circ.depth_by_types({OpType::CX, OpType::CY}) == 2);
}
}
SCENARIO("Test depth_2q method") {
GIVEN("2q OpTypes") {
Circuit circ(3, 1);
circ.add_op<unsigned>(OpType::CX, {0, 1});
circ.add_op<unsigned>(OpType::Z, {0});
circ.add_op<unsigned>(OpType::Z, {1});
circ.add_op<unsigned>(OpType::CZ, {1, 0});
circ.add_conditional_gate<unsigned>(OpType::CY, {}, {1, 2}, {0}, 0);
REQUIRE(circ.depth_2q() == 3);
}
GIVEN("Boxes") {
Circuit circ(3);
Circuit inner(2);
inner.add_op<unsigned>(OpType::CX, {0, 1});
CircBox cbox(inner);
circ.add_box(cbox, {0, 1});
circ.add_op<unsigned>(OpType::Z, {1});
REQUIRE(circ.depth_2q() == 1);
}
GIVEN("Multi-q gates") {
Circuit circ(5, 2);
circ.add_op<unsigned>(OpType::CnX, {0, 1, 2, 4, 3});
circ.add_op<unsigned>(OpType::CnX, {0, 2});
circ.add_op<unsigned>(OpType::CnX, {2, 4, 3});
circ.add_op<unsigned>(OpType::CnX, {3, 4});
REQUIRE(circ.depth_2q() == 2);
}
GIVEN("A circuit with other causal links") {
Circuit circ(4);
circ.add_op<unsigned>(OpType::CX, {0, 1});
circ.add_barrier({0, 2});
circ.add_op<unsigned>(OpType::CZ, {2, 3});
REQUIRE(circ.depth_2q() == 2);
}
}

SCENARIO("Test extracting slice segments") {
GIVEN("A simple circuit") {
Expand Down

0 comments on commit 9a65b83

Please sign in to comment.