Skip to content

Commit

Permalink
test: Improve testing and resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnchildren committed Sep 4, 2024
1 parent 04d83f5 commit 8fe14e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions pytket/tests/passes_serialisation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions pytket/tests/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tket/src/Transformations/Decomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double(double)> arg) { return (arg)(.5); }},
*fid.ZZPhase_fidelity);
Expand Down

0 comments on commit 8fe14e2

Please sign in to comment.