Skip to content

Conversation

@kt474
Copy link
Member

@kt474 kt474 commented Oct 29, 2025

Summary

Adding warnings before job submission if the instance limit has been reached.

Details and comments

Fixes #2453

@kt474 kt474 added the Changelog: New Feature Include in the Added section of the changelog label Oct 29, 2025
@kt474 kt474 requested a review from ElePT October 29, 2025 19:05
@kt474
Copy link
Member Author

kt474 commented Oct 29, 2025

FYI @francabrera

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.

I added one quick question, and I agree that it would be good to get an additional review from @francabrera.

) - usage_dict.get("usage_consumed_seconds", 0)

if limit_reached:
if not usage_dict.get("usage_limit_seconds") or usage_remaining > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

One question, what if usage_dict.get("usage_limit_seconds") is 0? In this case I believe that not usage_dict.get("usage_limit_seconds") will evaluate to True, but according to the issue we only want it to evaluate to True if the value is None. Did I follow this correctly?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you on how the 0 case will be handled - depending on how the above conversation evolves, this line might not be present anymore.

usage_dict = self._active_api_client.cloud_usage()
limit_reached = usage_dict.get("usage_limit_reached", False)
usage_remaining = usage_dict.get(
"usage_limit_seconds", usage_dict.get("usage_allocation_seconds")
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why usage_allocation_seconds is used here? If the instance is limited the limit will be usage_limit_seconds.

If it's there is no limit in the instance, but usage_limit_reached is true, then we always display the message for the instance's plan on the account.

Copy link
Member

@diego-plan9 diego-plan9 Nov 28, 2025

Choose a reason for hiding this comment

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

It seems related to #1829 - the logic for the existing usage() method also involves usage_allocation_seconds():

def usage(self) -> Dict[str, Any]:
"""Return usage information for the current active instance.
Returns:
Dict with usage details.
"""
usage_dict = self._active_api_client.cloud_usage()
if usage_dict.get("usage_limit_seconds") or usage_dict.get("usage_allocation_seconds"):
usage_remaining = max(
usage_dict.get("usage_limit_seconds", usage_dict.get("usage_allocation_seconds"))
- usage_dict.get("usage_consumed_seconds", 0),
0,
)
usage_dict["usage_remaining_seconds"] = usage_remaining
return usage_dict

@francabrera , can you verify that taking into account usage_allocation_seconds (if usage_limit_seconds) for the calculation is correct? If it is, I think we can just take advantage of the existing method and piggyback on it.

@diego-plan9
Copy link
Member

Continuing this PR from Kevin (thanks!) - in d8c778b:

  • revised the logic to hopefully take into account review comments
  • made use of QiskitRuntimeService::usage() for reusing the interface (rather than on the raw API call)
  • added an extra entry to the test

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inform the user when submitting a job to an instance that has reached its limit

4 participants