Skip to content

Commit da94a42

Browse files
jyu00kt474
andauthored
proper indent (#912)
Co-authored-by: Kevin Tian <[email protected]>
1 parent ed0e2d1 commit da94a42

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

docs/how_to/run_session.rst

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Run a primitive in a session
22
=================================
33

4-
There are several ways to set up and use sessions. The following information should not be considered mandatory steps to follow. Instead, choose the configuration that best suits your needs. To learn more about sessions, see `Introduction to sessions <../sessions.html>`__. This information assumes that you are using Qiskit Runtime `primitives <../primitives.html>`__.
4+
There are several ways to set up and use sessions. The following information should not be considered mandatory steps to follow. Instead, choose the configuration that best suits your needs. To learn more about sessions, see `Introduction to sessions <../sessions.html>`__. This information assumes that you are using Qiskit Runtime `primitives <../primitives.html>`__.
55

66
Prerequisites
77
--------------
88

99
Before starting a session, you must `Set up Qiskit Runtime <https://qiskit.org/documentation/partners/qiskit_ibm_runtime/getting_started.html>`__ and initialize it as a service:
1010

1111
.. code-block:: python
12-
12+
1313
from qiskit_ibm_runtime import QiskitRuntimeService
1414
1515
service = QiskitRuntimeService()
@@ -19,15 +19,15 @@ Open a session
1919

2020
You can open a runtime session by using the context manager `with Session(…)` or by initializing the `Session` class. When you start a session, you can specify options, such as the backend to run on. This topic describes the most commonly used options. For the full list, see the `Sessions API documentation <https://qiskit.org/documentation/partners/qiskit_ibm_runtime/stubs/qiskit_ibm_runtime.Session.html#qiskit_ibm_runtime.Session>`__.
2121

22-
.. important::
22+
.. important::
2323
Data from the first session job is cached and used by subsequent jobs. Therefore, if the first job is cancelled, subsequent session jobs will all fail.
2424

2525
**Session class**
2626

2727
A session can be created by initializing the `Session` class, which can then be passed to the desired primitives. Example:
2828

2929
.. code-block:: python
30-
30+
3131
session= Session(service=service, backend="ibmq_qasm_simulator")
3232
estimator = Estimator(session=session)
3333
sampler = Sampler(session=session)
@@ -37,7 +37,7 @@ A session can be created by initializing the `Session` class, which can then be
3737
The context manager automatically opens a session for you. A session is started when the first primitive job in this context manager starts (not when it is queued). Primitives created in the context automatically use that session. Example:
3838

3939
.. code-block:: python
40-
40+
4141
with Session(service=service, backend="ibmq_qasm_simulator"):
4242
estimator = Estimator()
4343
sampler = Sampler()
@@ -46,19 +46,19 @@ The context manager automatically opens a session for you. A session is started
4646
Specify a backend
4747
-----------------
4848

49-
When you start a session, you can specify session options, such as the backend to run on. A backend is required if you are using the IBM Quantum channel, but optional if you are using the IBM Cloud channel. Once specified, you cannot change the backend used for a session and you cannot specify multiple backends within a session. To use a different backend, open a new session.
49+
When you start a session, you can specify session options, such as the backend to run on. A backend is required if you are using the IBM Quantum channel, but optional if you are using the IBM Cloud channel. Once specified, you cannot change the backend used for a session and you cannot specify multiple backends within a session. To use a different backend, open a new session.
5050

5151
There are two ways to specify a backend in a session:
5252

53-
**Directly specify a string with the backend name.** Example:
54-
53+
**Directly specify a string with the backend name.** Example:
54+
5555
.. code-block:: python
5656
5757
backend = "ibmq_qasm_simulator"
5858
with Session(backend=backend):
5959
...
6060
61-
**Pass the backend object.** Example:
61+
**Pass the backend object.** Example:
6262

6363
.. code-block:: python
6464
@@ -74,43 +74,42 @@ When a session is started, it is assigned a maximum session timeout value. After
7474

7575
You can configure the maximum session timeout value through the `max_time` parameter, which can be specified as seconds (int) or a string, like "2h 30m 40s". This value has to be greater than the `max_execution_time` of the job and less than the system’s `max_time`. The default value is the system’s `max_time`. See `What is the maximum execution time for a Qiskit Runtime job? <../faqs/max_execution_time.html>`__ to determine the system limit.
7676

77-
When setting the session length, consider how long each job within the session might take. For example, if you run five jobs within a session and each job is estimated to be five minutes long, the maximum time for the session should at least 25 min.
77+
When setting the session length, consider how long each job within the session might take. For example, if you run five jobs within a session and each job is estimated to be five minutes long, the maximum time for the session should at least 25 min.
7878

7979
.. code-block:: python
8080
8181
with Session(service=service, backend=backend, max_time="25m"):
82-
...
82+
...
8383
84-
There is also an interactive timeout value (5 minutes), which is not configurable. If no session jobs are queued within that window, the session is temporarily deactivated. For more details about session length and timeout, see `How long a session stays active <../sessions.html#active>`__.
84+
There is also an interactive timeout value (5 minutes), which is not configurable. If no session jobs are queued within that window, the session is temporarily deactivated. For more details about session length and timeout, see `How long a session stays active <../sessions.html#active>`__.
8585

8686
.. _close session:
87-
87+
8888
Close a session
8989
---------------
9090

91-
When jobs are all done, it is recommended that you use `session.close()` to close the session. This allows the scheduler to run the next job without waiting for the session timeout, therefore making it easier for everyone. You cannot submit jobs to a closed session.
91+
When jobs are all done, it is recommended that you use `session.close()` to close the session. This allows the scheduler to run the next job without waiting for the session timeout, therefore making it easier for everyone. You cannot submit jobs to a closed session.
9292

93-
.. warning::
94-
Close a session only after all session jobs **complete**, rather than immediately after they have all been submitted. Session jobs that are not completed will fail.
93+
.. warning::
94+
Close a session only after all session jobs **complete**, rather than immediately after they have all been submitted. Session jobs that are not completed will fail.
9595

9696
.. code-block:: python
9797
9898
with Session(service=service, backend=backend) as session:
99-
...
100-
estimator = Estimator()
101-
job = estimator.run(...)
102-
# Do not close here, the job might not be completed!
103-
result = job.result()
104-
# Reaching this line means that the job is finished.
105-
session.close()
99+
estimator = Estimator()
100+
job = estimator.run(...)
101+
# Do not close here, the job might not be completed!
102+
result = job.result()
103+
# job.result() is blocking, so this job is now finished and the session can be safely closed.
104+
session.close()
106105
107106
Full example
108107
------------
109108

110109
In this example, we start a session, run an Estimator job, and output the result:
111110

112111
.. code-block:: python
113-
112+
114113
from qiskit.circuit.random import random_circuit
115114
from qiskit.quantum_info import SparsePauliOp
116115
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Estimator, Options

0 commit comments

Comments
 (0)