Skip to content

Conversation

kt474
Copy link
Member

@kt474 kt474 commented Jul 15, 2025

Summary

Messed up my other two branches. This method is now significantly faster because we don't need to fetch every single backend configuration and compare the number of pending jobs.
Screenshot 2025-07-15 at 2 43 03 PM

Details and comments

Fixes #2240

@ElePT ElePT added enhancement New feature or request Changelog: New Feature Include in the Added section of the changelog labels Jul 16, 2025
@ElePT ElePT added this to the 0.41.0 milestone Jul 16, 2025
@kt474 kt474 requested a review from ElePT July 16, 2025 17:23
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 @kt474. The PR looks good to me, I just added a minor documentation comment and a broad question. Apart from this, I think that the PR is ready to merge.

Comment on lines 204 to 206
self._backends_list = self._active_api_client.list_backends()
if not self._backends_list:
self._backends_list = self._active_api_client.list_backends()
Copy link
Collaborator

Choose a reason for hiding this comment

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

if list_backends is going to be called anyways outside of the if-else, why not do:

Suggested change
self._backends_list = self._active_api_client.list_backends()
if not self._backends_list:
self._backends_list = self._active_api_client.list_backends()
if not self._backends_list:
self._backends_list = self._active_api_client.list_backends()

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it this way because an instance passed to backends() could be a different instance from the current active api instance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmmm I might be missing something, but it looks like both lines are calling the current active client?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to handle the case where:

service = QiskitRuntimeService() # No default instance 

service.backends(instance="instance1") # backends_list will only have backends from instance1

service.backends(instance="instance2") # backends_list needs to be refetched because the instance passed in is not the active instance

If self._backends_list is not None but has the backends from a different instance the backends from the wrong instance would be returned.

There might be a better way to handle this, as the way I did it here is not the most intuitive.

@@ -200,7 +199,8 @@ def _discover_backends_from_instance(self, instance: str) -> List[str]:
new_client = self._create_new_cloud_api_client(instance)
self._api_clients.update({instance: new_client})
self._active_api_client = new_client
return self._active_api_client.list_backends()
self._backends_list = self._active_api_client.list_backends()
return [backend["name"] for backend in self._backends_list]
# On staging there some invalid instances returned that 403 when retrieving backends
Copy link
Member Author

Choose a reason for hiding this comment

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

We still have to store the /backends API response somewhere in the service object. I think it's best to handle that here in _discover_backends_from_instance()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You meant better to handle that here than in _discover_backends_from_instance(), right? I agree

@kt474 kt474 merged commit 6f9148a into Qiskit:main Jul 30, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the Added section of the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance on least_busy operation
2 participants