qiskit-documentation/docs/guides/max-execution-time.mdx

91 lines
5.0 KiB
Plaintext

---
title: Maximum execution time for Qiskit Runtime workloads
description: Describes how long a Qiskit Runtime job can run, regardless of what execution mode is used.
---
# Maximum execution time for Qiskit Runtime workloads
To ensure fairness and help control costs, there is a maximum amount of time each Qiskit Runtime job can run. If a job exceeds this time limit, it is forcibly canceled and a `RuntimeJobMaxTimeoutError` exception is raised.
<span id="max-job"></span>
## Job maximum execution time
The maximum execution time for a job is the smaller of these values:
- The value set for `max_execution_time`
- The QPU-determined job timeout value
The `max_execution_time` value is based on _quantum time_, not wall clock time. Quantum time is the time spent by the QPU complex to process the job. Simulator jobs use wall clock time because they do not have quantum time.
Set the maximum execution time (in seconds) on the job options, as shown in the following example. See [Specify options](/guides/specify-runtime-options) for information about setting options.
```python
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
estimator = Estimator(mode=backend)
estimator.options.max_execution_time = 2500
```
You can also find how much quantum time completed jobs have used by returning the job metrics as follows:
```python
# Find quantum time used by the job
print(f"Quantum time used by job {job.job_id()} was {job.metrics()['usage']['quantum_seconds']} seconds")
```
<span id="max-QPU"></span>
### QPU maximum execution time
The QPU calculates an appropriate job timeout value based on the input circuits and options. This QPU-calculated timeout is capped at 3 hours to ensure fair device usage. If a `max_execution_time` is also specified for the job, the lesser of the two values is used.
For example, if you specify `max_execution_time=5000` (approximately 83 minutes), but the QPU determines it should not take more than 5 minutes (300 seconds) to execute the job, then the job is canceled after 5 minutes.
<span id="batch-max-time"></span>
## Batch maximum execution time
When a batch is started, it is assigned a maximum TTL value. After this TTL is reached, the batch is terminated, any jobs that are already running continue running, and any queued jobs that remain in the batch are put into a failed state. For instructions to set the batch maximum TTL, see [Specify the batch length.](./run-jobs-batch#specify-batch-length)
Batches also have an ITTL value between jobs that cannot be configured. If you don't explicitly close a batch, it is deactivated after the ITTL expires and can be reactivated at any time until it reaches its maximum TTL.
| Instance type (Open or Premium Plan) | ITTL | Maximum TTL |
| --- | --- | --- |
| Both Open and Premium Plan | 1 sec | 10 min |
To determine the ITTL and maximum TTL values for a batch programmatically, use the [`batch.details()` method](run-jobs-batch#batch-details) and look for the `interactive_timeout` and `max_time` values, respectively.
<span id="session-max-time"></span>
## Session maximum execution time
When a session is started, it is assigned a maximum time to live (TTL) value that determines how long a session can run. After this TTL is reached, the session is terminated, any jobs that are already running continue running, and any queued jobs that remain in the session are put into a failed state.
You can set this value with the `max_time` parameter. For instructions, see [Specify the session length.](./run-jobs-session#specify-length)
There is also an interactive time to live (ITTL) value that cannot be configured. If no session jobs are queued within that window, the session is temporarily deactivated.
| Instance type (Open or Premium Plan) | ITTL | Maximum TTL |
| --- | --- | --- |
| Premium Plan | 60 sec* | 8 h* |
| Open Plan | sessions run in job mode | sessions run in job mode |
*\* Certain Premium Plan instances might be configured to have a different value.*
To determine the maximum TTL and ITTL values for a session programmatically, use the [`session.details()` method](run-jobs-session#session-details) and look for the `max_time` and `interactive_timeout` values, respectively.
## Other limitations
* Inputs to jobs cannot exceed 64MB in size.
* Open plan users can use up to 10 minutes of QPU execution time per month (resets at 00:00 UTC on the first of each month). QPU execution time is the amount of time that the QPU is dedicated to processing your job. You can track your monthly usage on the [Platform dashboard,](https://quantum.ibm.com/) [IBM Quantum&trade; Platform Workloads page,](https://quantum.ibm.com/workloads) and [Account](https://quantum.ibm.com/account) page.
## Next steps
<Admonition type="tip" title="Recommendations">
- [Estimate job run time](estimate-job-run-time).
- Review these tips: [Minimize job run time](minimize-time).
</Admonition>