Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initialization of subcircuit in GuidedPauliSimp implementation #1607

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def requirements(self):
self.requires("pybind11_json/0.2.14")
self.requires("symengine/0.12.0")
self.requires("tkassert/0.3.4@tket/stable")
self.requires("tket/1.3.31@tket/stable")
self.requires("tket/1.3.32@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tktokenswap/0.3.9@tket/stable")
Expand Down
7 changes: 7 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

Unreleased
----------

Fixes:

* Fix `GuidedPauliSimp` for circuits containing `CircBox` with classical wires.

1.33.0 (October 2024)
---------------------

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.3.31"
version = "1.3.32"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
9 changes: 8 additions & 1 deletion tket/src/Transformations/PauliOptimisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "tket/Circuit/CircUtils.hpp"
#include "tket/Converters/Converters.hpp"
#include "tket/OpType/EdgeType.hpp"
#include "tket/OpType/OpType.hpp"
#include "tket/OpType/OpTypeInfo.hpp"
#include "tket/PauliGraph/PauliGraph.hpp"
Expand Down Expand Up @@ -238,7 +239,13 @@ Transform special_UCC_synthesis(PauliSynthStrat strat, CXConfigType cx_config) {
Circuit inner_circ = *(box_ptr->to_circuit());
synther.apply(inner_circ);
decomp_boxes().apply(inner_circ);
Subcircuit sub = {circ.get_in_edges(v), circ.get_all_out_edges(v), {v}};
Subcircuit sub = {
circ.get_in_edges_of_type(v, EdgeType::Quantum),
circ.get_out_edges_of_type(v, EdgeType::Quantum),
circ.get_in_edges_of_type(v, EdgeType::Classical),
circ.get_out_edges_of_type(v, EdgeType::Classical),
circ.get_in_edges_of_type(v, EdgeType::Boolean),
{v}};
circ.substitute(inner_circ, sub);
}
return !circbox_verts
Expand Down
9 changes: 9 additions & 0 deletions tket/test/src/test_PauliGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "tket/PauliGraph/PauliGraph.hpp"
#include "tket/Transformations/PauliOptimisation.hpp"
#include "tket/Transformations/Rebase.hpp"
#include "tket/Utils/UnitID.hpp"

namespace tket {
namespace test_PauliGraph {
Expand Down Expand Up @@ -693,6 +694,14 @@ SCENARIO("Test mutual diagonalisation of fully commuting sets") {
test2.symbol_substitution(symbol_map);
REQUIRE(test_statevector_comparison(test1, test2));
}
GIVEN("A circuit with a classical bit") {
// https://github.com/CQCL/tket/issues/1578
Circuit c0(0, 1);
CircBox cbox(c0);
Circuit c(0, 1);
c.add_box<CircBox, Bit>(cbox, {Bit("c", 0)});
REQUIRE_NOTHROW(Transforms::special_UCC_synthesis().apply(c));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know GuidedPauliSimp could handle classically controlled CircBox. Is this fix just to make sure that the method doesn't complain that there are classically controlled CircBox that it won't optimise anyway (in which case I think this test is fine), or is it also decomposing them (in which case maybe we need the CircBox to include something that gets optimised)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case there's no classical control, it's just a classical wire being passed through the CircBox. Previously this caused an error because the Subcircuit constructor was assuming all wires were quantum.

}
GIVEN(
"Clifford merges requires removing from start line without segfault "
"(Grover circuit)") {
Expand Down
Loading