Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job_tags and max_execution_time to options #510

Closed
wants to merge 17 commits into from
10 changes: 10 additions & 0 deletions qiskit_ibm_runtime/options.py
Original file line number Diff line number Diff line change
@@ -104,6 +104,12 @@ class Options:
"""Options for the primitive programs.

Args:
max_execution_time: Maximum execution time in seconds. This overrides
the max_execution_time of the program and cannot exceed it.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this description a bit confusing. What does "overrides the max_execution_time of the program" mean? Does it update the max_execution_time metadata of a program? I don't think that's how this works?


job_tags: Tags to be assigned to the job. The tags can subsequently be used
as a filter in the :meth:`jobs()` function call.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
as a filter in the :meth:`jobs()` function call.
as a filter in the :meth:`qiskit_ibm_runtime.qiskit_runtime_service.jobs()` function call.

There is no jobs() method in this file so the reference link needs to be fully qualified.


optimization_level: How much optimization to perform on the circuits.
Higher levels generate more optimized circuits,
at the expense of longer transpilation times.
@@ -195,6 +201,8 @@ class Options:
Default: ``True``.
"""

max_execution_time: int = None
job_tags: List[str] = None
jyu00 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new EnvironmentOptions in my last PR as an attempt to organize less commonly used options (such as image) that is not related to transpilation or execution. I think job_tags can go there too, but max_execution_time can stay at level 1 as it's more likely to be used.

optimization_level: int = 1
resilience_level: int = 0
log_level: str = "WARNING"
@@ -273,4 +281,6 @@ def _get_runtime_options(options: Dict) -> Dict:
return {
"log_level": options.get("log_level"),
"image": experimental.get("image", None),
"job_tags": options.get("job_tags"),
"max_execution_time": options.get("max_execution_time"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is actually meant to return only fields inside the RuntimeOptions class to be passed to QiskitRuntimeService.run(). The docstring of QiskitRuntimeService.run() says the options parameter can only be backend, image, and log_level. If you want to change that you'll need to update docstring + release note.

}
6 changes: 4 additions & 2 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
@@ -860,6 +860,7 @@ def run(
inputs: Program input parameters. These input values are passed
to the runtime program.
options: Runtime options that control the execution environment.
``job_tags`` and ``max_execution_time`` can also be set here.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your intent is to move job_tags and max_execution_time to be part of RuntimeOptions class. If that's the case, then 1) the use of them as separate input args should be deprecated and 2) docstring should list them as bullet points, similar to backend, image, and log_level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we want to do? Deprecate job_tags and max_execution_time as input args and have them passed in through in options instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah since I think it's rather confusing to have some options inside options and some outside.


* backend: target backend to run on. This is required for ``ibm_quantum`` runtime.
* image: the runtime image used to execute the program, specified in
@@ -937,8 +938,9 @@ def run(
hgp=hgp_name,
log_level=options.get("log_level"),
session_id=session_id,
job_tags=job_tags,
max_execution_time=max_execution_time,
job_tags=job_tags or options.get("job_tags"),
max_execution_time=max_execution_time
or options.get("max_execution_time"),
start_session=start_session,
)
except RequestsApiError as ex:
10 changes: 9 additions & 1 deletion qiskit_ibm_runtime/runtime_options.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
import re
import logging
from dataclasses import dataclass
from typing import Optional
from typing import Optional, List

from qiskit.utils.deprecation import deprecate_arguments

@@ -34,6 +34,8 @@ def __init__(
backend: Optional[str] = None,
image: Optional[str] = None,
log_level: Optional[str] = None,
job_tags: Optional[List[str]] = None,
max_execution_time: Optional[int] = None,
) -> None:
"""RuntimeOptions constructor.

@@ -45,10 +47,16 @@ def __init__(
log_level: logging level to set in the execution environment. The valid
log levels are: ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, and ``CRITICAL``.
The default level is ``WARNING``.
job_tags: Tags to be assigned to the job. The tags can subsequently be used
as a filter in the :meth:`jobs()` function call.
max_execution_time: Maximum execution time in seconds. This overrides
the max_execution_time of the program and cannot exceed it.
"""
self.backend = backend
self.image = image
self.log_level = log_level
self.job_tags = job_tags
self.max_execution_time = max_execution_time

def validate(self, channel: str) -> None:
"""Validate options.
6 changes: 6 additions & 0 deletions releasenotes/notes/add-options-26c127fcd40623a5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upgrade:
- |
``job_tags`` and ``max_execution_time`` can now be passed into
:class:`qiskit_ibm_runtime.Options`. :class:`qiskit_ibm_runtime.RuntimeOptions`
has also been updated to include these two parameters.