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 max_time parameter to IBMBackend.open_session() #1274

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,11 @@ def _runtime_run(
raise RuntimeError(f"The session {self._session.session_id} is closed.")
session_id = self._session.session_id
start_session = session_id is None
max_session_time = self._session._max_time
else:
session_id = None
start_session = False
max_session_time = None

log_level = getattr(self.options, "log_level", None) # temporary
try:
Expand All @@ -777,6 +779,7 @@ def _runtime_run(
job_tags=job_tags,
session_id=session_id,
start_session=start_session,
session_time=max_session_time,
image=image,
)
except RequestsApiError as ex:
Expand Down Expand Up @@ -827,9 +830,9 @@ def _get_run_config(self, program_id: str, **kwargs: Any) -> Dict:
run_config_dict[key] = backend_options[key]
return run_config_dict

def open_session(self) -> ProviderSession:
def open_session(self, max_time: Optional[Union[int, str]] = None) -> ProviderSession:
"""Open session"""
self._session = ProviderSession()
self._session = ProviderSession(max_time=max_time)
return self._session

@property
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/max_session_time-0bd8665656bf439c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Added ``max_time`` parameter to ``IBMBackend.open_session()``.
11 changes: 11 additions & 0 deletions test/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from concurrent.futures import ThreadPoolExecutor, wait

from unittest.mock import MagicMock, Mock, patch
from qiskit.providers.fake_provider import FakeManila

from qiskit_ibm_runtime import Session
from qiskit_ibm_runtime.ibm_backend import IBMBackend
Expand Down Expand Up @@ -65,6 +66,12 @@ def test_using_ibm_backend_service(self):

def test_max_time(self):
"""Test max time."""
model_backend = FakeManila()
backend = IBMBackend(
configuration=model_backend.configuration(),
service=MagicMock(),
api_client=None,
)
max_times = [
(42, 42),
("1h", 1 * 60 * 60),
Expand All @@ -75,6 +82,10 @@ def test_max_time(self):
with self.subTest(max_time=max_t):
session = Session(service=MagicMock(), backend="ibm_gotham", max_time=max_t)
self.assertEqual(session._max_time, expected)
for max_t, expected in max_times:
with self.subTest(max_time=max_t):
backend.open_session(max_time=max_t)
self.assertEqual(backend.session._max_time, expected)

def test_run_after_close(self):
"""Test running after session is closed."""
Expand Down
Loading