diff --git a/README.md b/README.md index d1dd97a..15e9fdb 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,7 @@ 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. @@ -32,7 +31,7 @@ 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 @@ -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") diff --git a/doc/source/index.rst b/doc/source/index.rst index 2eaa8ea..41e3814 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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) diff --git a/doc/source/qibo_client.rst b/doc/source/qibo_client.rst index d6270ef..7c255a8 100644 --- a/doc/source/qibo_client.rst +++ b/doc/source/qibo_client.rst @@ -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 --------------- diff --git a/examples/run_error_job.py b/examples/run_error_job.py index 3fd0ba7..69b3746 100644 --- a/examples/run_error_job.py +++ b/examples/run_error_job.py @@ -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) @@ -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") diff --git a/examples/run_ping.py b/examples/run_ping.py index 1e12c3a..328f138 100644 --- a/examples/run_ping.py +++ b/examples/run_ping.py @@ -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" @@ -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") diff --git a/examples/run_successful_job.py b/examples/run_successful_job.py index 712012e..c171dd8 100644 --- a/examples/run_successful_job.py +++ b/examples/run_successful_job.py @@ -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) @@ -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") diff --git a/src/qibo_client/__init__.py b/src/qibo_client/__init__.py index 0d3fde6..76b7c78 100644 --- a/src/qibo_client/__init__.py +++ b/src/qibo_client/__init__.py @@ -4,4 +4,4 @@ __version__ = im.version(__package__) -from .tii import TII +from .qibo_client import Client diff --git a/src/qibo_client/qibo_client.py b/src/qibo_client/qibo_client.py index 957c5af..ad32951 100644 --- a/src/qibo_client/qibo_client.py +++ b/src/qibo_client/qibo_client.py @@ -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 diff --git a/src/qibo_client/tii.py b/src/qibo_client/tii.py deleted file mode 100644 index 805ef65..0000000 --- a/src/qibo_client/tii.py +++ /dev/null @@ -1,16 +0,0 @@ -from .qibo_client import Client - - -def base_url(): - return "https://cloud.qibo.science/" - - -def TII(token: str) -> Client: - """Instantiate a TII Client object. - - :param token: the authentication token associated to the webapp user - :type token: str - :return: the client instance connected to the TII server - :rtype: Client - """ - return Client(base_url(), token) diff --git a/tests/test_qibo_client.py b/tests/test_qibo_client.py index 9c63915..c1e7fa7 100644 --- a/tests/test_qibo_client.py +++ b/tests/test_qibo_client.py @@ -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 ) @@ -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): @@ -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()) @@ -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()) @@ -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 @@ -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 @@ -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() @@ -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() @@ -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()) diff --git a/tests/test_tii.py b/tests/test_tii.py deleted file mode 100644 index 81a66e0..0000000 --- a/tests/test_tii.py +++ /dev/null @@ -1,21 +0,0 @@ -from unittest.mock import Mock, patch - -from qibo_client import tii - -PKG = "qibo_client.tii" -FAKE_TOKEN = "fakeToken" - - -def test_base_url(): - assert tii.base_url() == "https://cloud.qibo.science/" - - -def fake_url(): - return "http://tii.url.com:1234" - - -@patch(f"{PKG}.base_url", fake_url) -@patch(f"{PKG}.Client.check_client_server_qibo_versions") -def test_TII(mock_method: Mock): - client = tii.TII(FAKE_TOKEN) - assert client.url == fake_url()