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 RebaseCustom for TK2 gates #1003

Merged
merged 6 commits into from
Sep 5, 2023
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 @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.37@tket/stable")
self.requires("tket/1.2.38@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
39 changes: 37 additions & 2 deletions pytket/tests/predicates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
from pytket.transform import Transform, PauliSynthStrat, CXConfigType
from pytket.passes import SynthesiseOQC
import numpy as np
from sympy import Symbol
from typing import Dict, Any, List, cast
from sympy import Symbol, Expr
from typing import Dict, Any, List, cast, Union

from useful_typedefs import ParamType as Param # type: ignore

Expand Down Expand Up @@ -902,6 +902,40 @@ def test_PeepholeOptimise2Q() -> None:
assert all(k == v for k, v in perm.items())


def test_rebase_custom_tk2() -> None:
def _tk1_to_phase(
a: Union[Expr, float], b: Union[Expr, float], c: Union[Expr, float]
) -> Circuit:
return Circuit(1).Rz(c, 0).Rx(b, 0).Rz(a, 0)

def _tk2_to_phase(
a: Union[Expr, float], b: Union[Expr, float], c: Union[Expr, float]
) -> Circuit:
return Circuit(2).ZZPhase(c, 0, 1).YYPhase(b, 0, 1).XXPhase(a, 0, 1)

to_phase_gates = RebaseCustom(
{OpType.Rx, OpType.Rz, OpType.XXPhase, OpType.YYPhase, OpType.ZZPhase},
tk2_replacement=_tk2_to_phase,
tk1_replacement=_tk1_to_phase,
)

tk2_c = Circuit(2).TK2(0.123, 0.5634, 0.2345, 0, 1)
assert to_phase_gates.apply(tk2_c)
coms = tk2_c.get_commands()
assert len(coms) == 11
assert coms[0].op.type == OpType.Rz
assert coms[1].op.type == OpType.Rz
assert coms[2].op.type == OpType.Rx
assert coms[3].op.type == OpType.Rx
assert coms[4].op.type == OpType.ZZPhase
assert coms[5].op.type == OpType.YYPhase
assert coms[6].op.type == OpType.XXPhase
assert coms[7].op.type == OpType.Rx
assert coms[8].op.type == OpType.Rx
assert coms[9].op.type == OpType.Rz
assert coms[10].op.type == OpType.Rz


if __name__ == "__main__":
test_predicate_generation()
test_compilation_unit_generation()
Expand All @@ -919,3 +953,4 @@ def test_PeepholeOptimise2Q() -> None:
test_RebaseOQC_and_SynthesiseOQC()
test_ZZPhaseToRz()
test_flatten_relabel_pass()
test_rebase_custom_tk2()
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.37"
version = "1.2.38"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
4 changes: 1 addition & 3 deletions tket/src/Transformations/Rebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ static bool standard_rebase_via_tk2(
op = cond.get_op();
}
OpType type = op->get_type();
if (allowed_gates.contains(type) || type == OpType::TK2 ||
type == OpType::Barrier)
continue;
if (allowed_gates.contains(type) || type == OpType::Barrier) continue;
// need to convert
Circuit replacement = TK2_circ_from_multiq(op);
// Find replacement Circuit for all TK2 gates
Expand Down
Loading