You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* move destructor up in file
* replace destructor with weakref finalize
* add conditional context management
* always add finalizer if session is present
* add some tests
* change mock_session scope to function
* only register finalizer if not present
* use static method call
* use _cleanup_session directly on session ref
* remove unnecessary test, add finally
* clean up tests
* only open session if needed in context manager
* add docstrings and lint statements
* add SessionContextMisuseWarning
* adapt docstrings to encourage context managed use
* encorage use of context manager in user guide
* adapt example_executor_qiskit
* use new ibm platform details
* adapt backend mitigation example to use context manager
* new black
@@ -60,7 +60,9 @@ The :class:`Executor <squlearn.Executor>` class provides the following key comfo
60
60
sub-programs. If the version of the Qiskit installation is larger equal than 1.2, the V2 Primitives are created, otherwise the V1 Primitives are returned.
61
61
- **Qiskit Session handling:** Automatically manages the creation and handling of Qiskit IBM Runtime sessions.
62
62
If Sessions are time out, the :class:`Executor <squlearn.Executor>` automatically creates a new session and re-executes the
63
-
job. Note that a manual closing of the session is reuqired when running in jupyter notebook, since otherwise unncessary runtime on the IBM Quantum Machines might be a consequence.
63
+
job. **Important:** When using IBM Quantum backends or Sessions, it is **strongly recommended**
64
+
to use the :class:`Executor <squlearn.Executor>` within a context manager (``with`` statement) to ensure proper cleanup
65
+
and avoid unnecessary charges for open sessions. See :ref:`Session Management <session_management>` for details.
64
66
- **Automatic backend selection (IBM Quantum only):** The :class:`Executor <squlearn.Executor>` class can automatically select the most suitable
65
67
backend for the quantum job. The selection process is facilitated by the `mapomatic <https://github.com/qiskit-community/mapomatic>`_ tool `[1]`_.
66
68
The :class:`Executor <squlearn.Executor>` can be initialized with a list of backends, a :class:`QiskitRuntimeService <qiskit_ibm_runtime.QiskitRuntimeService>`, or a Qiskit
@@ -148,18 +150,39 @@ execution environment:
148
150
149
151
150
152
- A :class:`Backend <qiskit.providers.Backend>` from :class:`QiskitRuntimeService <qiskit_ibm_runtime.QiskitRuntimeService>`'s :meth:`backend <qiskit_ibm_runtime.QiskitRuntimeservice.backend>` method, which utilizes the execution of quantum jobs on IBM Quantum.
151
-
Sessions and Primitives are automatically created and managed by the :class:`Executor <squlearn.Executor>` class (remember to close the session at the end of your code when running on IBM Quantum).
153
+
Sessions and Primitives are automatically created and managed by the :class:`Executor <squlearn.Executor>` class.
154
+
155
+
**Important:** Use the context manager to ensure the session is properly closed:
152
156
153
157
.. code-block:: python
154
158
155
159
from squlearn import Executor
156
160
from qiskit_ibm_runtime import QiskitRuntimeService
157
161
158
-
service = QiskitRuntimeService(channel="ibm_quantum", token="INSERT_YOUR_TOKEN_HERE")
See :ref:`Session Management <session_management>` for details.
163
186
164
187
It is also possible to pass a list of IBM Quantum backends from which the most suited backend is chosen
165
188
automatically (see :ref:`Automatic backend selection <autoselect>`)
@@ -172,8 +195,12 @@ execution environment:
172
195
from squlearn import Executor
173
196
from qiskit_ibm_runtime import QiskitRuntimeService
174
197
175
-
service = QiskitRuntimeService(channel="ibm_quantum", token="INSERT_YOUR_TOKEN_HERE")
176
-
executor = Executor(service)
198
+
service = QiskitRuntimeService(channel="ibm_quantum_platform", token="INSERT_YOUR_TOKEN_HERE")
199
+
200
+
# Use context manager for proper session management
201
+
with Executor(service, auto_backend_mode="quality") as executor:
202
+
# Your quantum computations here
203
+
qkrr.fit(X_train, y_train)
177
204
178
205
- A pre-initialized :class:`Session <qiskit_ibm_runtime.Session>` object, which can be used to execute quantum jobs on the :class:`QiskitRuntimeService <qiskit_ibm_runtime.QiskitRuntimeService>`.
179
206
@@ -182,11 +209,13 @@ execution environment:
182
209
from squlearn import Executor
183
210
from qiskit_ibm_runtime import QiskitRuntimeService
184
211
185
-
service = QiskitRuntimeService(channel="ibm_quantum", token="INSERT_YOUR_TOKEN_HERE")
0 commit comments