Skip to content

Commit

Permalink
Bugfix/incorrect serialisation for list of pairs (#1099)
Browse files Browse the repository at this point in the history
* Add failling test

* Fix PauliExpPairBox serialisation issue

* Update changelog

* bump tket version
  • Loading branch information
yao-cqc authored Oct 27, 2023
1 parent 631a688 commit 054a624
Show file tree
Hide file tree
Showing 5 changed files with 21 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 @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.61@tket/stable")
self.requires("tket/1.2.62@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
2 changes: 2 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Fixes:

* When converting QASM expressions to ``ClassicalExpBox``, preserve the ordering
of the bits in the expression in the resulting ``cmd.args``
* Fix incorrect serialisation of ``PauliExpPairBox`` when the Pauli strings are of
length 2.

1.21.0 (October 2023)
---------------------
Expand Down
11 changes: 11 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Bit,
BitRegister,
QubitRegister,
CXConfigType,
)
from pytket.circuit.display import get_circuit_renderer, render_circuit_as_html
from pytket.circuit.named_types import (
Expand Down Expand Up @@ -674,6 +675,15 @@ def test_boxes() -> None:
command.op.get_unitary()


def test_pauliexp_pair_box_serialisation() -> None:
# https://github.com/CQCL/tket/issues/1084
p = PauliExpPairBox(
[Pauli.Z, Pauli.X], 0.5, [Pauli.X, Pauli.Z], 0.2, CXConfigType.MultiQGate
)
c = Circuit(2).add_pauliexppairbox(p, [0, 1])
assert json_validate(c)


def test_tofollibox_strats() -> None:
permutation = [
([_0, _0, _0, _0], [_1, _1, _1, _1]),
Expand Down Expand Up @@ -1261,3 +1271,4 @@ def test_phase_order() -> None:
test_measuring_registers()
test_multi_controlled_gates()
test_counting_n_qubit_gates()
test_pauliexp_pair_box_serialisation()
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.61"
version = "1.2.62"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
7 changes: 6 additions & 1 deletion tket/src/Circuit/PauliExpBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ bool PauliExpPairBox::is_equal(const Op &op_other) const {
nlohmann::json PauliExpPairBox::to_json(const Op_ptr &op) {
const auto &box = static_cast<const PauliExpPairBox &>(*op);
nlohmann::json j = core_box_json(box);
j["paulis_pair"] = box.get_paulis_pair();
auto paulis_pair = box.get_paulis_pair();
// use vector to avoid serialising into a dictionary if the Pauli strings are
// of length 2
std::vector<std::vector<Pauli>> paulis_vec{
paulis_pair.first, paulis_pair.second};
j["paulis_pair"] = paulis_vec;
j["phase_pair"] = box.get_phase_pair();
j["cx_config"] = box.get_cx_config();
return j;
Expand Down

0 comments on commit 054a624

Please sign in to comment.