Pennylane-qiskit help

As of July 1st, following IBM’s expansion of its cloud services, it seems that a major update has been rolled out, upgrading Qiskit to version 2.0. Since then, we have been encountering compatibility issues between Qiskit and other packages.

Specifically, we experienced a hardware connection problem.

According to IBM’s official tutorials, we were able to successfully connect using QiskitRuntimeService and make the backend. However, the issue arises when attempting to access the backend through PennyLane. It appears that there is a dependency conflict between Qiskit and the pennylane-qiskit plugin.

Moreover, we noticed that using the latest GitHub version (0.42-dev) or the official release 0.41.0.post0 of pennylane-qiskit does not resolve the issue. In fact, installing the latest development version via GitHub throws a 404 Not Found error.

We would appreciate it if you could look into the compatibility between Qiskit 2.0 and pennylane-qiskit, and let us know if there are any patches, workarounds, or specific versions we should use to ensure successful integration.

# Put code here
from qiskit_ibm_runtime import QiskitRuntimeService
import pennylane as qml

QiskitRuntimeService.save_account(channel="ibm_quantum_platform", 
                                  token="token",
                                  instance="instance", 
                                  overwrite=True)
service = QiskitRuntimeService()
backend = service.backend(name='backend')
dev = qml.device("qiskit.remote", wires=127, backend=backend, seed_transpiler=42)

If you want help with diagnosing an error, please put the full error message below:

# Put full error message here
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/session.py:329, in RetrySession.request(self, method, url, bare, **kwargs)
    328     response = super().request(method, final_url, headers=headers, **kwargs)
--> 329     response.raise_for_status()
    330 except RequestException as ex:
    331     # Wrap the requests exceptions into a IBM Q custom one, for
    332     # compatibility.

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/requests/models.py:1026, in Response.raise_for_status(self)
   1025 if http_error_msg:
-> 1026     raise HTTPError(http_error_msg, response=self)

HTTPError: 401 Client Error: Unauthorized for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken

The above exception was the direct cause of the following exception:

IBMNotAuthorizedError                     Traceback (most recent call last)
Cell In[4], line 4
      1 from qiskit_ibm_runtime import QiskitRuntimeService
      2 import pennylane as qml
----> 4 service = QiskitRuntimeService()
      5 backend = service.backend(name='ibm_yonsei')

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:163, in QiskitRuntimeService.__init__(self, channel, token, url, filename, name, instance, proxies, verify, channel_strategy, private_endpoint)
    161     self._validate_channel_strategy()
    162 else:
--> 163     auth_client = self._authenticate_ibm_quantum_account(self._client_params)
    164     # Update client parameters to use authenticated values.
    165     self._client_params.url = auth_client.current_service_urls()["services"]["runtime"]

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:322, in QiskitRuntimeService._authenticate_ibm_quantum_account(self, client_params)
    315 if not version_info["new_api"] or "api-auth" not in version_info:
    316     raise IBMInputValueError(
    317         "The URL specified ({}) is not an IBM Quantum authentication URL. "
    318         "Valid authentication URL: {}.".format(
    319             client_params.url, QISKIT_IBM_RUNTIME_API_URL
    320         )
    321     )
--> 322 auth_client = AuthClient(client_params)
    323 service_urls = auth_client.current_service_urls()
    324 if not service_urls.get("services", {}).get(SERVICE_NAME):

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/clients/auth.py:39, in AuthClient.__init__(self, client_params)
     36 self._service_urls = {}  # type: ignore[var-annotated]
     38 self.auth_api = Api(RetrySession(self.auth_url, **client_params.connection_parameters()))
---> 39 self.base_api = self._init_service_clients(**client_params.connection_parameters())

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/clients/auth.py:51, in AuthClient._init_service_clients(self, **request_kwargs)
     42 """Initialize the clients used for communicating with the API.
     43 
     44 Args:
   (...)
     48     Client for the API server.
     49 """
     50 # Request an access token.
