Skip to content

Commit

Permalink
Update MultiplexedTensoredU2Box Circuit Construction (#1443)
Browse files Browse the repository at this point in the history
* First changes, compiling but returning incorrect results

* MultiplexedU2Box construction working

* hmm

* refactor to separate

* Update Multiplexor.cpp

* Working on specific cases

* Update test_Multiplexor.cpp

* Update test_Multiplexor.cpp

* working on most cases ...

* Refactor into separate methods

* refactor again and neaten code up

* Tidied, failling test for mystery reasons, moving on ...

* Multiplexed-rz with interleaved gates

* Tidy for PR

* bump

* Update Multiplexor.hpp

* Update Multiplexor.hpp

* Update test_Multiplexor.cpp

* Update Multiplexor.cpp

* attempt to remove mismatch ??

* Update Multiplexor.cpp

* Update Multiplexor.cpp

* fix

* changes

* update rz rotation indexing

* add asserts

* update error threshold

* add multiple constructors

* bump

* Update changelog.rst
  • Loading branch information
sjdilkes authored Jun 17, 2024
1 parent 7d4c055 commit 8f10936
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 128 deletions.
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.3.7@tket/stable")
self.requires("tket/1.3.8@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.4@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
----------

Features:

* Improve depth of circuit produced by ``MultiplexedTensoredU2Box``.

1.29.0 (June 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.7"
version = "1.3.8"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
38 changes: 35 additions & 3 deletions tket/include/tket/Circuit/Multiplexor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ class MultiplexorBox : public Box {
ctrl_op_map_t op_map_;
};

struct GateSpec {
// TODO: this struct is a little confused as only CX needs qubit, only
// Unitary1QBox needs matrix and only Rotation gates need angle. ... should
// probably make them optional ...
OpType type;
std::optional<unsigned> qubit;
std::optional<Eigen::Matrix2cd> matrix;
std::optional<Expr> angle;

GateSpec(const OpType &type_, unsigned qubit_) : type(type_), qubit(qubit_) {}

GateSpec(const OpType &type_, const Eigen::Matrix2cd &matrix_)
: type(type_), matrix(matrix_) {}

GateSpec(const OpType &type_, const Expr &angle_)
: type(type_), angle(angle_) {}
};

/**
* Multiplexed single-axis rotations
*/
Expand Down Expand Up @@ -139,6 +157,8 @@ class MultiplexedRotationBox : public Box {

static nlohmann::json to_json(const Op_ptr &op);

std::vector<GateSpec> decompose() const;

protected:
/**
* @brief Implement multiplexed rotation
Expand All @@ -156,6 +176,17 @@ class MultiplexedRotationBox : public Box {
OpType axis_;
};

struct MultiplexedU2Commands {
std::vector<GateSpec> commands;
Eigen::VectorXcd diag;
float phase;

MultiplexedU2Commands(
const std::vector<GateSpec> &commands_, const Eigen::VectorXcd &diag_,
float phase_)
: commands(commands_), diag(diag_), phase(phase_) {}
};

/**
* Multiplexed U2 gate
*/
Expand Down Expand Up @@ -205,11 +236,12 @@ class MultiplexedU2Box : public Box {

/**
* @brief Decompose the multiplexor into a sequence of interleaving CX and
* single qubit gates followed by a diagonal matrix
* single qubit gates followed by a diagonal matrix, given as command
* descriptions and a diagonal vector
*
* @return std::pair<Circuit, Eigen::VectorXcd>
* @return MultiplexedU2Commands
*/
std::pair<Circuit, Eigen::VectorXcd> decompose() const;
MultiplexedU2Commands decompose() const;

protected:
/**
Expand Down
Loading

0 comments on commit 8f10936

Please sign in to comment.