From bb786b8d25c9a371f038e134aa241fc70b6178f4 Mon Sep 17 00:00:00 2001 From: Tak Hur Date: Tue, 10 Dec 2024 00:11:21 +0900 Subject: [PATCH 1/5] Fix premature session closure error --- pennylane_qiskit/qiskit_device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index f7ae441e..caac871f 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -592,7 +592,8 @@ def execute_circuits(session): results.append(execute_fn(circ, session)) yield results finally: - session.close() + if self._session is None: + session.close() with execute_circuits(session) as results: return results From d9b91a37aa3c509a59945c7f59c3368f6412900d Mon Sep 17 00:00:00 2001 From: Tak Hur Date: Wed, 18 Dec 2024 01:30:00 +0900 Subject: [PATCH 2/5] fix too-many-positional-arguments --- pennylane_qiskit/qiskit_device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index caac871f..3415b516 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -15,7 +15,8 @@ This module contains a prototype base class for constructing Qiskit devices for PennyLane with the new device API. """ -# pylint: disable=too-many-instance-attributes,attribute-defined-outside-init +# pylint: disable=too-many-instance-attributes,attribute-defined-outside-init,too-many-positional-arguments + import warnings From daacbbfb121080015e576fa27a0eb75d33492095 Mon Sep 17 00:00:00 2001 From: Tak Hur Date: Wed, 18 Dec 2024 01:30:20 +0900 Subject: [PATCH 3/5] changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 422adaaa..35f8f541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,16 @@ ### Documentation 📝 -### Bug fixes 🐛 +### Bug fixes 🐛 +* Fixed premature session closure after a single execution when using `qiskit_device.qiskit_session`. + [(#608)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/608) ### Contributors ✍️ This release contains contributions from (in alphabetical order): Andrija Paurevic +Tak Hur(@takh04) --- # Release 0.39.1 From 89c6887c8e10b75a8142ea215f5e9f24b4bf5f4a Mon Sep 17 00:00:00 2001 From: Tak Hur Date: Wed, 18 Dec 2024 13:51:48 +0900 Subject: [PATCH 4/5] Reformat to comply with black --- pennylane_qiskit/converter.py | 1 - pennylane_qiskit/qiskit_device.py | 2 -- pennylane_qiskit/qiskit_device_legacy.py | 1 - 3 files changed, 4 deletions(-) diff --git a/pennylane_qiskit/converter.py b/pennylane_qiskit/converter.py index d55a966b..c34f1d5c 100644 --- a/pennylane_qiskit/converter.py +++ b/pennylane_qiskit/converter.py @@ -573,7 +573,6 @@ def _function(*args, params: dict = None, wires: list = None, **kwargs): mid_circ_regs[carg] = mid_circ_meas[-1] else: - try: if not isinstance(instruction, (ControlFlowOp,)): operation_args = [instruction.to_matrix()] diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index 3415b516..f4104ed7 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -18,7 +18,6 @@ # pylint: disable=too-many-instance-attributes,attribute-defined-outside-init,too-many-positional-arguments - import warnings import inspect from typing import Union, Callable, Tuple, Sequence @@ -326,7 +325,6 @@ def __init__( compile_backend=None, **kwargs, ): - if shots is None: warnings.warn( "Expected an integer number of shots, but received shots=None. Defaulting " diff --git a/pennylane_qiskit/qiskit_device_legacy.py b/pennylane_qiskit/qiskit_device_legacy.py index 33d2c4a0..dda5c790 100644 --- a/pennylane_qiskit/qiskit_device_legacy.py +++ b/pennylane_qiskit/qiskit_device_legacy.py @@ -105,7 +105,6 @@ class QiskitDeviceLegacy(QubitDevice, abc.ABC): _eigs = {} def __init__(self, wires, provider, backend, shots=1024, **kwargs): - super().__init__(wires=wires, shots=shots) self.provider = provider From b15c90e2c61732d0bf0274600d4fb5850238d950 Mon Sep 17 00:00:00 2001 From: Austin Huang <65315367+austingmhuang@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:34:08 -0500 Subject: [PATCH 5/5] Apply suggestions from code review --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f8f541..b0e248ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ ### Documentation 📝 ### Bug fixes 🐛 -* Fixed premature session closure after a single execution when using `qiskit_device.qiskit_session`. +* Fixed premature session closure when using `qiskit_session`. [(#608)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/608) ### Contributors ✍️ @@ -22,7 +22,7 @@ This release contains contributions from (in alphabetical order): Andrija Paurevic -Tak Hur(@takh04) +Tak Hur --- # Release 0.39.1