Skip to content

Commit

Permalink
Revert warning related to implcit swaps (#418)
Browse files Browse the repository at this point in the history
* remove implicit qubit permutation warning in tk_to_qiskit

* remove test

* update changelog

* fix note in the docs about 'compilation' to AerBackend

* fix import

* expand docstring

* minor fix
  • Loading branch information
CalMacCQ authored Nov 20, 2024
1 parent 11e63cd commit 7befd51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

# Changelog

## 0.60.0 (Unreleased)

- Revert a change made in release v0.59.0 where users are warned about implicit qubit permutations in {py:func}`tk_to_qiskit`. This avoids spamming the user with unhelpful warnings when using pytket-qiskit backends. These backends handle implicit permutations automatically.

## 0.59.0 (November 2024)

- Updated pytket version requirement to 1.34.0.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Every {py:class}`~pytket.backends.backend.Backend` in pytket has its own {py:met
- \[2\] {py:class}`~pytket._tket.passes.AutoRebase` is a conversion to the gateset supported by the backend. For IBM quantum devices and emulators the supported gate set is either $\{X, SX, Rz, CX\}$, $\{X, SX, Rz, ECR\}$, or $\{X, SX, Rz, CZ\}$. The more idealised Aer simulators have a much broader range of supported gates.
- \[3\] This is imported from qiskit and corresponds to the method in "LightSABRE: A Lightweight and Enhanced SABRE Algorithm", Henry Zou, Matthew Treinish, Kevin Hartman, Alexander Ivrii, Jake Lishman, arXiv:2409.08368.

**Note:** The {py:meth}`~AerBackend.default_compilation_pass` for {py:class}`AerBackend` is the same as above.
**Note:** The {py:meth}`~AerBackend.default_compilation_pass` for {py:class}`AerBackend` is the same as above if a {py:class}`NoiseModel` is used. A {py:class}`NoiseModel` implicitly defines connectivity constraints via edge errors. If no {py:class}`NoiseModel` is used then then any passes related to connectivity constraints are omitted from the {py:meth}`~AerBackend.default_compilation_pass` for {py:class}`AerBackend`.

## Noise Modelling

Expand Down
17 changes: 4 additions & 13 deletions pytket/extensions/qiskit/qiskit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"""Methods to allow conversion between Qiskit and pytket circuit classes
"""
import warnings
from collections import defaultdict
from collections.abc import Iterable
from inspect import signature
Expand Down Expand Up @@ -862,10 +861,6 @@ def append_tk_command_to_qiskit(
supported_gate_rebase = AutoRebase(_protected_tket_gates)


def _has_implicit_permutation(circ: Circuit) -> bool:
return any(q0 != q1 for q0, q1 in circ.implicit_qubit_permutation().items())


def tk_to_qiskit(
tkcirc: Circuit, replace_implicit_swaps: bool = False
) -> QuantumCircuit:
Expand All @@ -876,6 +871,10 @@ def tk_to_qiskit(
If no exact replacement can be found for a part of the circuit then an equivalent
circuit will be returned using the tket gates which are supported in qiskit.
Please note that implicit swaps in a pytket Circuit are not handled by default.
Consider using the replace_implicit_swaps flag to replace these implicit swaps with
SWAP gates.
:param tkcirc: A :py:class:`Circuit` to be converted
:param replace_implicit_swaps: Implement implicit permutation by adding SWAPs
to the end of the circuit.
Expand All @@ -885,14 +884,6 @@ def tk_to_qiskit(
if replace_implicit_swaps:
tkc.replace_implicit_wire_swaps()

if _has_implicit_permutation(tkcirc) and not replace_implicit_swaps:
warnings.warn(
"The pytket Circuit contains implicit qubit permutations"
+ " which aren't handled by default."
+ " Consider using the replace_implicit_swaps flag in tk_to_qiskit or"
+ " replacing them using Circuit.replace_implicit_swaps()."
)

qcirc = QuantumCircuit(name=tkc.name)
qreg_sizes: dict[str, int] = {}
for qb in tkc.qubits:
Expand Down
7 changes: 0 additions & 7 deletions tests/qiskit_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,3 @@ def test_nonregister_bits() -> None:
c.rename_units({Bit(0): Bit(1)})
with pytest.raises(NotImplementedError):
tk_to_qiskit(c)


def test_implicit_swap_warning() -> None:
c = Circuit(2).H(0).SWAP(0, 1)
c.replace_SWAPs()
with pytest.warns(UserWarning, match="The pytket Circuit contains implicit qubit"):
tk_to_qiskit(c)

0 comments on commit 7befd51

Please sign in to comment.