From 6bc09cc9db9a5d2f10ec7922ac9b20bccf87390a Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:02:08 +0000 Subject: [PATCH 01/23] add impl permutations warning back in --- pytket/extensions/qiskit/qiskit_convert.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index cd2660e4..71ef1358 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -861,8 +861,12 @@ 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 + tkcirc: Circuit, replace_implicit_swaps: bool = False, perm_warning: bool = True, ) -> QuantumCircuit: """ Converts a pytket :py:class:`Circuit` to a qiskit :py:class:`qiskit.QuantumCircuit`. @@ -871,7 +875,7 @@ 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. + 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. @@ -884,6 +888,14 @@ def tk_to_qiskit( if replace_implicit_swaps: tkc.replace_implicit_wire_swaps() + if _has_implicit_permutation(tkcirc) and perm_warning 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: From e68d754724ce1165bf1a672a94d072e760272845 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:21:37 +0000 Subject: [PATCH 02/23] add docstring --- pytket/extensions/qiskit/qiskit_convert.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 71ef1358..b82d2172 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -15,6 +15,7 @@ """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 @@ -862,6 +863,7 @@ def append_tk_command_to_qiskit( def _has_implicit_permutation(circ: Circuit) -> bool: + """Returns True if a Circuit has a non-trivial permutation of qubits, false otherwise.""" return any(q0 != q1 for q0, q1 in circ.implicit_qubit_permutation().items()) From abecdb7a7a127eb6edcbf1d8c119fc0aac9090aa Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:37:13 +0000 Subject: [PATCH 03/23] add test of warnings --- tests/qiskit_convert_test.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index cdde50d3..bc4fda8a 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import warnings from collections import Counter from math import pi @@ -62,7 +63,7 @@ reg_eq, ) from pytket.extensions.qiskit import IBMQBackend, qiskit_to_tk, tk_to_qiskit -from pytket.extensions.qiskit.backends import qiskit_aer_backend +from pytket.extensions.qiskit.backends import qiskit_aer_backend, AerStateBackend, AerBackend from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype from pytket.extensions.qiskit.result_convert import qiskit_result_to_backendresult from pytket.extensions.qiskit.tket_pass import TketAutoPass, TketPass @@ -1165,6 +1166,23 @@ def test_symbolic_param_conv() -> None: } ) +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) + + state_backend = AerStateBackend() + shots_backend = AerBackend() + with pytest.warns(UserWarning) as record: + state_backend.run_circuit(c) + c.measure_all() + shots_backend.run_circuit(c) + assert len(record) == 0 + + + + # https://github.com/CQCL/pytket-qiskit/issues/337 def test_nonregister_bits() -> None: From 31538ce86f621bab63561d0f4ba36261deca0675 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:38:38 +0000 Subject: [PATCH 04/23] add boolean flag to converter --- pytket/extensions/qiskit/qiskit_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index b82d2172..dc69340f 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -890,7 +890,7 @@ def tk_to_qiskit( if replace_implicit_swaps: tkc.replace_implicit_wire_swaps() - if _has_implicit_permutation(tkcirc) and perm_warning and not replace_implicit_swaps: + if _has_implicit_permutation(tkcirc) and perm_warning not replace_implicit_swaps: warnings.warn( "The pytket Circuit contains implicit qubit permutations" + " which aren't handled by default." From 7a5c006f5ab4cde3fc4a19790164c707adfb18d1 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:40:44 +0000 Subject: [PATCH 05/23] update docstring --- pytket/extensions/qiskit/qiskit_convert.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index dc69340f..3e93ba68 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -884,6 +884,8 @@ def tk_to_qiskit( :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. + :param perm_warnings: Warn on if input circuit has implicit qubit permutations, True by + default. :return: The converted circuit """ tkc = tkcirc.copy() # Make a local copy of tkcirc From b35e5a983da997e13a84e55a6d494c08f104493b Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:44:11 +0000 Subject: [PATCH 06/23] fix syntax mistake --- pytket/extensions/qiskit/qiskit_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 3e93ba68..bafc76bb 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -892,7 +892,7 @@ def tk_to_qiskit( if replace_implicit_swaps: tkc.replace_implicit_wire_swaps() - if _has_implicit_permutation(tkcirc) and perm_warning not replace_implicit_swaps: + if _has_implicit_permutation(tkcirc) and perm_warning and not replace_implicit_swaps: warnings.warn( "The pytket Circuit contains implicit qubit permutations" + " which aren't handled by default." From 2b7c485b3d41d4b3c6116c817d339cf670842ce6 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:01:29 +0000 Subject: [PATCH 07/23] fix test --- tests/qiskit_convert_test.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index bc4fda8a..f1b05d19 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -1169,21 +1169,16 @@ def test_symbolic_param_conv() -> None: def test_implicit_swap_warning() -> None: c = Circuit(2).H(0).SWAP(0, 1) c.replace_SWAPs() + c.measure_all() with pytest.warns(UserWarning, match="The pytket Circuit contains implicit qubit"): tk_to_qiskit(c) - state_backend = AerStateBackend() shots_backend = AerBackend() with pytest.warns(UserWarning) as record: - state_backend.run_circuit(c) - c.measure_all() shots_backend.run_circuit(c) assert len(record) == 0 - - - # https://github.com/CQCL/pytket-qiskit/issues/337 def test_nonregister_bits() -> None: c = Circuit(1).X(0).measure_all() From c825a3777c5f5f7f758f6d03db8ad4f3c975dbcd Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:02:13 +0000 Subject: [PATCH 08/23] fix import --- tests/qiskit_convert_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index f1b05d19..158b95f5 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. import os -import warnings from collections import Counter from math import pi From b6daff673f15f6d0f03ff048308cdbc8fbde8229 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:03:19 +0000 Subject: [PATCH 09/23] fix docstring --- pytket/extensions/qiskit/qiskit_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index bafc76bb..c5b75022 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -884,7 +884,7 @@ def tk_to_qiskit( :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. - :param perm_warnings: Warn on if input circuit has implicit qubit permutations, True by + :param perm_warnings: Warn if an input circuit has implicit qubit permutations, True by default. :return: The converted circuit """ From ee6b98ec2a3c17af2354b70fc82eb8ba72ac5f6e Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:03:47 +0000 Subject: [PATCH 10/23] use boolean flag in Aer backends --- pytket/extensions/qiskit/backends/aer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/backends/aer.py b/pytket/extensions/qiskit/backends/aer.py index 61337201..99bbea73 100644 --- a/pytket/extensions/qiskit/backends/aer.py +++ b/pytket/extensions/qiskit/backends/aer.py @@ -286,6 +286,7 @@ def process_circuits( circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list) replace_implicit_swaps = self.supports_state or self.supports_unitary + perm_warning = replace_implicit_swaps for (n_shots, batch), indices in zip(circuit_batches, batch_order): qcs, ppcirc_strs, tkc_qubits_count = [], [], [] @@ -296,7 +297,7 @@ def process_circuits( else: c0, ppcirc_rep = tkc, None - qc = tk_to_qiskit(c0, replace_implicit_swaps) + qc = tk_to_qiskit(c0, replace_implicit_swaps, perm_warning) if self.supports_state: qc.save_state() From 6cdf03fae66ccfefed957e10a79450b6671b1ebc Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:15:17 +0000 Subject: [PATCH 11/23] fix formatting issues --- pytket/extensions/qiskit/qiskit_convert.py | 10 ++++++++-- tests/qiskit_convert_test.py | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index c5b75022..94a01b04 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -868,7 +868,9 @@ def _has_implicit_permutation(circ: Circuit) -> bool: def tk_to_qiskit( - tkcirc: Circuit, replace_implicit_swaps: bool = False, perm_warning: bool = True, + tkcirc: Circuit, + replace_implicit_swaps: bool = False, + perm_warning: bool = True, ) -> QuantumCircuit: """ Converts a pytket :py:class:`Circuit` to a qiskit :py:class:`qiskit.QuantumCircuit`. @@ -892,7 +894,11 @@ def tk_to_qiskit( if replace_implicit_swaps: tkc.replace_implicit_wire_swaps() - if _has_implicit_permutation(tkcirc) and perm_warning and not replace_implicit_swaps: + if ( + _has_implicit_permutation(tkcirc) + and perm_warning + and not replace_implicit_swaps + ): warnings.warn( "The pytket Circuit contains implicit qubit permutations" + " which aren't handled by default." diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index 158b95f5..14c106ea 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -62,7 +62,11 @@ reg_eq, ) from pytket.extensions.qiskit import IBMQBackend, qiskit_to_tk, tk_to_qiskit -from pytket.extensions.qiskit.backends import qiskit_aer_backend, AerStateBackend, AerBackend +from pytket.extensions.qiskit.backends import ( + qiskit_aer_backend, + AerStateBackend, + AerBackend, +) from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype from pytket.extensions.qiskit.result_convert import qiskit_result_to_backendresult from pytket.extensions.qiskit.tket_pass import TketAutoPass, TketPass @@ -1165,6 +1169,7 @@ def test_symbolic_param_conv() -> None: } ) + def test_implicit_swap_warning() -> None: c = Circuit(2).H(0).SWAP(0, 1) c.replace_SWAPs() From e789a6461ebb8b7aa793ef0ab12a7bbe420ff7e4 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:30:49 +0000 Subject: [PATCH 12/23] fix boolean flag in aer --- pytket/extensions/qiskit/backends/aer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/backends/aer.py b/pytket/extensions/qiskit/backends/aer.py index 99bbea73..f23fb518 100644 --- a/pytket/extensions/qiskit/backends/aer.py +++ b/pytket/extensions/qiskit/backends/aer.py @@ -286,7 +286,7 @@ def process_circuits( circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list) replace_implicit_swaps = self.supports_state or self.supports_unitary - perm_warning = replace_implicit_swaps + perm_warning = False for (n_shots, batch), indices in zip(circuit_batches, batch_order): qcs, ppcirc_strs, tkc_qubits_count = [], [], [] From b157133362cbf5545904a5c36d49f9029bb136d6 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:31:06 +0000 Subject: [PATCH 13/23] fix warnings test --- tests/qiskit_convert_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index 14c106ea..495790b6 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import warnings from collections import Counter from math import pi @@ -64,7 +65,6 @@ from pytket.extensions.qiskit import IBMQBackend, qiskit_to_tk, tk_to_qiskit from pytket.extensions.qiskit.backends import ( qiskit_aer_backend, - AerStateBackend, AerBackend, ) from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype @@ -1178,9 +1178,9 @@ def test_implicit_swap_warning() -> None: tk_to_qiskit(c) shots_backend = AerBackend() - with pytest.warns(UserWarning) as record: + with warnings.catch_warnings(): + warnings.simplefilter("error") shots_backend.run_circuit(c) - assert len(record) == 0 # https://github.com/CQCL/pytket-qiskit/issues/337 From 8accca14a7f36f5c44df78d69c2fe005a335afff Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:33:17 +0000 Subject: [PATCH 14/23] fix docstring length --- pytket/extensions/qiskit/qiskit_convert.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 94a01b04..5c950e2f 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -886,8 +886,8 @@ def tk_to_qiskit( :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. - :param perm_warnings: Warn if an input circuit has implicit qubit permutations, True by - default. + :param perm_warnings: Warn if an input circuit has implicit qubit permutations, + True by default. :return: The converted circuit """ tkc = tkcirc.copy() # Make a local copy of tkcirc From df0cda3d1c46d8cbe5d69c9e9f43990cdd846bc7 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:43:05 +0000 Subject: [PATCH 15/23] fix invalid sphinx table in docs --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 45786d6f..cf7340c1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -194,7 +194,7 @@ Every {py:class}`~pytket.backends.backend.Backend` in pytket has its own {py:met 2 preserve barriers in a circuit, while optimisation level 3 will remove them. :::{list-table} **Default compilation pass for the IBMQBackend and IBMQEmulatorBackend** -:widths: 25 25 25 +:widths: 25 25 25 25 :header-rows: 1 * - optimisation_level = 0 @@ -208,7 +208,7 @@ Every {py:class}`~pytket.backends.backend.Backend` in pytket has its own {py:met * - [AutoRebase [2]](inv:#*.AutoRebase) - [SynthesiseTket](inv:#*.SynthesiseTket) - [FullPeepholeOptimise](inv:#*.passes.FullPeepholeOptimise) - - [RemoveBarriers](inv:#*.passes.RmoveBarriers) + - [RemoveBarriers](inv:#*pytket._tket.passes.RemoveBarriers) * - LightSabre [3] - LightSabre [3] - LightSabre [3] From e04d324922db162cbae6b975c920ac79da4b84a1 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:43:20 +0000 Subject: [PATCH 16/23] update changelog --- docs/changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index f75afa96..f54d7398 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,7 +6,8 @@ ## 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. +- Fix an unhelpful warning message about implicit swaps when using optimisation level 2 with {py:class}`AerBackend` +- Add a boolean `perm_warn` argument to {py:func}`tk_to_qiskit` indicating whether to give a warning if the input {py:class}`Circuit` has an implicit qubit permutation. - Add new level 3 optimisation that uses `GreedyPauliSimp` ## 0.59.0 (November 2024) From 193231cc8faaf6d9c243e54a129ecf079d8c0060 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:46:19 +0000 Subject: [PATCH 17/23] fix docstring length again --- pytket/extensions/qiskit/qiskit_convert.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 5c950e2f..654d3a87 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -863,7 +863,8 @@ def append_tk_command_to_qiskit( def _has_implicit_permutation(circ: Circuit) -> bool: - """Returns True if a Circuit has a non-trivial permutation of qubits, false otherwise.""" + """Returns True if a Circuit has a non-trivial permutation + of qubits, false otherwise.""" return any(q0 != q1 for q0, q1 in circ.implicit_qubit_permutation().items()) From 3cf422a4f1db16319668da13c6d889face684121 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:51:59 +0000 Subject: [PATCH 18/23] fix formatting again --- pytket/extensions/qiskit/qiskit_convert.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 654d3a87..68460e62 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -863,8 +863,8 @@ def append_tk_command_to_qiskit( def _has_implicit_permutation(circ: Circuit) -> bool: - """Returns True if a Circuit has a non-trivial permutation - of qubits, false otherwise.""" + """Returns True if a Circuit has a non-trivial permutation + of qubits, false otherwise.""" return any(q0 != q1 for q0, q1 in circ.implicit_qubit_permutation().items()) From 0c414570313b72d73be5bb3cb0736434d11ac76a Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:54:25 +0000 Subject: [PATCH 19/23] import ordering --- tests/qiskit_convert_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index 495790b6..c3ca48da 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -64,8 +64,8 @@ ) from pytket.extensions.qiskit import IBMQBackend, qiskit_to_tk, tk_to_qiskit from pytket.extensions.qiskit.backends import ( - qiskit_aer_backend, AerBackend, + qiskit_aer_backend, ) from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype from pytket.extensions.qiskit.result_convert import qiskit_result_to_backendresult From 8bd887c213a71f422c8494903ac41e996cb81a95 Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:04:27 +0000 Subject: [PATCH 20/23] clarify docstring --- pytket/extensions/qiskit/qiskit_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 68460e62..23b64c47 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -888,7 +888,7 @@ def tk_to_qiskit( :param replace_implicit_swaps: Implement implicit permutation by adding SWAPs to the end of the circuit. :param perm_warnings: Warn if an input circuit has implicit qubit permutations, - True by default. + and `replace_implicit_swaps` is `False`. True by default. :return: The converted circuit """ tkc = tkcirc.copy() # Make a local copy of tkcirc From dd6e9733966fe87ed10da27fb947ebde2c1aad9f Mon Sep 17 00:00:00 2001 From: CalMacCQ <93673602+CalMacCQ@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:05:33 +0000 Subject: [PATCH 21/23] don't define a new variable --- pytket/extensions/qiskit/backends/aer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pytket/extensions/qiskit/backends/aer.py b/pytket/extensions/qiskit/backends/aer.py index f23fb518..e809851d 100644 --- a/pytket/extensions/qiskit/backends/aer.py +++ b/pytket/extensions/qiskit/backends/aer.py @@ -286,7 +286,6 @@ def process_circuits( circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list) replace_implicit_swaps = self.supports_state or self.supports_unitary - perm_warning = False for (n_shots, batch), indices in zip(circuit_batches, batch_order): qcs, ppcirc_strs, tkc_qubits_count = [], [], [] @@ -297,7 +296,7 @@ def process_circuits( else: c0, ppcirc_rep = tkc, None - qc = tk_to_qiskit(c0, replace_implicit_swaps, perm_warning) + qc = tk_to_qiskit(c0, replace_implicit_swaps, perm_warning=False) if self.supports_state: qc.save_state() From 300fa32efd3526d7e674eaf3fd4496abca22502c Mon Sep 17 00:00:00 2001 From: Callum Macpherson <93673602+CalMacCQ@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:41:41 +0000 Subject: [PATCH 22/23] Update docs/changelog.md Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index f54d7398..1ce096b8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -7,7 +7,7 @@ ## 0.60.0 (Unreleased) - Fix an unhelpful warning message about implicit swaps when using optimisation level 2 with {py:class}`AerBackend` -- Add a boolean `perm_warn` argument to {py:func}`tk_to_qiskit` indicating whether to give a warning if the input {py:class}`Circuit` has an implicit qubit permutation. +- Add a boolean `perm_warning` argument to {py:func}`tk_to_qiskit` indicating whether to give a warning if the input {py:class}`Circuit` has an implicit qubit permutation. - Add new level 3 optimisation that uses `GreedyPauliSimp` ## 0.59.0 (November 2024) From fdefb05c8933b8d9264c187ef038ecb5ee0779c1 Mon Sep 17 00:00:00 2001 From: Callum Macpherson <93673602+CalMacCQ@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:41:51 +0000 Subject: [PATCH 23/23] Update pytket/extensions/qiskit/qiskit_convert.py Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> --- pytket/extensions/qiskit/qiskit_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 23b64c47..0a84eee1 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -887,7 +887,7 @@ def tk_to_qiskit( :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. - :param perm_warnings: Warn if an input circuit has implicit qubit permutations, + :param perm_warning: Warn if an input circuit has implicit qubit permutations, and `replace_implicit_swaps` is `False`. True by default. :return: The converted circuit """