0
$\begingroup$

I am trying to connect from a jupyter notebook to IBM quantum computing instance with the following code:

from qiskit_ibm_runtime import QiskitRuntimeService service = QiskitRuntimeService(token="API_KEY", channel="ibm_quantum_platform", url="https://quantum.cloud.ibm.com/") backend = service.least_busy(simulator=False, operational=True) # Convert to an ISA circuit and layout-mapped observables. pm = generate_preset_pass_manager(backend=backend, optimization_level=1) isa_circuit = pm.run(qc) isa_circuit.draw("mpl", idle_wires=False) 

Upon execution, the code throws the following error:

--------------------------------------------------------------------------- gaierror Traceback (most recent call last) File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self) 197 try: --> 198 sock = connection.create_connection( 199 (self._dns_host, self.port), 200 self.timeout, 201 source_address=self.source_address, 202 socket_options=self.socket_options, 203 ) 204 except socket.gaierror as e:

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/util/connection.py:60, in create_connection(address, timeout, source_address, socket_options) 58 raise LocationParseError(f"'{host}', label empty or too long") from None ---> 60 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 61 af, socktype, proto, canonname, sa = res

File /usr/lib/python3.11/socket.py:962, in getaddrinfo(host, port, family, type, proto, flags) 961 addrlist = [] --> 962 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 963 af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

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

NameResolutionError Traceback (most recent call last) File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw) 786 # Make the request on the HTTPConnection object --> 787 response = self._make_request( 788 conn, 789 method, 790 url, 791 timeout=timeout_obj, 792 body=body, 793 headers=headers, 794 chunked=chunked, 795 retries=retries, 796 response_conn=response_conn, 797 preload_content=preload_content, 798 decode_content=decode_content, 799 **response_kw, 800 ) 802 # Everything went great!

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connectionpool.py:488, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 487 new_e = _wrap_proxy_error(new_e, conn.proxy.scheme) --> 488 raise new_e 490 # conn.request() calls http.client.*.request, not the method in 491 # urllib3.request. It also calls makefile (recv) on the socket.

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connectionpool.py:464, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 463 try: --> 464 self._validate_conn(conn) 465 except (SocketTimeout, BaseSSLError) as e:

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connectionpool.py:1093, in HTTPSConnectionPool._validate_conn(self, conn) 1092 if conn.is_closed: -> 1093 conn.connect() 1095 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connection.py:753, in HTTPSConnection.connect(self) 752 sock: socket.socket | ssl.SSLSocket --> 753 self.sock = sock = self._new_conn() 754 server_hostname: str = self.host

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connection.py:205, in HTTPConnection._new_conn(self) 204 except socket.gaierror as e: --> 205 raise NameResolutionError(self.host, self, e) from e 206 except SocketTimeout as e:

NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x7f6491470dd0>: Failed to resolve 'iam.quantum.cloud.ibm.com' ([Errno -2] Name or service not known)

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

MaxRetryError Traceback (most recent call last) File ~/Venvs/pyQC/lib/python3.11/site-packages/requests/adapters.py:644, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 643 try: --> 644 resp = conn.urlopen( 645 method=request.method, 646 url=url, 647 body=request.body, 648 headers=request.headers, 649 redirect=False, 650 assert_same_host=False, 651 preload_content=False, 652 decode_content=False, 653 retries=self.max_retries, 654 timeout=timeout, 655 chunked=chunked, 656 ) 658 except (ProtocolError, OSError) as err:

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/connectionpool.py:841, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw) 839 new_e = ProtocolError("Connection aborted.", new_e) --> 841 retries = retries.increment( 842 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2] 843 ) 844 retries.sleep()

