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

Log instance on initialization and when running a job #1150

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 7 additions & 0 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ def __init__(
for backend_name in hgp.backends:
if backend_name not in self._backends:
self._backends[backend_name] = None
self._default_instance = self._account.instance
if not self._default_instance:
self._default_instance = self._get_hgp().name
logger.info("Default instance: %s", self._default_instance)
QiskitRuntimeService.global_service = self

# TODO - it'd be nice to allow some kind of autocomplete, but `service.ibmq_foo`
Expand Down Expand Up @@ -988,6 +992,9 @@ def run(
# Find the right hgp
hgp = self._get_hgp(instance=qrt_options.instance, backend_name=qrt_options.backend)
hgp_name = hgp.name
if hgp_name != self._default_instance:
self._default_instance = hgp_name
logger.info("Instance selected: %s", self._default_instance)
backend = self.backend(name=qrt_options.backend, instance=hgp_name)
status = backend.status()
if status.operational is True and status.status_msg != "active":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
At initialization, if not passed in directly, the default ``instance`` selected by the provider
will be logged at the "INFO" level. When running a job, if the backend selected is not in
the default instance but in a different instance the user also has access to, that instance
will also be logged.
10 changes: 10 additions & 0 deletions test/integration/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ def test_resolve_crn_for_invalid_service_instance_name(self):
token=self.dependencies.token,
instance=service_instance_name,
)

def test_logging_instance_at_init(self):
"""Test instance is logged at initialization if instance not passed in."""
with self.assertLogs("qiskit_ibm_runtime", "INFO") as logs:
QiskitRuntimeService(
channel="ibm_quantum",
url=self.dependencies.url,
token=self.dependencies.token,
)
self.assertIn("instance", logs.output[0])
Loading