qilimanjaro-tech / qiboconnection

Python library that allows you to execute quantum programs on Qilimanjaro's QPUs and simulators.
Apache License 2.0
19 stars 2 forks source link

[BUG] Client error raised when calling `api.get_results` #93

Closed AlbertMitjans closed 1 year ago

AlbertMitjans commented 1 year ago

I was running the following code:

from time import sleep

import numpy as np
from qibo.gates import M, X
from qibo.models import Circuit
from qiboconnection.api import API
from qiboconnection.connection import ConnectionConfiguration

api = API(ConnectionConfiguration(username="qat", api_key="meow"))

api.select_device_id(9)

ids0 = []
ids1 = []
qubits = np.arange(5)

for qubit in qubits:
    circuit = Circuit(5)
    circuit.add(M(qubit))

    circuit1 = Circuit(5)
    circuit1.add(X(qubit))
    circuit1.add(M(qubit))

    ids0.append(api.execute(circuit, nshots=1000))
    ids1.append(api.execute(circuit1, nshots=1000))

for qubit_idx, id0, id1 in zip(qubits, ids0, ids1):
    results0 = None
    results1 = None
    while results0 is None or results1 is None:
        results0 = api.get_results(id0)[0]
        results1 = api.get_results(id1)[0]
        sleep(5)

    clf_0 = (1 - results0["probabilities"]["0"] + results0["probabilities"]["1"]) / 2
    clf_1 = (1 - results1["probabilities"]["0"] + results1["probabilities"]["1"]) / 2
    fid_avg = (1 - clf_0 + clf_1) / 2
    print(f"### QUBIT: {qubit} ###")
    print(f"Ground state: {results0}")
    print(f"Excited state: {results1}")
    print("Fidelity", fid_avg)

And got the following output:

[qibo-connection] 0.12.0|INFO|2023-10-03 11:56:58]: Storing personal qibo configuration...
[qibo-connection] 0.12.0|INFO|2023-10-03 11:56:59]: Device Galadriel Qblox rack selected.
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:08]: Your job with id 1202 is still pending. Job queue position: 7
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:08]: Your job with id 1203 is still pending. Job queue position: 8
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:13]: Your job with id 1202 is still pending. Job queue position: 6
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:14]: Your job with id 1203 is still pending. Job queue position: 7
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:19]: Your job with id 1202 is still pending. Job queue position: 6
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:20]: Your job with id 1203 is still pending. Job queue position: 7
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:25]: Your job with id 1202 is still pending. Job queue position: 5
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:26]: Your job with id 1203 is still pending. Job queue position: 6
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:31]: Your job with id 1202 is still pending. Job queue position: 5
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:32]: Your job with id 1203 is still pending. Job queue position: 6
[qibo-connection] 0.12.0|WARNING|2023-10-03 11:57:37]: Your job with id 1202 is still pending. Job queue position: 5
Traceback (most recent call last):
  File "/Users/albertmitjans/Developer/qililab/dummy/BSC scripts/qiboconnection/readout_fidelities.py", line 33, in <module>
    results1 = api.get_results(id1)[0]
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/typeguard/__init__.py", line 1033, in wrapper
    retval = func(*args, **kwargs)
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/api.py", line 437, in get_results
    job_responses = [self._get_job(job_id) for job_id in job_ids]
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/api.py", line 437, in <listcomp>
    job_responses = [self._get_job(job_id) for job_id in job_ids]
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/api.py", line 396, in _get_job
    response, status_code = self._connection.send_get_auth_remote_api_call(path=f"{self.JOBS_CALL_PATH}/{job_id}")
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/connection.py", line 47, in decorated
    raise ex
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/connection.py", line 44, in decorated
    return func(self, *args, **kwargs)
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/typeguard/__init__.py", line 1033, in wrapper
    retval = func(*args, **kwargs)
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/qiboconnection/connection.py", line 370, in send_get_auth_remote_api_call
    response.raise_for_status()
  File "/Users/albertmitjans/Developer/qililab/.venv/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://qilimanjaroqaas.ddns.net:8080/api/v1/jobs/1203

Any idea what might be happening?

ziiiki commented 1 year ago

This is probably an error thrown by nginx to avoid DDoS attacks. There three facts that support this hypothesis: 1- Time needed for the error to appear is not the same between executions.

  1. The time needed depends on the sleep() value, the greater the more time needed for the error to appear 3- Despite the error, all jobs are run successfully so this is not related to our source code.

Assuming we are pointing to the right the direction, this is an evidence of lack of scalability of our current system, although we can probably modify nginx configuration to avoid that. How urgent is this issue? We don't think it is critical by now since the rest of the users aren't using while loops, probably.