Skip to content

Conversation

kt474
Copy link
Member

@kt474 kt474 commented Aug 8, 2025

Summary

Currently on 0.41.0, if there is a default saved instance, retrieving a backend and then attempting to create a session/batch will result in a "No API client found" error. In #2296, we added "instance" as a parameter when creating a backend. This made it so when creating a session, _get_api_client would look in the saved api clients which would be empty, instead of using _active_api_client. This only worked before because we weren't passing an instance to _get_api_client so the current active client was used.

if self._account.instance:
self._default_instance = True
if instance is not None:
self._api_clients = {instance: RuntimeClient(self._client_params)}
else:
self._api_clients = {}
instance_backends = self._resolve_cloud_instances(instance)
for inst, _ in instance_backends:
self._get_or_create_cloud_client(inst)

This code here is the main culprit:

  • The first issue is that if an instance name is passed in at initialization, the name instead of the crn will be the object key in self._api_clients which causes errors later because _get_api_client won't be able to find a client.

  • This logic is also flawed when an instance (name or crn) is saved in a account - _get_or_create_cloud_client() only adds the client to self._api_clients if the instance does not match the current active client instance. Since self._active_api_client is initialized a couple lines above (with the saved account instance), self._api_clients will remain empty which then also results in the no API client error.

  • I also realized that in the case where there are no instances and the service looks at all instances available, least_busy() was only using the current active instance. The instance parameter also would not have worked correctly.

Details and comments

Fixes #2358

Copy link

@psschwei psschwei left a comment

Choose a reason for hiding this comment

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

can confirm that after applying this patch I can create sessions again -- thanks for the quick fix !!

@kt474 kt474 added backport potential The bug might be minimal and/or important enough to be port to stable Changelog: Bugfix Include in the Fixed section of the changelog labels Aug 8, 2025
@kt474 kt474 marked this pull request as ready for review August 11, 2025 15:28
@kt474 kt474 changed the title Fix least_busy edge cases Fix account instance logic Aug 13, 2025
Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix, it LGTM and the tests look reasonable. I just found a couple of tiny tipos in the comments/reno.

kt474 and others added 2 commits August 18, 2025 11:01
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
@kt474 kt474 merged commit b938740 into Qiskit:main Aug 18, 2025
20 checks passed
@kt474 kt474 deleted the least-busy-edge-cases branch August 18, 2025 15:16
kt474 added a commit that referenced this pull request Aug 18, 2025
* Fix least_busy edge cases

* add release note

* add test

* update test

* update test and reno

* Update release-notes/unreleased/2359.bug.rst

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update test/integration/test_backend.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
@kt474 kt474 mentioned this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport potential The bug might be minimal and/or important enough to be port to stable Changelog: Bugfix Include in the Fixed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session creating failing with No API client found for given instance error on v0.41.0
3 participants