diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a55e510..6e59f21f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.18.0 + +### Feature + +- Add support for compressed job descriptions and results + [#155](https://github.com/qilimanjaro-tech/qiboconnection/pull/155) + ## 0.17.0 ### Feature diff --git a/changelog-dev.md b/changelog-dev.md index afbe9971..677e612b 100644 --- a/changelog-dev.md +++ b/changelog-dev.md @@ -6,9 +6,6 @@ This document contains the changes of the current release. ### Improvements -- Add support for compressed job descriptions and results - [#155](https://github.com/qilimanjaro-tech/qiboconnection/pull/155) - ### Breaking changes ### Deprecations / Removals diff --git a/docs/code/API/qiboconnection.api.API.rst b/docs/code/API/qiboconnection.api.API.rst new file mode 100644 index 00000000..002b4e28 --- /dev/null +++ b/docs/code/API/qiboconnection.api.API.rst @@ -0,0 +1,49 @@ +API +=== + +.. currentmodule:: qiboconnection.api + +.. autoclass:: API + :show-inheritance: + :members: + + + + + .. rubric:: Methods + + .. autosummary:: + + ~API.cancel_job + ~API.delete_job + ~API.delete_runcard + ~API.execute + ~API.execute_and_return_results + ~API.get_job + ~API.get_result + ~API.get_results + ~API.get_runcard + ~API.list_devices + ~API.list_jobs + ~API.list_runcards + ~API.login + ~API.ping + ~API.save_runcard + ~API.select_device_id + ~API.select_device_ids + ~API.set_device_to_maintenance + ~API.set_device_to_online + ~API.update_runcard + + + + + + .. rubric:: Attributes + + .. autosummary:: + + ~API.jobs + ~API.last_job + ~API.last_runcard + ~API.user_id diff --git a/docs/introduction/quickstart.rst b/docs/introduction/quickstart.rst index b99ab9fa..092f7766 100644 --- a/docs/introduction/quickstart.rst +++ b/docs/introduction/quickstart.rst @@ -35,7 +35,6 @@ Once you are logged in, you can list all accessible quantum processing units and "device_id": 9, "device_name": "Galadriel Qblox rack", "status": "online", - "availability": "available", "characteristics": { "type": "quantum" }, @@ -48,7 +47,6 @@ Once you are logged in, you can list all accessible quantum processing units and "device_id": 1, "device_name": "Radagast Simulator", "status": "offline", - "availability": "available" } You can then use :func:`~qiboconnection.API.select_device_id` or :func:`~qiboconnection.API.select_device_ids` to select diff --git a/src/qiboconnection/api.py b/src/qiboconnection/api.py index fdaf33f9..be497fdf 100644 --- a/src/qiboconnection/api.py +++ b/src/qiboconnection/api.py @@ -284,41 +284,6 @@ def set_device_to_maintenance(self, device_id: int) -> None: logger.error(json.loads(str(ex))[REST_ERROR.DETAIL]) raise ex - @typechecked - def block_device_id(self, device_id: int) -> None: - """Blocks a device to avoid others to manually use it. - .. warning:: - - This method is only available for Qilimanjaro members. - - Args: - device_id (int): Device identifier - """ - self._devices = self._add_or_update_single_device(device_id=device_id) - try: - self._devices.block_device(connection=self._connection, device_id=device_id) - except HTTPError as ex: - logger.error(json.loads(str(ex))[REST_ERROR.DETAIL]) - raise ex - - @typechecked - def release_device(self, device_id: int) -> None: - """Releases a device to let others manually using it. - - .. warning:: - - This method is only available for Qilimanjaro members. - - Args: - device_id (int): Device identifier - """ - self._devices = self._add_or_update_single_device(device_id=device_id) - try: - self._devices.release_device(connection=self._connection, device_id=device_id) - except HTTPError as ex: - logger.error(json.loads(str(ex))[REST_ERROR.DETAIL]) - raise ex - # REMOTE EXECUTIONS @typechecked diff --git a/src/qiboconnection/connection.py b/src/qiboconnection/connection.py index d0ce6687..ed600100 100644 --- a/src/qiboconnection/connection.py +++ b/src/qiboconnection/connection.py @@ -236,18 +236,6 @@ def update_device_status(self, device_id: int, status: str) -> Tuple[Any, int]: """ return self.send_put_auth_remote_api_call(path=f"/devices/{device_id}", data={"status": status}) - def update_device_availability(self, device_id: int, availability: str) -> Tuple[Any, int]: - """Makes the request for updating a Device availability with a new value. - - Args: - device_id (int): device identifier - availability (str): device availability - - Returns: - Tuple[Any, int]: Http Response - """ - return self.send_put_auth_remote_api_call(path=f"/devices/{device_id}", data={"availability": availability}) - def send_message(self, channel_id: int, message: dict) -> Tuple[Any, int]: """Sends a message to a channel registered in the system diff --git a/src/qiboconnection/models/devices/device.py b/src/qiboconnection/models/devices/device.py index ef3240f4..6b47ba62 100644 --- a/src/qiboconnection/models/devices/device.py +++ b/src/qiboconnection/models/devices/device.py @@ -15,13 +15,11 @@ """ Device class """ import json -from requests import HTTPError from typeguard import typechecked -from qiboconnection.config import logger from qiboconnection.connection import Connection from qiboconnection.typings.devices import DeviceInput -from qiboconnection.typings.enums import DeviceAvailability, DeviceStatus +from qiboconnection.typings.enums import DeviceStatus from .device_details import DeviceDetails @@ -121,31 +119,6 @@ def dynamic_features(self) -> int | None: """ return getattr(self, "_dynamic_features", None) - def block_device(self, connection: Connection) -> None: - """Blocks a device to avoid others to use it - - Args: - connection (Connection): Qibo API connection - - Raises: - HTTPError: Error blocking device - """ - try: - connection.update_device_availability(device_id=self._id, availability=DeviceAvailability.BLOCKED) # type: ignore[attr-defined] - self._availability = DeviceAvailability.BLOCKED - except HTTPError as ex: - logger.error("Error blocking device %s.", self.name) # type: ignore[attr-defined] - raise ex - - def release_device(self, connection: Connection) -> None: - """Releases a device to let others use it - - Args: - connection (Connection): Qibo API connection - """ - connection.update_device_availability(device_id=self._id, availability=DeviceAvailability.AVAILABLE) # type: ignore[attr-defined] - self._availability = DeviceAvailability.AVAILABLE - def set_to_online(self, connection: Connection) -> None: """Updates a device status so that it can accept remote jobs. Local jobs will be blocked. diff --git a/src/qiboconnection/models/devices/devices.py b/src/qiboconnection/models/devices/devices.py index 72fd7614..3d3443fb 100644 --- a/src/qiboconnection/models/devices/devices.py +++ b/src/qiboconnection/models/devices/devices.py @@ -21,7 +21,6 @@ from qiboconnection.config import logger from qiboconnection.connection import Connection -from qiboconnection.models.devices.util import block_device from .device import Device @@ -152,28 +151,6 @@ def _find_device(self, device_id: int) -> Device: raise ValueError(f"Device duplicated with same id:{device_id}") return device_found.pop() - def block_device(self, connection: Connection, device_id: int) -> None: - """Blocks a device to avoid it being used by others - - Args: - connection (Connection): Qibo remote connection - device_id (int): Device identifier - """ - device_found = self._find_device(device_id) - block_device(connection=connection, device=device_found) - logger.info("Device %s blocked for execution. AVAILABILITY: blocked", device_found.name) - - def release_device(self, connection: Connection, device_id: int) -> None: - """Releases a device to let others use it - - Args: - connection (Connection): Qibo remote connection - device_id (int): Device identifier - """ - device_found = self._find_device(device_id) - device_found.release_device(connection=connection) - logger.info("Device %s released. AVAILABILITY: AVAILABLE", device_found.name) - def set_device_to_online(self, connection: Connection, device_id: int) -> None: """Releases a device to let others use it diff --git a/src/qiboconnection/models/devices/util.py b/src/qiboconnection/models/devices/util.py index 75b6ab2d..e18aa555 100644 --- a/src/qiboconnection/models/devices/util.py +++ b/src/qiboconnection/models/devices/util.py @@ -17,24 +17,11 @@ from typeguard import typechecked -from qiboconnection.config import logger -from qiboconnection.connection import Connection from qiboconnection.typings.devices import DeviceInput from .device import Device -def block_device(connection: Connection, device: Device) -> None: - """Blocks a device to avoid being used by others - - Args: - connection (Connection): Qibo remote connection - device (Device): the Device to block - """ - device.block_device(connection=connection) - logger.info("Device %s blocked.", device.name) - - @typechecked def create_device(device_input: dict) -> Device: """Creates a Device from a given device input. diff --git a/src/qiboconnection/typings/devices/device_input.py b/src/qiboconnection/typings/devices/device_input.py index 30002b6f..3fff2d04 100644 --- a/src/qiboconnection/typings/devices/device_input.py +++ b/src/qiboconnection/typings/devices/device_input.py @@ -34,7 +34,6 @@ class DeviceInput: name: str status: str type: str | None = None - availability: str | None = None number_pending_jobs: int | None = None slurm_partition: str | None = None static_features: dict | None = None diff --git a/src/qiboconnection/typings/enums/__init__.py b/src/qiboconnection/typings/enums/__init__.py index d87f8fed..f7ae050e 100644 --- a/src/qiboconnection/typings/enums/__init__.py +++ b/src/qiboconnection/typings/enums/__init__.py @@ -15,7 +15,6 @@ """ Enums typing module """ from .algorithm_name import AlgorithmName from .algorythm_type import AlgorithmType -from .device_availability import DeviceAvailability from .device_status import DeviceStatus from .device_type import DeviceType from .grant_type import GrantType diff --git a/src/qiboconnection/typings/enums/device_availability.py b/src/qiboconnection/typings/enums/device_availability.py deleted file mode 100644 index 58eb70bb..00000000 --- a/src/qiboconnection/typings/enums/device_availability.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2023 Qilimanjaro Quantum Tech -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" DeviceAvailability enum """ -from .str_enum import StrEnum - - -class DeviceAvailability(StrEnum): - """Device availability""" - - AVAILABLE = "available" - BLOCKED = "blocked" diff --git a/tests/end2end/tests/test_end2end.py b/tests/end2end/tests/test_end2end.py index 389aaf86..d7735299 100644 --- a/tests/end2end/tests/test_end2end.py +++ b/tests/end2end/tests/test_end2end.py @@ -10,7 +10,6 @@ from qiboconnection.api import API from qiboconnection.models.devices import Device -from qiboconnection.typings.enums import DeviceAvailability as DA from qiboconnection.typings.enums import DeviceStatus as DS from qiboconnection.typings.enums import JobStatus from qiboconnection.typings.job_data import JobData @@ -87,30 +86,6 @@ def test_device_selection(device: Device, api: API): pytest.skip(f"Operation {Operation.SELECT} not possible for {device}") -@pytest.mark.parametrize("device", get_devices_listing_params()) -def test_device_blocking_and_release(device: Device, api: API): - """Test whether each device can be blocked and released - - Args: - api: api instance to call the server with - """ - - op_result = get_expected_operation_result(Operation.BLOCK, device) - if op_result == OperationResult.EXCEPTION: - with pytest.raises(Exception): - api.block_device_id(device_id=device.id) - elif op_result == OperationResult.SUCCESS: - try: - api.block_device_id(device_id=device.id) - api.release_device(device_id=device.id) - except ConnectionError: - pytest.fail(f"Connection was not possible to {device.name}", pytrace=False) - except Exception as ex: # pylint: disable=broad-exception-caught - pytest.fail(f"Connecting to {device.name} raised {ex}", pytrace=True) - else: - pytest.skip(f"Operation {Operation.BLOCK} not possbile for {device}") - - @pytest.mark.parametrize("device", get_devices_listing_params()) def test_circuit_posting(device: Device, api: API, numpy_circuit: Circuit): """Test whether a circuit can be sent to each device @@ -208,35 +183,22 @@ def test_all_status(device: Device, api: API): check_operation_possible_or_skip(Operation.CHANGE_STATUS, device) initial_status = device._status - initial_availability = device._availability if initial_status == DS.ONLINE: api.set_device_to_maintenance(device_id=device.id) assert get_device(api, device.id)._status == DS.MAINTENANCE api.set_device_to_online(device_id=device.id) assert get_device(api, device.id)._status == DS.ONLINE elif initial_status == DS.MAINTENANCE: - # If the device is MAINTENANCE + BLOCKED, we can not put it in online, that - # will cause an exception. In fact the way to proceed should be - # {Maintenace, Blocked} --[release]--> {Maintenace, Available} --[online]--> {Online, Available} - if initial_availability == DA.BLOCKED: - api.release_device(device_id=device.id) - assert get_device(api, device.id)._availability == DA.AVAILABLE - api.set_device_to_online(device_id=device.id) assert get_device(api, device.id)._status == DS.ONLINE api.set_device_to_maintenance(device_id=device.id) assert get_device(api, device.id)._status == DS.MAINTENANCE - - if initial_availability == DA.BLOCKED: - api.block_device_id(device_id=device.id) - assert get_device(api, device.id)._availability == DA.BLOCKED else: pytest.skip(f"Device {device} in status {initial_status}") # Check there are no changes in the device before we start the tests assert get_device(api, device.id)._status == initial_status - assert get_device(api, device.id)._availability == initial_availability @pytest.mark.parametrize("device", get_devices_listing_params()) diff --git a/tests/end2end/tests/test_user_roles.py b/tests/end2end/tests/test_user_roles.py index 76a46c5c..b3fe0c75 100644 --- a/tests/end2end/tests/test_user_roles.py +++ b/tests/end2end/tests/test_user_roles.py @@ -11,29 +11,23 @@ from qiboconnection.api import API from qiboconnection.models.devices import Device from qiboconnection.models.runcard import Runcard -from qiboconnection.typings.enums import DeviceAvailability, DeviceStatus +from qiboconnection.typings.enums import DeviceStatus from qiboconnection.typings.enums.job_status import JobStatus from qiboconnection.typings.job_data import JobData from qiboconnection.typings.vqa import VQA from tests.end2end.utils.operations import Operation, check_operation_possible_or_skip from tests.end2end.utils.utils import ( UserRole, - admin_block_device, - admin_release_device, - admin_set_device_to_maintenance, - admin_set_device_to_online, get_api_or_fail_test, get_device, get_devices_listing_params, get_logging_conf_or_fail_test, - get_user_can_change_availability_api, get_user_can_change_status_api, get_user_can_delete_runcard_api, get_user_can_get_runcard_api, get_user_can_list_runcard_api, get_user_can_save_runcard_api, get_user_can_update_runcard_api, - get_user_cannot_change_availability_api, get_user_cannot_change_status_api, get_user_cannot_delete_runcard_api, get_user_cannot_get_runcard_api, @@ -104,120 +98,7 @@ def test_cannot_change_device_status(device: Device, user_role: UserRole): api.set_device_to_online(device_id=device.id) -@pytest.mark.parametrize( - "device, user_role", - [(device, user_role) for user_role in list_user_roles() for device in get_devices_listing_params(user_role)], -) -@pytest.mark.slow -def test_cannot_change_device_status_when_blocked(device: Device, user_role: UserRole, api: API): - """Ensure any user role can change device status when device availabiliyty is not available - - Args: - device (Device): all devices - user_role (str): all users - api (API): Qiboconnection API instance - """ - logger.info(f"Device: {device}, User Role: {user_role}") - - admin_set_device_to_maintenance(device=device, api=api) - admin_block_device(device=device, api=api) - - user_api = get_api_or_fail_test(get_logging_conf_or_fail_test(user_role=user_role)) - - with pytest.raises(requests.exceptions.HTTPError): - user_api.set_device_to_online(device_id=device.id) - user_api.set_device_to_maintenance(device_id=device.id) - - admin_release_device(device=device, api=api) - admin_set_device_to_online(device=device, api=api) - - -# ------------------------------------------------------------------------ OPERATION: CAN CHANGE AVAILABILITY - - -@pytest.mark.parametrize( - "device, user_role", - [(device, user_role) for user_role in list_user_roles() for device in get_devices_listing_params(user_role)], -) -@pytest.mark.slow -def test_can_change_device_availability(device: Device, user_role: UserRole, api: API): - """Ensure that user roles which, by definition, can change availability are allowed to do it. - - Args: - device (Device): _description_ - user_role (str): _description_ - api (API): _description_ - """ - logger.info(f"Device: {device}, User Role: {user_role}") - - admin_set_device_to_maintenance(device=device, api=api) - - user_role_api = get_user_can_change_availability_api(user_role=user_role) - - user_role_api.release_device(device_id=device.id) - assert get_device(user_role_api, device.id)._availability == DeviceAvailability.AVAILABLE - - user_role_api.block_device_id(device_id=device.id) - assert get_device(user_role_api, device.id)._availability == DeviceAvailability.BLOCKED - - user_role_api.release_device(device_id=device.id) - assert get_device(user_role_api, device.id)._availability == DeviceAvailability.AVAILABLE - - admin_set_device_to_online(device=device, api=api) - - -@pytest.mark.parametrize( - "device, user_role", - [(device, user_role) for user_role in list_user_roles() for device in get_devices_listing_params(user_role)], -) -@pytest.mark.slow -def test_cannot_change_device_availability(device: Device, user_role: UserRole, api: API): - """Ensure that user roles which, by definition, cannot change availability are not allowed to do it - - Args: - device (Device): all devices - user_role (str): all users - api (API): Qiboconnection API instance - """ - logger.info(f"Device: {device}, User Role: {user_role}") - - admin_set_device_to_maintenance(device=device, api=api) - - user_api = get_user_cannot_change_availability_api(user_role=user_role) - - with pytest.raises(requests.exceptions.HTTPError): - user_api.release_device(device_id=device.id) - user_api.block_device_id(device_id=device.id) - user_api.release_device(device_id=device.id) - - admin_set_device_to_online(device=device, api=api) - - -@pytest.mark.parametrize( - "device, user_role", - [(device, user_role) for user_role in list_user_roles() for device in get_devices_listing_params(user_role)], -) -@pytest.mark.slow -def test_cannot_change_device_availability_when_online(device: Device, user_role: UserRole, api: API): - """Ensure tany user can block any device when status is not maintenance - - Args: - device (Device): all devices - user_role (str): all users - api (API): Qiboconnection API instance - """ - logger.info(f"Device: {device}, User Role: {user_role}") - - admin_set_device_to_online(device=device, api=api) - - user_api = get_api_or_fail_test(get_logging_conf_or_fail_test(user_role=user_role)) - - with pytest.raises(requests.exceptions.HTTPError): - user_api.release_device(device_id=device.id) - user_api.block_device_id(device_id=device.id) - user_api.release_device(device_id=device.id) - - admin_set_device_to_online(device=device, api=api) +# ------------------------------------------------------------------------ OPERATION: POST QPROGRAM and VQA @pytest.mark.parametrize( diff --git a/tests/end2end/utils/operations.py b/tests/end2end/utils/operations.py index 0586c450..8ac0f62c 100644 --- a/tests/end2end/utils/operations.py +++ b/tests/end2end/utils/operations.py @@ -6,20 +6,18 @@ import pytest from qiboconnection.models.devices import Device -from qiboconnection.typings.enums import DeviceAvailability, DeviceStatus, DeviceType +from qiboconnection.typings.enums import DeviceStatus, DeviceType from .utils import is_development # Explanation: # Given a device, there are a series of OPERATIONS we can perform: -# - Block: block the device # - Select: select the device # - Post: post a job # - Response: Obtain a job response # The expected results for such operations depends on its STATUS that is a combination of # - Status: online, offline -# - Availability: available, blocked # - IsDevelopment?: If the test are performed in the development environment # - IsQuantum?: If it is Quantum device # where Environment, Type of device are not real attributes of the device (as the others) but @@ -42,7 +40,6 @@ class OperationResult(Enum): class Operation(Enum): """Expected result of the operation for a given device in a certain environment""" - BLOCK = "block" SELECT = "select" POST = "post" RESPONSE = "response" @@ -50,10 +47,8 @@ class Operation(Enum): CANCEL = "cancel" -def is_device(device: Device, status: DeviceStatus, availability: DeviceAvailability) -> bool: - return (device._status is None or device._status == status) and ( - device._availability is None or device._availability == availability - ) +def is_device(device: Device, status: DeviceStatus) -> bool: + return device._status is None or device._status == status def is_quantum(device: Device) -> bool: @@ -72,7 +67,7 @@ def get_expected_operation_result( # pylint: disable=too-many-branches ) -> OperationResult: """Get the expected result of performing a certain operation in a device. - Together with the status and availability of the device, it takes into consideration other + Together with the of the device, it takes into consideration other factors as the environment (eg. PRODUCTION) and the type of device (eg. QUANTUM) Args: @@ -91,19 +86,10 @@ def get_expected_operation_result( # pylint: disable=too-many-branches result: OperationResult = OperationResult.FORBIDDEN if operation in [Operation.SELECT, Operation.POST, Operation.CANCEL]: result = OperationResult.SUCCESS - elif operation == Operation.BLOCK: - if is_quantum(device) and not is_development(): - result = OperationResult.FORBIDDEN - elif is_device(device, DeviceStatus.MAINTENANCE, DeviceAvailability.AVAILABLE): - result = OperationResult.SUCCESS - else: - result = OperationResult.EXCEPTION elif operation == Operation.CHANGE_STATUS: if is_quantum(device) and not is_development(): result = OperationResult.FORBIDDEN - if is_device(device, status=DeviceStatus.ONLINE, availability=DeviceAvailability.AVAILABLE) or is_device( - device, availability=DeviceAvailability.AVAILABLE, status=DeviceStatus.MAINTENANCE - ): + if is_device(device, status=DeviceStatus.ONLINE) or is_device(device, status=DeviceStatus.MAINTENANCE): result = OperationResult.SUCCESS else: result = OperationResult.EXCEPTION @@ -111,7 +97,7 @@ def get_expected_operation_result( # pylint: disable=too-many-branches elif operation == Operation.RESPONSE: if is_quantum(device) and is_development(): result = OperationResult.EXCEPTION - elif is_device(device, status=DeviceStatus.ONLINE, availability=DeviceAvailability.AVAILABLE): + elif is_device(device, status=DeviceStatus.ONLINE): result = OperationResult.SUCCESS else: result = OperationResult.FORBIDDEN diff --git a/tests/end2end/utils/utils.py b/tests/end2end/utils/utils.py index 19f7f921..ca17bd3d 100644 --- a/tests/end2end/utils/utils.py +++ b/tests/end2end/utils/utils.py @@ -13,7 +13,7 @@ from qiboconnection.errors import HTTPError from qiboconnection.models.devices import Device from qiboconnection.typings.connection import ConnectionConfiguration -from qiboconnection.typings.enums import DeviceAvailability, DeviceStatus, JobStatus +from qiboconnection.typings.enums import DeviceStatus, JobStatus from qiboconnection.typings.job_data import JobData @@ -22,7 +22,7 @@ class MissingCredentialsException(ValueError): class UserRole(str, Enum): - """User roles with different permissions. admin is allowed to change device status and availability. qilimanjaro_user can only change availability provided that device status=maintenance. bsc_user can change none.""" + """User roles with different permissions. admin is allowed to change device status.""" ADMIN = "admin" QILI = "qilimanjaro_user" @@ -37,7 +37,6 @@ class UserRole(str, Enum): { "role": UserRole.ADMIN, "can_change_status": True, - "can_change_availability": True, "can_post_qprograms": True, "can_post_vqas": True, "can_get_runcard": True, @@ -49,7 +48,6 @@ class UserRole(str, Enum): { "role": UserRole.BSC, "can_change_status": False, - "can_change_availability": False, "can_post_qprograms": True, "can_post_vqas": False, "can_get_runcard": True, @@ -61,7 +59,6 @@ class UserRole(str, Enum): { "role": UserRole.QILI, "can_change_status": False, - "can_change_availability": True, "can_post_qprograms": True, "can_post_vqas": True, "can_get_runcard": True, @@ -73,7 +70,6 @@ class UserRole(str, Enum): { "role": UserRole.MACHINE, "can_change_status": False, - "can_change_availability": False, "can_post_qprograms": False, "can_post_vqas": False, "can_get_runcard": True, @@ -302,36 +298,6 @@ def get_user_cannot_change_status_api(user_role: UserRole): return get_api_or_fail_test(get_logging_conf_or_fail_test(user_role=user_role)) -def get_user_can_change_availability_api(user_role: UserRole): - """Get API instance for the user roles that can change availability, by definition. - Args: - user_role (UserRole): - - Returns: - API: API instance only for the users that can change status - """ - - if not get_user_role_operations(user_role=user_role)["can_change_availability"]: - pytest.skip(f"{user_role} cannot change availability") - - return get_api_or_fail_test(get_logging_conf_or_fail_test(user_role=user_role)) - - -def get_user_cannot_change_availability_api(user_role: UserRole): - """Get API instance for the user roles that cannot change availability, by definition. - - Args: - user_role (UserRole): - - Returns: - API: API instance only for the users that can change status - """ - if get_user_role_operations(user_role=user_role)["can_change_availability"]: - pytest.skip(f"{user_role} can change availability") - - return get_api_or_fail_test(get_logging_conf_or_fail_test(user_role=user_role)) - - def get_user_cannot_post_and_list_qprogram_api(user_role: UserRole): """Get API instance for the user roles that cannot post qililab qprogram, by definition. @@ -516,8 +482,6 @@ def admin_set_device_to_online(device: Device, api: API): Args: device (Device): device. """ - if device._availability == DeviceAvailability.BLOCKED: - pytest.fail(f"{device.name} is {device._availability} and hence can't set it to online.") if device._status == DeviceStatus.OFFLINE and is_development(): pytest.skip(f"{device.name} is {device._status}") @@ -531,8 +495,6 @@ def admin_set_device_to_maintenance(device: Device, api: API): Args: device (Device): device """ - if get_device(api, device.id)._availability == DeviceAvailability.BLOCKED: - pytest.fail(f"{device.name} is {device._availability} and hence can't set it to maintenance.") if get_device(api, device.id)._status == DeviceStatus.OFFLINE and is_development(): pytest.skip(f"{device.name} is {device._status}") @@ -540,38 +502,6 @@ def admin_set_device_to_maintenance(device: Device, api: API): api.set_device_to_maintenance(device_id=device.id) -def admin_block_device(device: Device, api: API): - """Block device with admin user - - Args: - device (Device): device - """ - - if get_device(api, device.id)._status == DeviceStatus.ONLINE: - pytest.fail(f"{device.name} is {device._status} and hence can't block it.") - - if get_device(api, device.id)._status == DeviceStatus.OFFLINE and is_development(): - pytest.skip(f"{device} is {device._status}") - - api.block_device_id(device_id=device.id) - - -def admin_release_device(device: Device, api: API): - """Release device with admin user - - Args: - device (Device): device - """ - - if get_device(api, device.id)._status == DeviceStatus.ONLINE: - pytest.fail(f"{device.name} is {device._status} and hence can't release it.") - - if get_device(api, device.id)._status == DeviceStatus.OFFLINE and is_development(): - pytest.skip(f"{device.name} is {device._status}") - - api.release_device(device_id=device.id) - - def get_logging_conf(role: UserRole = UserRole.ADMIN) -> ConnectionConfiguration: """Build a ConnectionConfiguration object from the keys defined in environment diff --git a/tests/unit/data/testing_data.py b/tests/unit/data/testing_data.py index 447d01bf..258a278c 100644 --- a/tests/unit/data/testing_data.py +++ b/tests/unit/data/testing_data.py @@ -2,27 +2,25 @@ """ Data to used alongside the test suite. """ from qiboconnection.typings.devices import DeviceInput -from qiboconnection.typings.enums import DeviceAvailability, DeviceStatus +from qiboconnection.typings.enums import DeviceStatus from .web_responses import WebResponses device_inputs = [ - DeviceInput(id=1, name="one_device", status="online", availability="available"), + DeviceInput(id=1, name="one_device", status="online"), DeviceInput( id=2, name="second_device", status=DeviceStatus.ONLINE, - availability=DeviceAvailability.AVAILABLE, ), ] offline_device_inputs = [ - DeviceInput(id=1, name="one_device", status="offline", availability="available"), + DeviceInput(id=1, name="one_device", status="offline"), DeviceInput( id=2, name="second_device", status=DeviceStatus.OFFLINE, - availability=DeviceAvailability.AVAILABLE, ), ] @@ -42,7 +40,6 @@ id=1, name="radagast-simulator", status="online", - availability="available", characteristics={ "type": "simulator", "cpu": "Intel Core i9-9900K @ 16x 5GHz", @@ -60,7 +57,6 @@ id=1, name="galadriel-cluster", status="online", - availability="available", last_calibration_time="0", characteristics={"type": "quantum", "description": "Cluster"}, calibration_details={"t1": 10, "frequency": 988, "elapsed_time": 10}, diff --git a/tests/unit/data/web_responses/devices.py b/tests/unit/data/web_responses/devices.py index 5a8aca42..492ee0ce 100644 --- a/tests/unit/data/web_responses/devices.py +++ b/tests/unit/data/web_responses/devices.py @@ -5,7 +5,6 @@ "device_name": "AWS Development Simulator", "device_type": "simulator", "status": "other", - "availability": "other", "channel_id": 2, "number_pending_jobs": 6, "characteristics": { @@ -23,7 +22,6 @@ "device_id": 9, "device_name": "AWS Development Quantum", "status": 2, - "availability": "available", "channel_id": 2, "characteristics": {"type": "quantum"}, "calibration_details": {"t1": 10, "frequency": 988}, @@ -34,7 +32,6 @@ "device_id": 7, "device_name": "AWS Development Simulator", "status": "offline", - "availability": "available", "channel_id": 2, "number_pending_jobs": 6, "new_field": 8969, diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index 9ad712c6..02bf1e34 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -624,7 +624,6 @@ def setup_method(self): "status": "offline", "device_id": 9, "device_name": "Dummy Device", - "availability": "available", "channel_id": 0, }, ) diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py index 71e1fd6e..a7412026 100644 --- a/tests/unit/test_connection.py +++ b/tests/unit/test_connection.py @@ -501,19 +501,6 @@ def test_update_device_status(mocked_rest_call: MagicMock, mocked_connection: Co mocked_rest_call.assert_called_with(mocked_connection, path=f"/devices/{_DEVICE_ID}", data={"status": _NEW_STATUS}) -@patch("qiboconnection.connection.Connection.send_put_auth_remote_api_call", autospec=True) -def test_update_device_availability(mocked_rest_call: MagicMock, mocked_connection: Connection): - """Asserts correct put function is called for updating a device status""" - - _DEVICE_ID = 1 - _NEW_AVAILABILITY = "new_status" - - mocked_connection.update_device_availability(device_id=1, availability=_NEW_AVAILABILITY) - mocked_rest_call.assert_called_with( - mocked_connection, path=f"/devices/{_DEVICE_ID}", data={"availability": _NEW_AVAILABILITY} - ) - - @patch("qiboconnection.connection.Connection.send_post_auth_remote_api_call", autospec=True) def test_send_message(mocked_rest_call: MagicMock, mocked_connection: Connection): """Asserts correct put function is called for updating a device status""" diff --git a/tests/unit/test_device.py b/tests/unit/test_device.py index 604c87cd..182ec4a3 100644 --- a/tests/unit/test_device.py +++ b/tests/unit/test_device.py @@ -76,7 +76,6 @@ def test_device_json_representation_expanded(device_input: DeviceInput): "slurm_partition": None, "static_features": None, "dynamic_features": None, - "availability": "available", "str": str(device), } assert json.loads(device.toJSON(expand=True)) == expected_dict diff --git a/tests/unit/test_devices.py b/tests/unit/test_devices.py index 500de5c1..e6263e3d 100644 --- a/tests/unit/test_devices.py +++ b/tests/unit/test_devices.py @@ -48,7 +48,6 @@ def test_devices_to_dict_expand(simulator_device_input: DeviceInput): assert output_dict[0]["id"] == simulator_device_input.id assert output_dict[0]["name"] == simulator_device_input.name assert output_dict[0]["status"] == simulator_device_input.status - assert output_dict[0]["availability"] == simulator_device_input.availability assert output_dict[0]["characteristics"] == simulator_device_input.characteristics # type: ignore[attr-defined] assert output_dict == [simulator_device.to_dict(expand=True)] @@ -68,7 +67,6 @@ def test_devices_to_json_expand(simulator_device_input: DeviceInput): assert output_dict[0]["id"] == simulator_device_input.id assert output_dict[0]["name"] == simulator_device_input.name assert output_dict[0]["status"] == simulator_device_input.status - assert output_dict[0]["availability"] == simulator_device_input.availability assert output_dict[0]["characteristics"] == simulator_device_input.characteristics # type: ignore[attr-defined] assert output_dict == [simulator_device.to_dict(expand=True)]