Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e without availability #157

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions docs/code/API/qiboconnection.api.API.rst
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions docs/introduction/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
DZPM marked this conversation as resolved.
Show resolved Hide resolved
"characteristics": {
"type": "quantum"
},
Expand All @@ -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
Expand Down
35 changes: 0 additions & 35 deletions src/qiboconnection/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/qiboconnection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 1 addition & 28 deletions src/qiboconnection/models/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down
23 changes: 0 additions & 23 deletions src/qiboconnection/models/devices/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
13 changes: 0 additions & 13 deletions src/qiboconnection/models/devices/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/qiboconnection/typings/devices/device_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/qiboconnection/typings/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions src/qiboconnection/typings/enums/device_availability.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/end2end/tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Loading
Loading