I have code which runs on the IBMQ website perfectly, however copying and pasting the same code (and including my API token) the same code does not run when I try and run it on a real quantum computer from Jupyter notebook. My code is :
import math
import certifi
import matplotlib.pyplot as plt
import numpy as np
from math import pi
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute, Aer,BasicAer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from qiskit.tools.visualization import circuit_drawer
from qiskit.quantum_info import state_fidelity
backend = BasicAer.get_backend('unitary_simulator')
IBMQ.save_account('My_token', overwrite=True)
IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q-research')
#circuit I want to run
def circtest(x1,x2,shotsin):
maxShot=shotsin
import random
zz=[x1,x2]
qr=QuantumRegister(1)
my_layout={qr[0]:4}
circuit2 = QuantumCircuit();
circuit2.add_register(qr)
cr=ClassicalRegister(1)
circuit2.add_register(cr)
circuit2.initialize(zz,0)
circuit2.measure(0,0);
device = provider.get_backend('ibmq_casablanca')
Cfin=circuit2;
result = execute(circuit2,backend=device,shots=maxShot).result()
counts = result.get_counts(0)
return counts
However running the simple test
#simple test
circtest(1,0,100)
returns the following error:
---------------------------------------------------------------------------
SSLCertVerificationError Traceback (most recent call last)
<ipython-input-3-8d451fe64647> in <module>
1 #simple test
----> 2 totcirc1Qx(1,0,100)
<ipython-input-2-5ff78fcf31bb> in totcirc1Qx(x1, x2, shotsin)
23 device = provider.get_backend('ibmq_casablanca')
24 Cfin=circuit2;
---> 25 result = execute(circuit2,backend=device,shots=maxShot).result()
26
27 counts = result.get_counts(0)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/job/ibmqjob.py in result(self, timeout, wait, partial, refresh)
274 """
275 # pylint: disable=arguments-differ
--> 276 if not self._wait_for_completion(timeout=timeout, wait=wait,
277 required_status=(JobStatus.DONE,)):
278 if self._status is JobStatus.CANCELLED:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/job/ibmqjob.py in _wait_for_completion(self, timeout, wait, required_status, status_queue)
909
910 try:
--> 911 status_response = self._api_client.job_final_status(
912 self.job_id(), timeout=timeout, wait=wait, status_queue=status_queue)
913 except UserTimeoutExceededError:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/account.py in job_final_status(self, job_id, timeout, wait, status_queue)
367 start_time = time.time()
368 try:
--> 369 status_response = self._job_final_status_websocket(
370 job_id=job_id, timeout=timeout, status_queue=status_queue)
371 except WebsocketTimeoutError as ex:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/account.py in _job_final_status_websocket(self, job_id, timeout, status_queue)
419 else:
420 raise
--> 421 return loop.run_until_complete(
422 self.client_ws.get_job_status(job_id, timeout=timeout, status_queue=status_queue))
423
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nest_asyncio.py in run_until_complete(self, future)
68 raise RuntimeError(
69 'Event loop stopped before Future completed.')
---> 70 return f.result()
71
72 def _run_once(self):
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/futures.py in result(self)
199 self.__log_traceback = False
200 if self._exception is not None:
--> 201 raise self._exception
202 return self._result
203
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py in __step(***failed resolving arguments***)
256 result = coro.send(None)
257 else:
--> 258 result = coro.throw(exc)
259 except StopIteration as exc:
260 if self._must_cancel:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/websocket.py in get_job_status(self, job_id, timeout, retries, backoff_factor, status_queue)
256 while current_retry_attempt <= retries:
257 try:
--> 258 websocket = await self._connect(url)
259 # Read messages from the server until the connection is closed or
260 # a timeout has been reached.
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/websocket.py in _connect(self, url)
165 # Isolate specific exceptions, so they are not retried in `get_job_status`.
166 except (SSLError, InvalidURI) as ex:
--> 167 raise ex
168
169 # pylint: disable=broad-except
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/websocket.py in _connect(self, url)
161 try:
162 logger.debug('Starting new websocket connection: %s', url)
--> 163 websocket = await connect(url)
164
165 # Isolate specific exceptions, so they are not retried in `get_job_status`.
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py in __await_impl__(self)
620 async def __await_impl__(self) -> WebSocketClientProtocol:
621 for redirects in range(self.MAX_REDIRECTS_ALLOWED):
--> 622 transport, protocol = await self._create_connection()
623 # https://github.com/python/typeshed/pull/2756
624 transport = cast(asyncio.Transport, transport)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py in create_connection(self, protocol_factory, host, port, ssl, family, proto, flags, sock, local_addr, server_hostname, ssl_handshake_timeout, happy_eyeballs_delay, interleave)
1079 f'A Stream Socket was expected, got {sock!r}')
1080
-> 1081 transport, protocol = await self._create_connection_transport(
1082 sock, protocol_factory, ssl, server_hostname,
1083 ssl_handshake_timeout=ssl_handshake_timeout)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py in _create_connection_transport(self, sock, protocol_factory, ssl, server_hostname, server_side, ssl_handshake_timeout)
1109
1110 try:
-> 1111 await waiter
1112 except:
1113 transport.close()
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/futures.py in __await__(self)
282 if not self.done():
283 self._asyncio_future_blocking = True
--> 284 yield self # This tells Task to wait for completion.
285 if not self.done():
286 raise RuntimeError("await wasn't used with future")
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py in __wakeup(self, future)
326 def __wakeup(self, future):
327 try:
--> 328 future.result()
329 except BaseException as exc:
330 # This may also be a cancellation.
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/futures.py in result(self)
199 self.__log_traceback = False
200 if self._exception is not None:
--> 201 raise self._exception
202 return self._result
203
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py in data_received(self, data)
526
527 try:
--> 528 ssldata, appdata = self._sslpipe.feed_ssldata(data)
529 except (SystemExit, KeyboardInterrupt):
530 raise
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py in feed_ssldata(self, data, only_handshake)
186 if self._state == _DO_HANDSHAKE:
187 # Call do_handshake() until it doesn't raise anymore.
--> 188 self._sslobj.do_handshake()
189 self._state = _WRAPPED
190 if self._handshake_cb:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py in do_handshake(self)
942 def do_handshake(self):
943 """Start the SSL/TLS handshake."""
--> 944 self._sslobj.do_handshake()
945
946 def unwrap(self):
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1122)
I assume I am just missing some way in which I can communicate with the actual devices but I am not sure what this is
/Applications/Python\ <version>/Install\ Certificates.command
directly into terminal? $\endgroup$