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

Bugfix/allow implicit swaps not handled correctly #526

Merged
merged 3 commits into from
Oct 28, 2024
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
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Use QIR by default for program submission.
- Update pytket-qir version requirement to 0.15.
- Add new `kwarg` `n_leakage_detection_qubits` to `process_circuits()`
- Fix `allow_implicit_swaps` configuration not handled correctly in default passes.

## 0.38.1 (October 2024)

Expand Down
20 changes: 17 additions & 3 deletions pytket/extensions/quantinuum/backends/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,19 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
elif target_2qb_gate == OpType.ZZPhase:
decomposition_passes = [
NormaliseTK2(),
DecomposeTK2(ZZPhase_fidelity=1.0),
DecomposeTK2(
allow_swaps=self.compilation_config.allow_implicit_swaps,
ZZPhase_fidelity=1.0,
),
]
elif target_2qb_gate == OpType.ZZMax:
decomposition_passes = [NormaliseTK2(), DecomposeTK2(ZZMax_fidelity=1.0)]
decomposition_passes = [
NormaliseTK2(),
DecomposeTK2(
allow_swaps=self.compilation_config.allow_implicit_swaps,
ZZMax_fidelity=1.0,
),
]
else:
raise ValueError(
f"Unrecognized target 2-qubit gate: {target_2qb_gate.name}"
Expand All @@ -711,7 +720,12 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
]
)
else:
passlist.append(FullPeepholeOptimise(target_2qb_gate=OpType.TK2))
passlist.append(
FullPeepholeOptimise(
allow_swaps=self.compilation_config.allow_implicit_swaps,
target_2qb_gate=OpType.TK2,
)
)
passlist.extend(decomposition_passes)
passlist.extend(
[
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ def test_switch_target_2qb_gate() -> None:
assert compiled.n_gates_of_type(OpType.TK2) == 0


def test_not_allow_implicit_swaps() -> None:
# https://github.com/CQCL/pytket-quantinuum/issues/515
b = QuantinuumBackend("", machine_debug=True)
circuits = [Circuit(2).SWAP(0, 1), Circuit(2).CX(0, 1).CX(1, 0).CX(0, 1)]
b.set_compilation_config_allow_implicit_swaps(False)
for target_gate in [OpType.ZZMax, OpType.ZZPhase, OpType.TK2]:
for c in circuits:
b.set_compilation_config_target_2qb_gate(target_gate)
d0 = b.get_compiled_circuit(c, optimisation_level=0)
d1 = b.get_compiled_circuit(c, optimisation_level=1)
d2 = b.get_compiled_circuit(c, optimisation_level=2)
assert d0.implicit_qubit_permutation() == {
Qubit(0): Qubit(0),
Qubit(1): Qubit(1),
}
assert d1.implicit_qubit_permutation() == {
Qubit(0): Qubit(0),
Qubit(1): Qubit(1),
}
assert d2.implicit_qubit_permutation() == {
Qubit(0): Qubit(0),
Qubit(1): Qubit(1),
}


if __name__ == "__main__":
test_implicit_swap_removal()
test_switch_target_2qb_gate()
test_not_allow_implicit_swaps()
Loading