Skip to content

Commit

Permalink
Merge pull request #47 from qiboteam/apichange
Browse files Browse the repository at this point in the history
API updates
  • Loading branch information
scarrazza authored Jul 2, 2024
2 parents 56b2f6b + a86cf01 commit c04b5d6
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 76 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ pip install qibo-client

## Quick start

Once installed, the provider allows to run quantum circuit computations on the
TiiQ remote server.
Once installed, the provider allows to run quantum circuit computations on remote labs using Qibo.

:warning: Note: to run jobs on the remote cluster it is mandatory to own a
validated account.
Please, sign up to [this link](https://cloud.qibo.science) to
obtain the needed token to run computations on the cluster.

The following snippet provides a basic usage example.
Replace the `your-tii-qrc-token` string with your user token received during the
Replace the `your-token` string with your user token received during the
registration process.

```python
Expand All @@ -43,8 +42,8 @@ import qibo_client
circuit = qibo.models.QFT(5)

# authenticate to server through the client instance
token = "your-tii-qrc-token"
client = qibo_client.TII(token)
token = "your-token"
client = qibo_client.Client(token)

# run the circuit
result = client.run_circuit(circuit, nshots=1000, device="sim")
Expand Down
4 changes: 2 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ receive after registration.

.. code-block:: python
>>> from qibo_client import TII
>>> from qibo_client import Client
>>> import qibo
>>> circuit = qibo.models.QFT(5)
>>> client = TII("your qibo token")
>>> client = Client("your qibo token")
>>> result = client.run_circuit(circuit, nshots=100, device="sim")
>>> print(result)
Expand Down
8 changes: 0 additions & 8 deletions doc/source/qibo_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ qibo\_client.qibo\_client module
:undoc-members:
:show-inheritance:

qibo\_client.tii module
-----------------------

.. automodule:: qibo_client.tii
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
4 changes: 2 additions & 2 deletions examples/run_error_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import qibo

from qibo_client import TII
from qibo_client import Client

# create the circuit you want to run
circuit = qibo.models.QFT(11)
Expand All @@ -13,7 +13,7 @@
token = f.read()

# authenticate to server through the client instance
client = TII(token)
client = Client(token)

# run the circuit
print(f"{'*'*20}\nPost first circuit")
Expand Down
4 changes: 2 additions & 2 deletions examples/run_ping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from pathlib import Path

from qibo_client import TII
from qibo_client import Client

# read the token from file
token_path = Path(__file__).parent / "token.txt"
Expand All @@ -10,5 +10,5 @@

# authenticate to server through the client instance
start = time.time()
client = TII(token)
client = Client(token)
print(f"Program done in {time.time() - start:.4f}s")
4 changes: 2 additions & 2 deletions examples/run_successful_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import qibo

from qibo_client import TII
from qibo_client import Client

# create the circuit you want to run
circuit = qibo.models.QFT(5)
Expand All @@ -14,7 +14,7 @@
token = f.read()

# authenticate to server through the client instance
client = TII(token)
client = Client(token)

# run the circuit
print(f"{'*'*20}\nPost first circuit")
Expand Down
2 changes: 1 addition & 1 deletion src/qibo_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__version__ = im.version(__package__)

from .tii import TII
from .qibo_client import Client
10 changes: 5 additions & 5 deletions src/qibo_client/qibo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ def check_response_has_keys(response: requests.models.Response, keys: List[str])


class Client:
"""Class to manage the interaction with the QRC cluster."""
"""Class to manage the interaction with the remote server."""

def __init__(self, url: str, token: str):
def __init__(self, token: str, url: str = "https://cloud.qibo.science/"):
"""
:param url: the server address
:type url: str
:param token: the authentication token associated to the webapp user
:type token: str
:param url: the server address
:type url: str
"""
self.url = url
self.token = token
self.url = url

self.pid = None
self.results_folder = None
Expand Down
16 changes: 0 additions & 16 deletions src/qibo_client/tii.py

This file was deleted.

24 changes: 12 additions & 12 deletions tests/test_qibo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ def test_check_response_has_missing_keys():
qibo_client.check_response_has_keys(mock_response, keys)


def _get_tii_client():
return qibo_client.Client(LOCAL_URL, "valid_token")
def _get_local_client():
return qibo_client.Client("valid_token", LOCAL_URL)


def test_check_client_server_qibo_versions_with_version_match(mock_request: Mock):
_get_tii_client()
_get_local_client()
mock_request.get.assert_called_once_with(
LOCAL_URL + "qibo_version/", timeout=TIMEOUT
)
Expand All @@ -137,14 +137,14 @@ def test_check_client_server_qibo_versions_with_version_mismatch(
patch(f"{PKG}.constants.MINIMUM_QIBO_VERSION_ALLOWED", "0.1.9"),
patch(f"{PKG}.logger") as mock_logger,
):
_get_tii_client()
_get_local_client()
mock_logger.warning.assert_called_once()


def test_check_client_server_qibo_versions_with_low_local_version(mock_qibo: Mock):
mock_qibo.__version__ = "0.0.1"
with pytest.raises(AssertionError):
_get_tii_client()
_get_local_client()


def test__post_circuit_with_invalid_token(mock_request: Mock):
Expand All @@ -153,7 +153,7 @@ def _new_side_effect(url, json, timeout):

mock_request.post.side_effect = _new_side_effect

client = _get_tii_client()
client = _get_local_client()
with pytest.raises(HTTPError):
client._post_circuit(utils.MockedCircuit())

Expand All @@ -165,7 +165,7 @@ def _new_side_effect(url, json, timeout):

mock_request.post.side_effect = _new_side_effect

client = _get_tii_client()
client = _get_local_client()
with pytest.raises(JobPostServerError):
client._post_circuit(utils.MockedCircuit())

Expand All @@ -177,7 +177,7 @@ def _new_side_effect(url, json, timeout):

mock_request.post.side_effect = _new_side_effect

client = _get_tii_client()
client = _get_local_client()
return_value = client.run_circuit(utils.MockedCircuit())

assert return_value is None
Expand Down Expand Up @@ -262,7 +262,7 @@ def test__get_result_handles_tarfile_readerror(mock_request, results_base_folder
file_path = results_base_folder / "file.txt"
file_path.write_text("test content")

client = _get_tii_client()
client = _get_local_client()
result = client.run_circuit(utils.MockedCircuit())

assert result is None
Expand Down Expand Up @@ -299,7 +299,7 @@ def test__save_and_unpack_stream_response_to_folder(
def test__get_result(mock_qibo, mock_request, mock_tempfile, results_base_folder):
expected_array_path = results_base_folder / FAKE_PID / "results.npy"

client = _get_tii_client()
client = _get_local_client()
client.pid = FAKE_PID
result = client._get_result()

Expand All @@ -312,7 +312,7 @@ def test__get_result_with_job_status_error(
):
mock_request.get.side_effect = _get_request_side_effect(job_status="error")

client = _get_tii_client()
client = _get_local_client()
client.pid = FAKE_PID
result = client._get_result()

Expand All @@ -323,7 +323,7 @@ def test__get_result_with_job_status_error(
def test__run_circuit(mock_qibo, mock_request, mock_tempfile, results_base_folder):
expected_array_path = results_base_folder / FAKE_PID / "results.npy"

client = _get_tii_client()
client = _get_local_client()
client.pid = FAKE_PID
result = client.run_circuit(utils.MockedCircuit())

Expand Down
21 changes: 0 additions & 21 deletions tests/test_tii.py

This file was deleted.

0 comments on commit c04b5d6

Please sign in to comment.