unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
368 stars 163 forks source link

mitiq garage or mitiq carpentry #192

Closed nathanshammah closed 4 years ago

nathanshammah commented 4 years ago

Ask workshop attendees, upon invitation, to communicate or bring their pet algorithm to the mitiq garage.

nathanshammah commented 4 years ago

@rmlarose can you check how to use the IBM token to make the IBM Q tutorial work on the jupyterhub? I updated it and it gives me, predictably, this error:

HTTPError: 400 Client Error: Bad Request for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken

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

RequestsApiError                          Traceback (most recent call last)
<ipython-input-3-104b2c77b8bc> in <module>
      1 """Enable IBMQ account to use backends."""
----> 2 provider = qiskit.IBMQ.enable_account(token="")

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/ibmqfactory.py in enable_account(self, token, url, **kwargs)
     94 
     95         # Initialize the providers.
---> 96         self._initialize_providers(credentials)
     97 
     98         # Prevent edge case where no hubs are available.

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/ibmqfactory.py in _initialize_providers(self, credentials)
    377         auth_client = AuthClient(credentials.token,
    378                                  credentials.base_url,
--> 379                                  **credentials.connection_parameters())
    380         service_urls = auth_client.current_service_urls()
    381         user_hubs = auth_client.user_hubs()

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/api/clients/auth.py in __init__(self, api_token, auth_url, **request_kwargs)
     41 
     42         self.client_auth = Auth(RetrySession(auth_url, **request_kwargs))
---> 43         self.client_api = self._init_service_clients(**request_kwargs)
     44 
     45     def _init_service_clients(self, **request_kwargs: Any) -> Api:

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/api/clients/auth.py in _init_service_clients(self, **request_kwargs)
     53         """
     54         # Request an access token.
---> 55         access_token = self._request_access_token()
     56         # Use the token for the next auth server requests.
     57         self.client_auth.session.access_token = access_token

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/api/clients/auth.py in _request_access_token(self)
     75         """
     76         try:
---> 77             response = self.client_auth.login(self.api_token)
     78             return response['id']
     79         except RequestsApiError as ex:

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/api/rest/auth.py in login(self, api_token)
     37         """
     38         url = self.get_url('login')
---> 39         return self.session.post(url, json={'apiToken': api_token}).json()
     40 
     41     def user_info(self) -> Dict[str, Any]:

/opt/tljh/user/lib/python3.7/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    579         """
    580 
--> 581         return self.request('POST', url, data=data, json=json, **kwargs)
    582 
    583     def put(self, url, data=None, **kwargs):

/opt/tljh/user/lib/python3.7/site-packages/qiskit/providers/ibmq/api/session.py in request(self, method, url, bare, **kwargs)
    237                 self._modify_chained_exception_messages(ex)
    238 
--> 239             raise RequestsApiError(message) from ex
    240 
    241         return response

RequestsApiError: '400 Client Error: Bad Request for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken. API key not found., Error code: 3402.'

If you find a way to make it work, we can add this bit of information in the notebook itself. "If you are running it from JupyterHub, ..."

nathanshammah commented 4 years ago

I wonder if this issue is related, but I think not. On the JupyterHub, this is the mitiq.about() table

Mitiq: A Python toolkit for implementing 
error mitigation on quantum computers.
========================================
Mitiq team – 2020 and later.
See https://github.com/unitaryfund/mitiq for details.

Mitiq Version:      0.1a1
Numpy Version:      1.18.4
Scipy Version:      1.4.1
Cirq Version:       0.8.1
Pyquil Version:     2.18.0
Qiskit Version:     0.12.0
Python Version:     3.7.7
Platform Info:      Linux (x86_64)
Installation path:  /home/jupyter-nathan/mitiq-0.1a1/mitiq
nathanshammah commented 4 years ago

Ok, just by copying the token from my IBM Q account worked fine for the notebook on jupyterhub. So this seems solved. On my machine I saved my account.

@rmlarose, I was noticing: The notebook takes a bit to run, also on the hub. Could you change its workshop version a bit so that it takes less to run? Already in Part 1,

"""Run this cell to do zero-noise extrapolation with the custom factory."""

this cell takes a while.

rmlarose commented 4 years ago

Unfortunately the runtime is determined by the queue. That's the cell which takes the longest to run because the factory sends jobs sequentially. After that they are batched.

The only way to speed it up is to use a simulator, but that would involved adding noise to the circuit.