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

Session.from_id unexpectedly suppresses deprecation warnings. #1886

Open
dcanuto opened this issue Aug 22, 2024 · 1 comment
Open

Session.from_id unexpectedly suppresses deprecation warnings. #1886

dcanuto opened this issue Aug 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@dcanuto
Copy link

dcanuto commented Aug 22, 2024

Desribe the bug

When Session.from_id is called, internally it calls cls(service, backend) to create a Session instance, with backend set to a string. Unless it's intentional to suppress warnings from Session.__init__ when called from Session.from_id, this should raise two deprecation warnings (one for passing a service and one for backend as a string), but raises none.

Steps to reproduce

First, create a session instance and grab the ID:

from qiskit_ibm_runtime import Session, QiskitRuntimeService

service = QiskitRuntimeService() # account info previously saved
backend = service.least_busy(operational=True, simulator=False)
session = Session(backend=backend)

session_id = session.session_id

Next, regenerate the session from its ID:

regenerated_session = Session.from_id(session_id, service) # produces no warnings

Expected behavior

Deprecation warnings raised for service and backend as a string, as for example when I use Session.__init__ directly:

backend = service.least_busy(operational=True, simulator=False)
session = Session(service=service, backend=backend.name)

/var/folders/7_/rsgnsxr55d32q72f3m991h5r0000gn/T/ipykernel_33497/3846134487.py:6: DeprecationWarning: The service parameter is deprecated as of qiskit-ibm-runtime 0.26.0 and will be removed no sooner than 3 months after the release date. The service can be extracted from the backend object so it is no longer necessary.
  session = Session(service=service, backend=backend.name)
/var/folders/7_/rsgnsxr55d32q72f3m991h5r0000gn/T/ipykernel_33497/3846134487.py:6: DeprecationWarning: Passing a backend as a string is deprecated as of qiskit-ibm-runtime 0.26.0 and will be removed no sooner than 3 months after the release date. Use the actual backend object instead.
  session = Session(service=service, backend=backend.name)

Suggested solutions

Not sure how to solve the problem in its entirety, but part of the issue seems to be how issue_deprecation_msg is used in Session.__init__. As used there, the stacklevel passed to warnings.warn is 3 (default value of 2, plus one), which works when a session is created via __init__ directly. In that case, the stack is: issue_deprecation_msg -> Session.__init__ -> caller. But when Session.from_id is used, the stack is too deep: issue_deprecation_msg -> Session.__init__ -> Session.from_id -> caller.

Additional Information

  • qiskit-ibm-runtime version: 0.28.0
  • Python version: 3.11
  • Operating system: MacOS Sonoma 14.6.1
@dcanuto dcanuto added the bug Something isn't working label Aug 22, 2024
@kt474
Copy link
Member

kt474 commented Aug 23, 2024

@dcanuto thanks for noticing this, we'll have to refactor from_id()

@kt474 kt474 self-assigned this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants