Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
144 stars 153 forks source link

`TypeError: from_id() missing 1 required positional argument: 'service'` in `Session.from_id` with 0.15.0 #1228

Closed mriedem closed 9 months ago

mriedem commented 9 months ago

Describe the bug

This code started failing with version 0.15.0:

>       session = Session.from_id(session_id, backend=device)
E       TypeError: from_id() missing 1 required positional argument: 'service'

Steps to reproduce

Call Session.from_id without a service kwarg.

Expected behavior

What worked before should continue to work unless it's a major version breaking change.

Suggested solutions

Support the old interface.

Additional Information

mriedem commented 9 months ago

In this usage:

backend=device

device is a string name of a backend.

mriedem commented 9 months ago

From the release notes I see this:

The backend parameter in from_id() is being deprecated because sessions do not support multiple backends. Additionally, the service parameter is no longer optional.

How is that a bug fix and not something that goes through a deprecation period first since it's an interface change?

mriedem commented 9 months ago

There seems to be a related regression with this. It used to be that calling Session.from_id() with an invalid session ID would return an error message with the 4318 error code, bug I'm not seeing that now.

I have a very simple test like this:

def test_using_arbitrary_session_id_should_fail(service, device):
    session_id = 'test_using_arbitrary_session_id_should_fail'
    session = Session.from_id(session_id, service, backend=device)
    with pytest.raises(Exception) as ex:
        run_job(session=session)
        # https://internal-docs.quantum-computing.ibm.com/system-architecture/errors.html#c4318
        assert '4318' in str(ex)

After passing service into from_id() to workaround this issue, I'm getting a failure on the assertion because 4318 isn't in the error message - is that a regression in the client or the server? I can revert back to qiskit-ibm_runtime<0.15.0 to confirm.

mriedem commented 9 months ago

is that a regression in the client or the server? I can revert back to qiskit-ibm_runtime<0.15.0 to confirm.

It's another regression in 0.15.0, it works fine in 0.14.0:

$ TEST_DEVICE=fake_backend1 tox -e staging -- tests/test_sessions.py::test_using_arbitrary_session_id_should_fail                                
GLOB sdist-make: /home/osboxes/ibmq/iqp-channel-e2e-tests/setup.py
staging recreate: /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging
staging installdeps: pytest, qiskit-ibm-provider, qiskit-ibm-runtime>=0.13,<0.15
staging inst: /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/.tmp/package/1/iqp-channel-e2e-tests-0.0.1.zip
staging installed: certifi==2023.7.22,cffi==1.16.0,charset-normalizer==3.3.2,cryptography==41.0.5,dill==0.3.7,exceptiongroup==1.1.3,ibm-cloud-sdk-core==3.18.0,ibm-platform-services==0.47.0,idna==3.4,iniconfig==2.0.0,iqp-channel-e2e-tests==0.0.1,mpmath==1.3.0,numpy==1.24.4,packaging==23.2,pbr==6.0.0,pluggy==1.3.0,ply==3.11,psutil==5.9.6,pycparser==2.21,PyJWT==2.8.0,pyspnego==0.10.2,pytest==7.4.3,python-dateutil==2.8.2,qiskit==0.45.0,qiskit-ibm-provider==0.7.2,qiskit-ibm-runtime==0.14.0,qiskit-terra==0.45.0,requests==2.31.0,requests-ntlm==1.2.0,rustworkx==0.13.2,scipy==1.10.1,six==1.16.0,stevedore==5.1.0,symengine==0.9.2,sympy==1.12,tomli==2.0.1,typing-extensions==4.8.0,urllib3==2.1.0,websocket-client==1.6.4,websockets==12.0
staging run-test-pre: PYTHONHASHSEED='1052335426'
staging run-test: commands[0] | pytest -v tests/test_sessions.py::test_using_arbitrary_session_id_should_fail
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.10, pytest-7.4.3, pluggy-1.3.0 -- /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging/bin/python
cachedir: .tox/staging/.pytest_cache
rootdir: /home/osboxes/ibmq/iqp-channel-e2e-tests
configfile: tox.ini
collected 1 item                                                                                                                                                                            

tests/test_sessions.py::test_using_arbitrary_session_id_should_fail 
-------------------------------------------------------------------------------------- live log setup ---------------------------------------------------------------------------------------
""2023-11-17 12:50:37" [    INFO] getting service (conftest.py:28)"
""2023-11-17 12:50:43" [    INFO] got service (conftest.py:33)"
PASSED                                                                                                                                                                                [100%]

===================================================================================== warnings summary ======================================================================================
.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:170
  /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:170: DeprecationWarning: The class ``qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals`` is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. This algorithm utility has been migrated to an independent package: https://github.com/qiskit-community/qiskit-algorithms. You can run ``pip install qiskit_algorithms`` and import ``from qiskit_algorithms.utils`` instead. 
    algorithm_globals = QiskitAlgorithmGlobals()

.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:49
  /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:49: DeprecationWarning: The property ``qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals.num_processes`` is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. This algorithm utility belongs to a legacy workflow and has no replacement.
    self.num_processes = settings.get("num_processes", QiskitAlgorithmGlobals.CPU_COUNT)

.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:120
  /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging/lib/python3.8/site-packages/qiskit/utils/algorithm_globals.py:120: DeprecationWarning: The property ``qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals.num_processes`` is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. This algorithm utility belongs to a legacy workflow and has no replacement.
    parallel.CPU_COUNT = self.num_processes

.tox/staging/lib/python3.8/site-packages/qiskit/qpy/binary_io/circuits.py:27
  /home/osboxes/ibmq/iqp-channel-e2e-tests/.tox/staging/lib/python3.8/site-packages/qiskit/qpy/binary_io/circuits.py:27: PendingDeprecationWarning: The qiskit.extensions module is pending deprecation since Qiskit 0.45.0. It will be deprecated in a following release, no sooner than 3 months after the 0.45.0 release.
    from qiskit import extensions

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================================================== 1 passed, 4 warnings in 7.59s ===============================================================================
__________________________________________________________________________________________ summary __________________________________________________________________________________________
  staging: commands succeeded
  congratulations :)
kt474 commented 9 months ago

I'll revert the change and do a patch release 0.15.1