---> 51 self.access_token = self._request_access_token()
     52 self.auth_api.session.auth = QuantumAuth(access_token=self.access_token)
     53 self._service_urls = self.user_urls()

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/clients/auth.py:77, in AuthClient._request_access_token(self)
     67 """Request a new access token from the API authentication service.
     68 
     69 Returns:
   (...)
     74     RequestsApiError: If the request failed.
     75 """
     76 try:
---> 77     response = self.auth_api.login(self.api_token)
     78     return response["id"]
     79 except RequestsApiError as ex:
     80     # Get the original exception that raised.

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/rest/root.py:92, in Api.login(self, api_token)
     83 """Login with token.
     84 
     85 Args:
   (...)
     89     JSON response.
     90 """
     91 url = self.get_url("login")
---> 92 return self.session.post(url, json={"apiToken": api_token}).json()

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/requests/sessions.py:637, in Session.post(self, url, data, json, **kwargs)
    626 def post(self, url, data=None, json=None, **kwargs):
    627     r"""Sends a POST request. Returns :class:`Response` object.
    628 
    629     :param url: URL for the new :class:`Request` object.
   (...)
    634     :rtype: requests.Response
    635     """
--> 637     return self.request("POST", url, data=data, json=json, **kwargs)

File ~/miniconda3/envs/qiskit_2/lib/python3.10/site-packages/qiskit_ibm_runtime/api/session.py:350, in RetrySession.request(self, method, url, bare, **kwargs)
    348             message += f". {ex.response.text}"
    349     if status_code == 401:
--> 350         raise IBMNotAuthorizedError(message) from ex
    351     raise RequestsApiError(message, status_code) from ex
    353 return response

IBMNotAuthorizedError: '401 Client Error: Unauthorized for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken. Login failed., Error code: 3446.' 

Hi @hicho ,

Thank you for reporting this.
Do you know if the issue is present both with IBM’s open plan and premium plan? Or is this limited to one of the two?
From the tests you have done, would you say this is reproducible with both hardware and simulators, or only one of the two?

Unfortunately IBM’s big change came at a bad time because the next PennyLane release will happen in just over a week so we won’t be able to implement and test any new changes in time.

We’ll be looking into fixing this issue after the release, so hopefully we can get everything working well in Master soon after :crossed_fingers: .

We’ll let you know if we have any follow-up questions or updates.

Thanks again for bringing this to our attention :heart: .

Thank you for answering my question. I’m a premium IBM Quantum user and haven’t tested it with the open plan.
In the past, it was possible to run experiments on IBM Quantum hardware directly through PennyLane, but since the transition to Qiskit Runtime, integration has been discontinued.
From that experience, I’ve observed that there was always a noticeable difference between the simulator and the hardware, and minimizing that gap remains one of the key challenges in our research.

I’m looking forward to the next PennyLane release, and I appreciate all your hard work.

Hi @hicho ,

Thanks for this info.

One of my colleagues ran a test with PennyLane=v0.42.0.dev37 (the PennyLane version that will be released next week) on the pennylane-qiskit master branch. They don’t get any errors running code on either real hardware or simulator. (On Qiskit v1.2.4, qiskit-ibm-runtime v0.29.0)

Is it possible for you to use Qiskit v1.2.4 instead of Qiskit 2.0? Or are you limited to using the latest Qiskit version?

I downloaded the latest version of PennyLane from GitHub and ran some tests related to Qiskit v1.2.4 and qiskit-ibm-runtime v0.29.0. I encountered a 404 Not Found error, which seemed to be caused by IBM no longer supporting the previous channel “ibm_quantum”.

But, I fixed the issue by changing the code in qiskit-ibm-runtime and pennylane-qiskit modules.

The issue has been resolved, so it can be closed.
Thank you!

I’m glad you resolved it @hicho !

If you can share the details of what you changed here it might help others having similar problems in the future. Please make sure NOT to share your API key though.