From 6c4d02271b556f9a9d0facc0389d95e3c4a366f5 Mon Sep 17 00:00:00 2001 From: John Children Date: Tue, 3 Sep 2024 14:27:36 +0100 Subject: [PATCH 01/21] WIP: Allow constant ZZPhase in DecomposeTK2 --- .../include/tket/Transformations/Transform.hpp | 2 +- tket/include/tket/Utils/Expression.hpp | 9 +++++++++ tket/src/Predicates/PassGenerators.cpp | 12 +++++++++++- tket/src/Transformations/Decomposition.cpp | 18 ++++++++++++++++-- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tket/include/tket/Transformations/Transform.hpp b/tket/include/tket/Transformations/Transform.hpp index 6b0a93cb89..5ebfd346f7 100644 --- a/tket/include/tket/Transformations/Transform.hpp +++ b/tket/include/tket/Transformations/Transform.hpp @@ -99,7 +99,7 @@ inline const Transform id = struct TwoQbFidelities { std::optional CX_fidelity; std::optional ZZMax_fidelity; - std::optional> ZZPhase_fidelity; + std::optional>> ZZPhase_fidelity; }; } // namespace Transforms diff --git a/tket/include/tket/Utils/Expression.hpp b/tket/include/tket/Utils/Expression.hpp index a70ca14add..00efb94f85 100644 --- a/tket/include/tket/Utils/Expression.hpp +++ b/tket/include/tket/Utils/Expression.hpp @@ -28,6 +28,15 @@ #include "Json.hpp" #include "Symbols.hpp" +/** Helper struct for use with std::visit */ +template +struct overloaded : Ts... { + using Ts::operator()...; +}; +// explicit deduction guide (not needed as of C++20) +template +overloaded(Ts...) -> overloaded; + namespace tket { /** Representation of a phase as a multiple of \f$ \pi \f$ */ diff --git a/tket/src/Predicates/PassGenerators.cpp b/tket/src/Predicates/PassGenerators.cpp index 0a6c3f316a..7d7ab534a9 100644 --- a/tket/src/Predicates/PassGenerators.cpp +++ b/tket/src/Predicates/PassGenerators.cpp @@ -16,9 +16,12 @@ #include #include +#include #include #include +#include +#include "Utils/Expression.hpp" #include "tket/ArchAwareSynth/SteinerForest.hpp" #include "tket/Circuit/CircPool.hpp" #include "tket/Circuit/Circuit.hpp" @@ -811,7 +814,14 @@ PassPtr DecomposeTK2(const Transforms::TwoQbFidelities& fid, bool allow_swaps) { j["allow_swaps"] = allow_swaps; nlohmann::json fid_json; fid_json["CX"] = fid.CX_fidelity; - fid_json["ZZPhase"] = "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; + std::visit( + overloaded{ + [](std::nullopt_t) { return; }, + [&fid_json](double arg) { fid_json["ZZPhase"] = arg; }, + [&fid_json](std::function) { + fid_json["ZZPhase"] = "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; + }}, + *fid.ZZPhase_fidelity); fid_json["ZZMax"] = fid.ZZMax_fidelity; j["fidelities"] = fid_json; return std::make_shared(precons, t, postcons, j); diff --git a/tket/src/Transformations/Decomposition.cpp b/tket/src/Transformations/Decomposition.cpp index 56b9fe84dc..8e9fca02be 100644 --- a/tket/src/Transformations/Decomposition.cpp +++ b/tket/src/Transformations/Decomposition.cpp @@ -19,6 +19,7 @@ // replace with c++20 when available #include #include +#include #include "tket/Architecture/Architecture.hpp" #include "tket/Circuit/CircPool.hpp" @@ -616,7 +617,14 @@ static double best_noise_aware_decomposition( unsigned max_nzz = fid.ZZMax_fidelity ? 1 : 3; for (unsigned n_zz = 0; n_zz <= max_nzz; ++n_zz) { if (n_zz > 0) { - double gate_fid = (*fid.ZZPhase_fidelity)(angles[n_zz - 1]); + double gate_fid = std::visit( + overloaded{// Constant value + [](double arg) { return arg; }, + // A value depending on the angle + [angles, n_zz](std::function arg) { + return (arg)(angles[n_zz - 1]); + }}, + *fid.ZZPhase_fidelity); if (gate_fid < 0 || gate_fid > 1) { throw std::domain_error( "ZZPhase_fidelity returned a value outside of [0, 1]."); @@ -857,7 +865,13 @@ Transform decompose_TK2(const TwoQbFidelities &fid, bool allow_swaps) { } } if (fid.ZZMax_fidelity && fid.ZZPhase_fidelity) { - if (*fid.ZZMax_fidelity < (*fid.ZZPhase_fidelity)(.5)) { + double ZZPhase_half = std::visit( + overloaded{// Half of the provided Value. + [](double arg) { return arg * .5; }, + // A value depending on the input. + [](std::function arg) { return (arg)(.5); }}, + *fid.ZZPhase_fidelity); + if (*fid.ZZMax_fidelity < ZZPhase_half) { throw std::domain_error( "The ZZMax fidelity cannot be smaller than the ZZPhase(0.5) " "fidelity"); From 2a01d039ca27c170b4f2548abbfde63b4109093e Mon Sep 17 00:00:00 2001 From: John Children Date: Tue, 3 Sep 2024 15:31:41 +0100 Subject: [PATCH 02/21] chore: Clean up some code issues --- pytket/binders/passes.cpp | 2 +- tket/src/Predicates/CompilerPass.cpp | 3 ++- tket/src/Predicates/PassGenerators.cpp | 10 +++++----- tket/test/src/test_json.cpp | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index dfe27683da..5c8c57be94 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -58,7 +58,7 @@ Transforms::TwoQbFidelities get_fidelities(const py::kwargs &kwargs) { } else if (kwargstr == "ZZMax_fidelity") { fid.ZZMax_fidelity = py::cast(kwarg.second); } else if (kwargstr == "ZZPhase_fidelity") { - fid.ZZPhase_fidelity = py::cast(kwarg.second); + fid.ZZPhase_fidelity = py::cast>(kwarg.second); } else { throw py::type_error( "got an unexpected keyword argument '" + kwargstr + "'"); diff --git a/tket/src/Predicates/CompilerPass.cpp b/tket/src/Predicates/CompilerPass.cpp index e9cb2f52ab..9085388759 100644 --- a/tket/src/Predicates/CompilerPass.cpp +++ b/tket/src/Predicates/CompilerPass.cpp @@ -393,7 +393,8 @@ void from_json(const nlohmann::json& j, PassPtr& pp) { content.at("fidelities").at("CX").get>(); fid.ZZMax_fidelity = content.at("fidelities").at("ZZMax").get>(); - fid.ZZPhase_fidelity = std::nullopt; + fid.ZZPhase_fidelity = + content.at("fidelities").at("ZZPhase").get>(); bool allow_swaps = content.at("allow_swaps").get(); pp = DecomposeTK2(fid, allow_swaps); } else if (passname == "PeepholeOptimise2Q") { diff --git a/tket/src/Predicates/PassGenerators.cpp b/tket/src/Predicates/PassGenerators.cpp index 7d7ab534a9..a87ae4ce27 100644 --- a/tket/src/Predicates/PassGenerators.cpp +++ b/tket/src/Predicates/PassGenerators.cpp @@ -814,12 +814,12 @@ PassPtr DecomposeTK2(const Transforms::TwoQbFidelities& fid, bool allow_swaps) { j["allow_swaps"] = allow_swaps; nlohmann::json fid_json; fid_json["CX"] = fid.CX_fidelity; - std::visit( + fid_json["ZZPhase"] = std::visit( overloaded{ - [](std::nullopt_t) { return; }, - [&fid_json](double arg) { fid_json["ZZPhase"] = arg; }, - [&fid_json](std::function) { - fid_json["ZZPhase"] = "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; + [](std::nullopt_t) { return nullptr; }, + [](double arg) { return arg; }, + [](std::function) { + return "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; }}, *fid.ZZPhase_fidelity); fid_json["ZZMax"] = fid.ZZMax_fidelity; diff --git a/tket/test/src/test_json.cpp b/tket/test/src/test_json.cpp index 9219258c7f..4af2183bca 100644 --- a/tket/test/src/test_json.cpp +++ b/tket/test/src/test_json.cpp @@ -940,6 +940,7 @@ SCENARIO("Test compiler pass serializations") { COMPPASSJSONTEST(KAKDecomposition, KAKDecomposition(OpType::CX, 0.98)) COMPPASSJSONTEST( DecomposeTK2, DecomposeTK2({0.98, std::nullopt, std::nullopt}, false)) + COMPPASSJSONTEST(DecomposeTK2, DecomposeTK2({0.98, 0.98, 0.98})) COMPPASSJSONTEST(ThreeQubitSquash, ThreeQubitSquash(false)) COMPPASSJSONTEST( EulerAngleReduction, gen_euler_pass(OpType::Rx, OpType::Ry, false)) From af65a8a671a188df7816fc90541e34d00dcf9df9 Mon Sep 17 00:00:00 2001 From: John Children Date: Tue, 3 Sep 2024 17:32:55 +0100 Subject: [PATCH 03/21] chore: simplify logic a bit --- tket/src/Predicates/PassGenerators.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tket/src/Predicates/PassGenerators.cpp b/tket/src/Predicates/PassGenerators.cpp index a87ae4ce27..c9cdec1692 100644 --- a/tket/src/Predicates/PassGenerators.cpp +++ b/tket/src/Predicates/PassGenerators.cpp @@ -15,6 +15,7 @@ #include "tket/Predicates/PassGenerators.hpp" #include +#include #include #include #include @@ -814,14 +815,17 @@ PassPtr DecomposeTK2(const Transforms::TwoQbFidelities& fid, bool allow_swaps) { j["allow_swaps"] = allow_swaps; nlohmann::json fid_json; fid_json["CX"] = fid.CX_fidelity; - fid_json["ZZPhase"] = std::visit( - overloaded{ - [](std::nullopt_t) { return nullptr; }, - [](double arg) { return arg; }, - [](std::function) { - return "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; - }}, - *fid.ZZPhase_fidelity); + if (fid.ZZPhase_fidelity.has_value()) { + fid_json["ZZPhase"] = std::visit( + overloaded{ + [](double arg) { return arg; }, + [](std::function) { + return "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; + }}, + *fid.ZZPhase_fidelity); + } else { + fid_json["ZZPhase"] = std::nullptr_t{}; + } fid_json["ZZMax"] = fid.ZZMax_fidelity; j["fidelities"] = fid_json; return std::make_shared(precons, t, postcons, j); From 0ab7e6d1877fef5621ae20895806276c9392c68b Mon Sep 17 00:00:00 2001 From: John Children Date: Tue, 3 Sep 2024 18:19:27 +0100 Subject: [PATCH 04/21] chore: Fix compile error --- tket/src/Predicates/PassGenerators.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tket/src/Predicates/PassGenerators.cpp b/tket/src/Predicates/PassGenerators.cpp index c9cdec1692..2cf5327c0e 100644 --- a/tket/src/Predicates/PassGenerators.cpp +++ b/tket/src/Predicates/PassGenerators.cpp @@ -816,15 +816,16 @@ PassPtr DecomposeTK2(const Transforms::TwoQbFidelities& fid, bool allow_swaps) { nlohmann::json fid_json; fid_json["CX"] = fid.CX_fidelity; if (fid.ZZPhase_fidelity.has_value()) { - fid_json["ZZPhase"] = std::visit( + std::visit( overloaded{ - [](double arg) { return arg; }, - [](std::function) { - return "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; + [&fid_json](double arg) { fid_json["ZZPhase"] = arg; }, + [&fid_json](std::function) { + fid_json["ZZPhase"] = + "SERIALIZATION OF FUNCTIONS IS NOT SUPPORTED"; }}, - *fid.ZZPhase_fidelity); + fid.ZZPhase_fidelity.value()); } else { - fid_json["ZZPhase"] = std::nullptr_t{}; + fid_json["ZZPhase"] = nullptr; } fid_json["ZZMax"] = fid.ZZMax_fidelity; j["fidelities"] = fid_json; From 1559ba57492e9143560bf162a27996e6142d073e Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 09:36:16 +0100 Subject: [PATCH 05/21] chore: maybe fix serialization? --- tket/src/Predicates/PassGenerators.cpp | 6 +----- tket/src/Transformations/Decomposition.cpp | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tket/src/Predicates/PassGenerators.cpp b/tket/src/Predicates/PassGenerators.cpp index 2cf5327c0e..584cb6b062 100644 --- a/tket/src/Predicates/PassGenerators.cpp +++ b/tket/src/Predicates/PassGenerators.cpp @@ -15,14 +15,10 @@ #include "tket/Predicates/PassGenerators.hpp" #include -#include #include -#include #include #include -#include -#include "Utils/Expression.hpp" #include "tket/ArchAwareSynth/SteinerForest.hpp" #include "tket/Circuit/CircPool.hpp" #include "tket/Circuit/Circuit.hpp" @@ -825,7 +821,7 @@ PassPtr DecomposeTK2(const Transforms::TwoQbFidelities& fid, bool allow_swaps) { }}, fid.ZZPhase_fidelity.value()); } else { - fid_json["ZZPhase"] = nullptr; + fid_json["ZZPhase"] = std::nullptr_t{}; } fid_json["ZZMax"] = fid.ZZMax_fidelity; j["fidelities"] = fid_json; diff --git a/tket/src/Transformations/Decomposition.cpp b/tket/src/Transformations/Decomposition.cpp index 8e9fca02be..b893f70d10 100644 --- a/tket/src/Transformations/Decomposition.cpp +++ b/tket/src/Transformations/Decomposition.cpp @@ -19,7 +19,6 @@ // replace with c++20 when available #include #include -#include #include "tket/Architecture/Architecture.hpp" #include "tket/Circuit/CircPool.hpp" From ff2e8db6dcb81ea98716c88c591f5089f9c270b5 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 09:52:39 +0100 Subject: [PATCH 06/21] chore: Handle unset ZZPhase? --- tket/src/Predicates/CompilerPass.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tket/src/Predicates/CompilerPass.cpp b/tket/src/Predicates/CompilerPass.cpp index 9085388759..56f7054b54 100644 --- a/tket/src/Predicates/CompilerPass.cpp +++ b/tket/src/Predicates/CompilerPass.cpp @@ -15,6 +15,7 @@ #include "tket/Predicates/CompilerPass.hpp" #include +#include #include #include "tket/Mapping/RoutingMethodJson.hpp" @@ -394,7 +395,8 @@ void from_json(const nlohmann::json& j, PassPtr& pp) { fid.ZZMax_fidelity = content.at("fidelities").at("ZZMax").get>(); fid.ZZPhase_fidelity = - content.at("fidelities").at("ZZPhase").get>(); + content.at("fidelities") + .value>("ZZPhase", std::nullopt); bool allow_swaps = content.at("allow_swaps").get(); pp = DecomposeTK2(fid, allow_swaps); } else if (passname == "PeepholeOptimise2Q") { From 71255d5d79e8ede96beb799dd1784c70d8a5bb73 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 10:15:46 +0100 Subject: [PATCH 07/21] test: Move DecomposeTK2 test to two way passes --- pytket/tests/passes_serialisation_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 242f2f33cf..3d36dadbd6 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -299,6 +299,17 @@ def nonparam_predicate_dict(name: str) -> Dict[str, Any]: "AutoRebase": standard_pass_dict( {"name": "AutoRebase", "basis_allowed": ["H", "TK1", "CX"], "allow_swaps": True} ), + "DecomposeTK2": standard_pass_dict( + { + "name": "DecomposeTK2", + "fidelities": { + "CX": None, + "ZZMax": 1.0, + "ZZPhase": 0.5, + }, + "allow_swaps": True, + } + ), } # non-parametrized passes that satisfy pass.from_dict(d).to_dict()==d From 7a006492dbf93187c90525c71c72035a7ae69d78 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 11:04:55 +0100 Subject: [PATCH 08/21] test: Improve testing and resolve comments --- pytket/tests/passes_serialisation_test.py | 1 + pytket/tests/transform_test.py | 10 ++++++++++ tket/src/Transformations/Decomposition.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 3d36dadbd6..f378e73360 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -299,6 +299,7 @@ def nonparam_predicate_dict(name: str) -> Dict[str, Any]: "AutoRebase": standard_pass_dict( {"name": "AutoRebase", "basis_allowed": ["H", "TK1", "CX"], "allow_swaps": True} ), + # ZZPhase must be a float and note a function. "DecomposeTK2": standard_pass_dict( { "name": "DecomposeTK2", diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index e4f99f602b..c34d3c1477 100644 --- a/pytket/tests/transform_test.py +++ b/pytket/tests/transform_test.py @@ -209,6 +209,16 @@ def test_DecomposeTK2() -> None: assert c.n_gates_of_type(OpType.CX) == 0 assert c.n_gates_of_type(OpType.ZZMax) == 3 + c = Circuit(2).add_gate(OpType.TK2, [0.5, 0.5, 0.5], [0, 1]) + Transform.DecomposeTK2(False, ZZPhase_fidelity=0.8).apply(c) + assert c.n_gates_of_type(OpType.CX) == 0 + assert c.n_gates_of_type(OpType.ZZMax) == 3 + + c = Circuit(2).add_gate(OpType.TK2, [0.5, 0.5, 0.5], [0, 1]) + Transform.DecomposeTK2(False, ZZPhase_fidelity=lambda _: 0.8).apply(c) + assert c.n_gates_of_type(OpType.CX) == 0 + assert c.n_gates_of_type(OpType.ZZMax) == 3 + def test_fidelity_KAK() -> None: c = get_KAK_test_circuit() diff --git a/tket/src/Transformations/Decomposition.cpp b/tket/src/Transformations/Decomposition.cpp index b893f70d10..e3d36157ff 100644 --- a/tket/src/Transformations/Decomposition.cpp +++ b/tket/src/Transformations/Decomposition.cpp @@ -865,8 +865,8 @@ Transform decompose_TK2(const TwoQbFidelities &fid, bool allow_swaps) { } if (fid.ZZMax_fidelity && fid.ZZPhase_fidelity) { double ZZPhase_half = std::visit( - overloaded{// Half of the provided Value. - [](double arg) { return arg * .5; }, + overloaded{// A constant value. + [](double arg) { return arg; }, // A value depending on the input. [](std::function arg) { return (arg)(.5); }}, *fid.ZZPhase_fidelity); From 5b0551b5f48a3fb1bd8d4dbb6b47c5eddc3322e9 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 11:06:35 +0100 Subject: [PATCH 09/21] chore: Update conanfile --- tket/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tket/conanfile.py b/tket/conanfile.py index 3c6f11dbc9..558f4756d0 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.20" + version = "1.3.21" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket" From bf9a0ff82a0969ef05f69ba819c6b87b63de6d60 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 11:49:57 +0100 Subject: [PATCH 10/21] chore: Fix the binders for transforms --- pytket/binders/transform.cpp | 2 +- pytket/tests/transform_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytket/binders/transform.cpp b/pytket/binders/transform.cpp index e376762a37..8d83d49df4 100644 --- a/pytket/binders/transform.cpp +++ b/pytket/binders/transform.cpp @@ -48,7 +48,7 @@ Transforms::TwoQbFidelities get_fidelities(const py::kwargs &kwargs) { } else if (kwargstr == "ZZMax_fidelity") { fid.ZZMax_fidelity = py::cast(kwarg.second); } else if (kwargstr == "ZZPhase_fidelity") { - fid.ZZPhase_fidelity = py::cast(kwarg.second); + fid.ZZPhase_fidelity = py::cast>(kwarg.second); } else { throw py::type_error( "got an unexpected keyword argument '" + kwargstr + "'"); diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index c34d3c1477..4edac7b179 100644 --- a/pytket/tests/transform_test.py +++ b/pytket/tests/transform_test.py @@ -212,12 +212,12 @@ def test_DecomposeTK2() -> None: c = Circuit(2).add_gate(OpType.TK2, [0.5, 0.5, 0.5], [0, 1]) Transform.DecomposeTK2(False, ZZPhase_fidelity=0.8).apply(c) assert c.n_gates_of_type(OpType.CX) == 0 - assert c.n_gates_of_type(OpType.ZZMax) == 3 + assert c.n_gates_of_type(OpType.ZZPhase) == 3 c = Circuit(2).add_gate(OpType.TK2, [0.5, 0.5, 0.5], [0, 1]) Transform.DecomposeTK2(False, ZZPhase_fidelity=lambda _: 0.8).apply(c) assert c.n_gates_of_type(OpType.CX) == 0 - assert c.n_gates_of_type(OpType.ZZMax) == 3 + assert c.n_gates_of_type(OpType.ZZPhase) == 3 def test_fidelity_KAK() -> None: From eb1d35546800026a45870c8a0ebbab88ae538e7d Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 12:01:30 +0100 Subject: [PATCH 11/21] chore: Reformat C++ --- tket/include/tket/Transformations/Transform.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tket/include/tket/Transformations/Transform.hpp b/tket/include/tket/Transformations/Transform.hpp index 5ebfd346f7..f19f9560da 100644 --- a/tket/include/tket/Transformations/Transform.hpp +++ b/tket/include/tket/Transformations/Transform.hpp @@ -99,7 +99,8 @@ inline const Transform id = struct TwoQbFidelities { std::optional CX_fidelity; std::optional ZZMax_fidelity; - std::optional>> ZZPhase_fidelity; + std::optional>> + ZZPhase_fidelity; }; } // namespace Transforms From 1edfb6700d1f966c4d8e61d7509f909a1a1b0322 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 13:20:56 +0100 Subject: [PATCH 12/21] chore: Add ZZPhase fidelity to pass schema --- schemas/compiler_pass_v1.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/schemas/compiler_pass_v1.json b/schemas/compiler_pass_v1.json index 3d117a7b1c..e3a807dde3 100644 --- a/schemas/compiler_pass_v1.json +++ b/schemas/compiler_pass_v1.json @@ -320,6 +320,11 @@ "type": ["number", "null"], "minimum": 0, "maximum": 1 + }, + "ZZPhase": { + "type": ["number", "null"], + "minimum": 0, + "maximum": 1 } } }, From 32094274349eaf054b30f5adfa86b670c15973ea Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 13:27:09 +0100 Subject: [PATCH 13/21] docs: Update changelog --- pytket/docs/changelog.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index aae91b09f4..087b2518ee 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Unreleased +---------- + +Features: + +* DecomposeTK2 pass can now accept a float for ZZPhase_fidelity. +* DecomposeTK2 now has a json representation when it contains no functions. + 1.32.0 (September 2024) ----------------------- From d9cd070145f43ef2bc43a6ce06c1f60d907d1283 Mon Sep 17 00:00:00 2001 From: John Children Date: Wed, 4 Sep 2024 13:50:53 +0100 Subject: [PATCH 14/21] chore: Correct tket version in conan file --- pytket/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index 18126f363b..fef1dc8ad3 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -32,7 +32,7 @@ def package(self): cmake.install() def requirements(self): - self.requires("tket/1.3.20@tket/stable") + self.requires("tket/1.3.21@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") From 7f409ac622e40b173e2cb25ee30505993f9c6578 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 14:47:03 +0100 Subject: [PATCH 15/21] Update docstrings. --- pytket/binders/passes.cpp | 6 +++--- pytket/binders/transform.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pytket/binders/passes.cpp b/pytket/binders/passes.cpp index 5c8c57be94..3275a395c1 100644 --- a/pytket/binders/passes.cpp +++ b/pytket/binders/passes.cpp @@ -405,9 +405,9 @@ PYBIND11_MODULE(passes, m) { "`ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities " "must be given by a single floating point fidelity. The `ZZPhase` " "fidelity is given as a lambda float -> float, mapping a ZZPhase " - "angle parameter to its fidelity. These parameters will be used " - "to return the optimal decomposition of each TK2 gate, taking " - "noise into consideration.\n\n" + "angle parameter to its fidelity, or by a single float. These parameters " + "will be used to return the optimal decomposition of each TK2 gate, " + "taking noise into consideration.\n\n" "If no fidelities are provided, the TK2 gates will be decomposed " "exactly using CX gates. For equal fidelities, ZZPhase will be prefered " "over ZZMax and CX if the decomposition results in fewer two-qubit " diff --git a/pytket/binders/transform.cpp b/pytket/binders/transform.cpp index 8d83d49df4..8ef8027b78 100644 --- a/pytket/binders/transform.cpp +++ b/pytket/binders/transform.cpp @@ -228,9 +228,9 @@ PYBIND11_MODULE(transform, m) { "`ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities " "must be given by a single floating point fidelity. The `ZZPhase` " "fidelity is given as a lambda float -> float, mapping a ZZPhase " - "angle parameter to its fidelity. These parameters will be used " - "to return the optimal decomposition of each TK2 gate, taking " - "noise into consideration.\n\n" + "angle parameter to its fidelity, or by a single float. These " + "parameters will be used to return the optimal decomposition of each " + "TK2 gate, taking noise into consideration.\n\n" "Using the `allow_swaps=True` (default) option, qubits will be " "swapped when convenient to reduce the two-qubit gate count of the " "decomposed TK2.\n\n" From 8ebe4b53dc6cd7c39ab34f00ecacbf651ed446ea Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 14:47:35 +0100 Subject: [PATCH 16/21] Update changelog. --- pytket/docs/changelog.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index 087b2518ee..d8ff307da7 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -6,8 +6,8 @@ Unreleased Features: -* DecomposeTK2 pass can now accept a float for ZZPhase_fidelity. -* DecomposeTK2 now has a json representation when it contains no functions. +* DecomposeTK2 pass and transform can now accept a float for ZZPhase_fidelity. +* DecomposeTK2 pass now has a json representation when it contains no functions. 1.32.0 (September 2024) ----------------------- From 5258428885186d61f12411c946ca5dab86ae25fa Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 14:48:04 +0100 Subject: [PATCH 17/21] Fix typo. --- pytket/tests/passes_serialisation_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index f378e73360..cf7423248c 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -299,7 +299,7 @@ def nonparam_predicate_dict(name: str) -> Dict[str, Any]: "AutoRebase": standard_pass_dict( {"name": "AutoRebase", "basis_allowed": ["H", "TK1", "CX"], "allow_swaps": True} ), - # ZZPhase must be a float and note a function. + # ZZPhase must be a float and not a function. "DecomposeTK2": standard_pass_dict( { "name": "DecomposeTK2", From 742b645ae9e9d990537a4a9e2c8420a278baa749 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 14:49:55 +0100 Subject: [PATCH 18/21] Regenerate stubs. --- pytket/pytket/_tket/passes.pyi | 2 +- pytket/pytket/_tket/transform.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/pytket/_tket/passes.pyi b/pytket/pytket/_tket/passes.pyi index a764716485..20fc8db621 100644 --- a/pytket/pytket/_tket/passes.pyi +++ b/pytket/pytket/_tket/passes.pyi @@ -346,7 +346,7 @@ def DecomposeTK2(allow_swaps: bool = True, **kwargs: Any) -> BasePass: Gate fidelities can be passed as keyword arguments to perform noise-aware decompositions. If the fidelities of several gate types are provided, the best will be chosen. - We currently support `CX_fidelity`, `ZZMax_fidelity` and `ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities must be given by a single floating point fidelity. The `ZZPhase` fidelity is given as a lambda float -> float, mapping a ZZPhase angle parameter to its fidelity. These parameters will be used to return the optimal decomposition of each TK2 gate, taking noise into consideration. + We currently support `CX_fidelity`, `ZZMax_fidelity` and `ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities must be given by a single floating point fidelity. The `ZZPhase` fidelity is given as a lambda float -> float, mapping a ZZPhase angle parameter to its fidelity, or by a single float. These parameters will be used to return the optimal decomposition of each TK2 gate, taking noise into consideration. If no fidelities are provided, the TK2 gates will be decomposed exactly using CX gates. For equal fidelities, ZZPhase will be prefered over ZZMax and CX if the decomposition results in fewer two-qubit gates. diff --git a/pytket/pytket/_tket/transform.pyi b/pytket/pytket/_tket/transform.pyi index d033e46221..2a4d720607 100644 --- a/pytket/pytket/_tket/transform.pyi +++ b/pytket/pytket/_tket/transform.pyi @@ -140,7 +140,7 @@ class Transform: All TK2 gate parameters must be normalised, i.e. they must satisfy `NormalisedTK2Predicate`. - Gate fidelities are passed as keyword arguments to perform noise-aware decompositions. We currently support `CX_fidelity`, `ZZMax_fidelity` and `ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities must be given by a single floating point fidelity. The `ZZPhase` fidelity is given as a lambda float -> float, mapping a ZZPhase angle parameter to its fidelity. These parameters will be used to return the optimal decomposition of each TK2 gate, taking noise into consideration. + Gate fidelities are passed as keyword arguments to perform noise-aware decompositions. We currently support `CX_fidelity`, `ZZMax_fidelity` and `ZZPhase_fidelity`. If provided, the `CX` and `ZZMax` fidelities must be given by a single floating point fidelity. The `ZZPhase` fidelity is given as a lambda float -> float, mapping a ZZPhase angle parameter to its fidelity, or by a single float. These parameters will be used to return the optimal decomposition of each TK2 gate, taking noise into consideration. Using the `allow_swaps=True` (default) option, qubits will be swapped when convenient to reduce the two-qubit gate count of the decomposed TK2. From 35730c66a94e206511ebdf30d74b3f4bc94ca40f Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 15:15:23 +0100 Subject: [PATCH 19/21] Delete explicit deduction guide. --- tket/include/tket/Utils/Expression.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tket/include/tket/Utils/Expression.hpp b/tket/include/tket/Utils/Expression.hpp index 00efb94f85..2bae49493d 100644 --- a/tket/include/tket/Utils/Expression.hpp +++ b/tket/include/tket/Utils/Expression.hpp @@ -33,9 +33,6 @@ template struct overloaded : Ts... { using Ts::operator()...; }; -// explicit deduction guide (not needed as of C++20) -template -overloaded(Ts...) -> overloaded; namespace tket { From 0224e0d65c891a9c679b422ce67d9cc936d5420d Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 15:22:23 +0100 Subject: [PATCH 20/21] Revert "Delete explicit deduction guide." This reverts commit 35730c66a94e206511ebdf30d74b3f4bc94ca40f. --- tket/include/tket/Utils/Expression.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tket/include/tket/Utils/Expression.hpp b/tket/include/tket/Utils/Expression.hpp index 2bae49493d..00efb94f85 100644 --- a/tket/include/tket/Utils/Expression.hpp +++ b/tket/include/tket/Utils/Expression.hpp @@ -33,6 +33,9 @@ template struct overloaded : Ts... { using Ts::operator()...; }; +// explicit deduction guide (not needed as of C++20) +template +overloaded(Ts...) -> overloaded; namespace tket { From e316237c5d5cadb270be3b7ce9dc401b86cccd06 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Wed, 4 Sep 2024 15:29:27 +0100 Subject: [PATCH 21/21] Bump tket version. --- pytket/conanfile.py | 2 +- tket/conanfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/conanfile.py b/pytket/conanfile.py index fef1dc8ad3..d40d046736 100644 --- a/pytket/conanfile.py +++ b/pytket/conanfile.py @@ -32,7 +32,7 @@ def package(self): cmake.install() def requirements(self): - self.requires("tket/1.3.21@tket/stable") + self.requires("tket/1.3.22@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") diff --git a/tket/conanfile.py b/tket/conanfile.py index 558f4756d0..10f613618c 100644 --- a/tket/conanfile.py +++ b/tket/conanfile.py @@ -23,7 +23,7 @@ class TketConan(ConanFile): name = "tket" - version = "1.3.21" + version = "1.3.22" package_type = "library" license = "Apache 2" homepage = "https://github.com/CQCL/tket"