Skip to content

Commit

Permalink
Bugfix/symbol sub doesn't preserve opgroup (#1632)
Browse files Browse the repository at this point in the history
* Add failing test

* Preserve opgroups when sub symbols

* bump tket version

* Add entry to changelog

* bump tket version

* Drop support for MacOS 12 (#1634)

* Updated nixpkgs. Added custom mypy build. (#1636)

* Updated nixpkgs. Added custom mypy build (required version isn't in nixpkgs)

* Used overrideAttrs on nixpkgs' mypy rather than a new derivation as per @johnchildren's suggestion

* Refactor greedy pauli simp (#1611)

* Initial refactor

* Refactor node types

* Move nodes definition into a new file

* Refactor synthesis

* Cleanup

* More refactoring

* Refactor pauli graph converters

* Initial implementation of GPGraph

* Migrate to GPGraph

* Ignore global phase

* Add supports for conditional gates

* Add support for classical ops

* flatten_registers should only rename qubits and bits

* Replace unsigned with Bit

* Revert "Replace unsigned with Bit"

This reverts commit 9e9a2fd.

* Manually check if qubits and bits can be flattened since ``is_simple()`` doesn't work with wasm

* Consistent enum names

* Add support for mid-circuit measurement

* Rename variables

* Add support for resets

* Update docstrings

* Update pass predicate

* Add more tests

* bump tket version

* Add changelog entry

* Fix docs errors

* bump tket version

* Remove unused headers

* bump tket version in pytket

* uncomment lines

* remove consts in SQ_CLIFF_DAGGER

* Merging conditionals

* Revert "Merging conditionals"

This reverts commit f5138f1.

* Optimise conditional handling

* remove ConditionalPauliRotation

* Remove clifford reduction and pass parameters when synthesis conditionals

* Seeded tie breaking

* Add limits to the search space

* Allowing ZZPhase gates

* update binder and serialisation

* Add test for ops handling in python

* add note for AC node cost

* bump tket version

* update changelog

* fix changelog format

* add missing prams in docstrings

* cast size_t to unsigned

* remove nondeterminism from test

* Remove more nondeterminism

* regen stubs

* Add debug info

* Revert "Add debug info"

This reverts commit e5030e2.

* Replace implicit wire swaps in optimised conditional circuits

* re-organise changelog

* Bump tket version

* fix bug in sign correction

* Add more tests

* Bump version and update changelog for 1.34.0 release (#1637)

* Update README.md (#1625)

* nump tket version

* update changelog

* bump tket version

* Update changelog

---------

Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Jake Arkinstall <[email protected]>
Co-authored-by: Callum Macpherson <[email protected]>
  • Loading branch information
4 people authored Oct 28, 2024
1 parent 83c0099 commit 510d4a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
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.35@tket/stable")
self.requires("tket/1.3.36@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 `symbol_substitution` not preserving opgroups.

1.34.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.35"
version = "1.3.36"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
2 changes: 1 addition & 1 deletion tket/src/Circuit/Circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void Circuit::symbol_substitution(const SymEngine::map_basic_basic sub_map) {
BGL_FORALL_VERTICES(v, dag, DAG) {
Op_ptr new_op = get_Op_ptr_from_Vertex(v)->symbol_substitution(sub_map);
if (new_op) {
dag[v] = {new_op};
dag[v] = {new_op, dag[v].opgroup};
}
}
phase = phase.subs(sub_map);
Expand Down
31 changes: 31 additions & 0 deletions tket/test/src/Circuit/test_Circ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../testutil.hpp"
#include "tket/Circuit/Circuit.hpp"
#include "tket/Circuit/DAGDefs.hpp"
#include "tket/Circuit/PauliExpBoxes.hpp"
#include "tket/Circuit/Simulation/CircuitSimulator.hpp"
#include "tket/Gate/GatePtr.hpp"
#include "tket/Gate/OpPtrFunctions.hpp"
Expand Down Expand Up @@ -1292,6 +1293,36 @@ SCENARIO("Functions with symbolic ops") {
REQUIRE(test_equiv_val(op2->get_params()[0], 0.2));
REQUIRE(op3->get_type() == OpType::Barrier);
}
GIVEN("A circuit with symbolic gates and boxes that belong to opgroups.") {
Sym asym = SymEngine::symbol("a");
Expr alpha(asym);
Sym bsym = SymEngine::symbol("b");
Expr beta(bsym);
Circuit circ(2);
circ.add_op<unsigned>(OpType::Rx, alpha, {0}, "Rx");
Circuit inner_circ(2);
inner_circ.add_op<unsigned>(OpType::Rx, {alpha}, {0});
inner_circ.add_op<unsigned>(OpType::Ry, {beta}, {0});
auto cbox = CircBox(inner_circ);
circ.add_box(cbox, {0, 1}, "cbox");
DensePauliMap paulis0{Pauli::X, Pauli::X};
DensePauliMap paulis1{Pauli::Z, Pauli::X};
auto ppbox = PauliExpPairBox(
SymPauliTensor(paulis0, alpha), SymPauliTensor(paulis1, beta));
circ.add_box(ppbox, {0, 1}, "ppbox");
symbol_map_t symbol_map;
symbol_map[asym] = Expr(0.2);
symbol_map[bsym] = Expr(0.3);
circ.symbol_substitution(symbol_map);
REQUIRE(!circ.is_symbolic());
std::unordered_set<std::string> opgroups({"Rx", "cbox", "ppbox"});
REQUIRE(circ.get_opgroups() == opgroups);
std::vector<Command> cmds = circ.get_commands();
REQUIRE(cmds.size() == 3);
REQUIRE(cmds[0].get_opgroup().value() == "Rx");
REQUIRE(cmds[1].get_opgroup().value() == "cbox");
REQUIRE(cmds[2].get_opgroup().value() == "ppbox");
}
}

SCENARIO("Test depth_by_type method") {
Expand Down

0 comments on commit 510d4a8

Please sign in to comment.