File ~/Venvs/pyQC/lib/python3.11/site-packages/urllib3/util/retry.py:519, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 518 reason = error or ResponseError(cause) --> 519 raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 521 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='iam.quantum.cloud.ibm.com', port=443): Max retries exceeded with url: /identity/token (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f6491470dd0>: Failed to resolve 'iam.quantum.cloud.ibm.com' ([Errno -2] Name or service not known)"))

During handling of the above exception, another exception occurred:

ConnectionError Traceback (most recent call last) File ~/Venvs/pyQC/lib/python3.11/site-packages/qiskit_ibm_runtime/accounts/account.py:327, in CloudAccount.list_instances(self) 326 try: --> 327 result = client.search( 328 query="service_name:quantum-computing", 329 fields=[ 330 "crn", 331 "service_plan_unique_id", 332 "name", 333 "doc", 334 "tags", 335 ], 336 search_cursor=search_cursor, 337 limit=100, 338 ).get_result() 339 except:

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_platform_services/global_search_v2.py:236, in GlobalSearchV2.search(self, query, fields, search_cursor, x_request_id, x_correlation_id, account_id, limit, timeout, sort, is_deleted, is_reclaimed, is_public, impersonate_user, can_tag, is_project_resource, **kwargs) 235 url = '/v3/resources/search' --> 236 request = self.prepare_request( 237 method='POST', 238 url=url, 239 headers=headers, 240 params=params, 241 data=data, 242 ) 244 response = self.send(request, **kwargs)

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/base_service.py:441, in BaseService.prepare_request(self, method, url, headers, params, data, files, **kwargs) 439 request['data'] = data --> 441 self.authenticator.authenticate(request) 443 # Compress the request body if applicable

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/authenticators/iam_request_based_authenticator.py:64, in IAMRequestBasedAuthenticator.authenticate(self, req) 63 headers = req.get('headers') ---> 64 bearer_token = self.token_manager.get_token() 65 headers['Authorization'] = 'Bearer {0}'.format(bearer_token)

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/token_managers/token_manager.py:82, in TokenManager.get_token(self) 81 logger.debug('Performing synchronous token fetch') ---> 82 self.paced_request_token() 84 if self._token_needs_refresh():

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/token_managers/token_manager.py:141, in TokenManager.paced_request_token(self) 140 if not request_active: --> 141 token_response = self.request_token() 142 self._save_token_info(token_response)

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/token_managers/iam_request_based_token_manager.py:127, in IAMRequestBasedTokenManager.request_token(self) 126 logger.debug('Invoking IAM get_token operation: %s', request_url) --> 127 response = self._request( 128 method='POST', 129 url=request_url, 130 headers=request_headers, 131 data=data, 132 auth_tuple=auth_tuple, 133 proxies=self.proxies, 134 ) 135 logger.debug('Returned from IAM get_token operation')

File ~/Venvs/pyQC/lib/python3.11/site-packages/ibm_cloud_sdk_core/token_managers/jwt_token_manager.py:85, in JWTTokenManager._request(self, method, url, headers, params, data, auth_tuple, **kwargs) 83 kwargs['verify'] = False ---> 85 response = requests.request( 86 method=method, url=url, headers=headers, params=params, data=data, auth=auth_tuple, **kwargs 87 ) 88 if 200 <= response.status_code <= 299:

File ~/Venvs/pyQC/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs) 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, **kwargs)

File ~/Venvs/pyQC/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 588 send_kwargs.update(settings) --> 589 resp = self.send(prep, **send_kwargs) 591 return resp

File ~/Venvs/pyQC/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs) 702 # Send the request --> 703 r = adapter.send(request, **kwargs) 705 # Total elapsed time of the request (approximately)

File ~/Venvs/pyQC/lib/python3.11/site-packages/requests/adapters.py:677, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 675 raise SSLError(e, request=request) --> 677 raise ConnectionError(e, request=request) 679 except ClosedPoolError as e:

ConnectionError: HTTPSConnectionPool(host='iam.quantum.cloud.ibm.com', port=443): Max retries exceeded with url: /identity/token (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f6491470dd0>: Failed to resolve 'iam.quantum.cloud.ibm.com' ([Errno -2] Name or service not known)"))

During handling of the above exception, another exception occurred:

InvalidAccountError Traceback (most recent call last) Cell In[8], line 4 1 from qiskit_ibm_runtime import QiskitRuntimeService 3 # service = QiskitRuntimeService(instance="crn:v1:bluemix:public:quantum-computing:us-east:a/0bd68fd6ab0d4d84853348a2b182e20d:fcf24b6f-e246-4f08-bd48-e17eb5db8628::") ----> 4 service = QiskitRuntimeService(token="a3nYPxnZ_9PV3ow9ZV-5TGpDuYPevHQ8cjQmmDFHmrW0",

 5 channel="ibm_quantum_platform", 6 url="https://quantum.cloud.ibm.com/") 7 backend = service.least_busy(simulator=False, operational=True) 9 # Convert to an ISA circuit and layout-mapped observables. 

File ~/Venvs/pyQC/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:184, in QiskitRuntimeService.init(self, channel, token, url, filename, name, instance, proxies, verify, private_endpoint, url_resolver, region, plans_preference, tags) 182 else: 183 self._api_clients = {} --> 184 instance_backends = self._resolve_cloud_instances(instance) 185 for inst, _ in instance_backends: 186 self._get_or_create_cloud_client(inst)

File ~/Venvs/pyQC/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:535, in QiskitRuntimeService._resolve_cloud_instances(self, instance) 533 return [(default_crn, self._discover_backends_from_instance(default_crn))] 534 if not self._all_instances: --> 535 self._all_instances = self._account.list_instances() 536 logger.warning( 537 "Default instance not set. Searching all available instances.", 538 ) 539 if not self._backend_instance_groups:

File ~/Venvs/pyQC/lib/python3.11/site-packages/qiskit_ibm_runtime/accounts/account.py:340, in CloudAccount.list_instances(self) 327 result = client.search( 328 query="service_name:quantum-computing", 329 fields=[ (...) 337 limit=100, 338 ).get_result() 339 except: --> 340 raise InvalidAccountError("Unable to retrieve instances.") 341 crns = [] 342 items = result.get("items", [])

InvalidAccountError: 'Unable to retrieve instances.'

I am trying to run the Hello World example. Could someone shed some light as to where am I making the mistake and how to correct that?

$\endgroup$

1 Answer 1

1
$\begingroup$

Just replace your following code :

 service = QiskitRuntimeService(token=token, channel="ibm_quantum_platform", url="https://quantum.cloud.ibm.com/") 

with this code:

token = "your-api-token" QiskitRuntimeService.save_account(channel="ibm_cloud", token=token, set_as_default=True, overwrite=True) service = QiskitRuntimeService() 

Please note that save_account method saves your credentials locally, so you can skip that method next time.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.