Skip to content

Commit

Permalink
Merge branch 'main' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardusrendy committed Mar 23, 2024
2 parents dfe1d7c + ed1b67b commit c4c2820
Show file tree
Hide file tree
Showing 53 changed files with 405 additions and 310 deletions.
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Report a Bug
description: Use this template to report an alab_os bug.
labels: ["bug"]
title: "[Bug]: "
body:
- type: textarea
id: current-behavior
attributes:
label: Current behavior
description: What bad behavior do you see?
validations:
required: true

- type: textarea
id: expected-behavior
attributes:
label: Expected Behavior
description: What did you expect to see?
validations:
required: true

- type: textarea
id: code-snippet
attributes:
label: Minimal example
description: If possible, provide a code snippet relevant to reproducing this bug.
render: Python
validations:
required: false

- type: textarea
id: files
attributes:
label: Relevant files/images/logs
description: Please upload relevant files to help reproduce this bug, or logs if helpful.
validations:
required: false
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Feature Request
description: Use this template to request a new feature in alab_os.
labels: ["feature"]
title: "[Feature Request]: "
body:
- type: textarea
id: feature
attributes:
label: Feature Requested
description: Specify the feature and provide examples or use cases.
validations:
required: true

- type: textarea
id: solution
attributes:
label: Proposed Solution
description: Share your thoughts on how the feature could be implemented.
placeholder: Implement a new method that ...
validations:
required: true

- type: textarea
id: relevant
attributes:
label: Relevant Information
description: Additional context or links for understanding or implementing the feature.
placeholder: Use cases, related discussions, relevant literature, ...
validations:
required: false
4 changes: 2 additions & 2 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9" # Specify the Python version you need
python-version: "3.10" # Specify the Python version you need
- name: Install Black
run: pip install black==22.3.0
run: pip install black
- name: Run Black
run: black ./alab_management
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
python-version: ["3.10"]
services:
rabbitmq:
image: "rabbitmq:3.9"
Expand All @@ -37,7 +37,7 @@ jobs:
uses: actions/setup-python@v2
with:
# python-version: ${{ matrix.python-version }}
python-version: "3.9"
python-version: "3.10"
# cache: 'pip'
# cache-dependency-path:
- name: Set up environment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.10'
- name: Set up dependencies
run: pip install --quiet .
- name: Compile sphinx
Expand Down
3 changes: 2 additions & 1 deletion alab_management/_default/devices/default_device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import ClassVar

from alab_management import BaseDevice, SamplePosition
from alab_management.device_view import BaseDevice
from alab_management.sample_view import SamplePosition


class DefaultDevice(BaseDevice):
Expand Down
20 changes: 10 additions & 10 deletions alab_management/builders/experimentbuilder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Set, Union
from typing import Any, Literal

from .samplebuilder import SampleBuilder

Expand All @@ -13,20 +13,20 @@ class ExperimentBuilder:
name (str): The name of the experiment.
"""

def __init__(self, name: str, tags: Optional[List[str]] = None, **metadata):
def __init__(self, name: str, tags: list[str] | None = None, **metadata):
"""
Args:
name (str): The name of the experiment.
tags (List[str]): A list of tags to attach to the experiment.
"""
self.name = name
self._samples: List[SampleBuilder] = []
self._tasks: Dict[str, Dict[str, Any]] = {}
self._samples: list[SampleBuilder] = []
self._tasks: dict[str, dict[str, Any]] = {}
self.tags = tags or []
self.metadata = metadata

def add_sample(
self, name: str, tags: Optional[List[str]] = None, **metadata
self, name: str, tags: list[str] | None = None, **metadata
) -> SampleBuilder:
"""
Add a sample to the batch. Each sample already has multiple tasks binded to it. Each
Expand All @@ -53,8 +53,8 @@ def add_task(
self,
task_id: str,
task_name: str,
task_kwargs: Dict[str, Any],
samples: List[SampleBuilder],
task_kwargs: dict[str, Any],
samples: list[SampleBuilder],
) -> None:
"""
This function adds a task to the sample. You should use this function only for special cases which
Expand All @@ -78,7 +78,7 @@ def add_task(
"samples": [sample.name for sample in samples],
}

def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> dict[str, Any]:
"""
Return a dictionary that can be used to generate an input file for the `experiment`
to run.
Expand All @@ -88,9 +88,9 @@ def to_dict(self) -> Dict[str, Any]:
A dictionary that can be used to generate an input file for the `experiment` to run.
"""
samples: List[Dict[str, Any]] = []
samples: list[dict[str, Any]] = []
# tasks = []
tasks: List[Dict[str, Union[str, Set[int], List]]] = []
tasks: list[dict[str, str | set[int] | list]] = []
task_ids = {}

for sample in self._samples:
Expand Down
8 changes: 4 additions & 4 deletions alab_management/builders/samplebuilder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Build the sample object."""

from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import TYPE_CHECKING, Any

from bson import ObjectId # type: ignore

Expand All @@ -23,11 +23,11 @@ def __init__(
self,
name: str,
experiment: "ExperimentBuilder",
tags: Optional[List[str]] = None,
tags: list[str] | None = None,
**metadata,
):
self.name = name
self._tasks: List[str] = [] # type: ignore
self._tasks: list[str] = [] # type: ignore
self.experiment = experiment
self.metadata = metadata
self._id = str(ObjectId())
Expand All @@ -49,7 +49,7 @@ def add_task(
if task_id not in self._tasks:
self._tasks.append(task_id)

def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> dict[str, Any]:
"""Return Sample as a dictionary.
This looks like:
Expand Down
6 changes: 3 additions & 3 deletions alab_management/builders/utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""This module contains utility functions for the builders module."""

from typing import TYPE_CHECKING, List, Union
from typing import TYPE_CHECKING

from bson import ObjectId # type: ignore

from .experimentbuilder import ExperimentBuilder
from .samplebuilder import SampleBuilder

if TYPE_CHECKING:
from alab_management import BaseTask
from alab_management.task_view import BaseTask


def append_task(
task: "BaseTask",
samples: Union[SampleBuilder, List[SampleBuilder]],
samples: SampleBuilder | list[SampleBuilder],
):
"""
Used to add basetask to a SampleBuilder's tasklist during Experiment construction.
Expand Down
4 changes: 2 additions & 2 deletions alab_management/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import os
from pathlib import Path
from types import MappingProxyType as FrozenDict
from typing import Any, Dict
from typing import Any

import toml


def freeze_config(config_: Dict[str, Any]) -> FrozenDict:
def freeze_config(config_: dict[str, Any]) -> FrozenDict:
"""
Convert the config dict to frozen config.
Expand Down
6 changes: 3 additions & 3 deletions alab_management/dashboard/routes/experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This is a dashboard that displays data from the ALab database."""

from datetime import datetime, timedelta
from typing import Any, Dict, List, Optional
from typing import Any

from bson import ObjectId # type: ignore
from bson.errors import InvalidId # type: ignore
Expand Down Expand Up @@ -180,11 +180,11 @@ def query_experiment_results(exp_id: str):
def cancel_experiment(exp_id: str):
try:
exp_id = ObjectId(exp_id)
experiment: Optional[Dict[str, Any]] = experiment_view.get_experiment(exp_id)
experiment: dict[str, Any] | None = experiment_view.get_experiment(exp_id)
if experiment is None:
return {"status": "error", "reason": "Experiment not found"}, 400

tasks: List[Dict[str, Any]] = experiment["tasks"]
tasks: list[dict[str, Any]] = experiment["tasks"]
# tasks = experiment_view.get_experiment(exp_id)["tasks"]

for task in tasks:
Expand Down
13 changes: 6 additions & 7 deletions alab_management/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
DeviceManager class, which will handle all the request to run certain methods on the real device.
"""

from collections.abc import Callable
from concurrent.futures import Future
from enum import Enum, auto
from functools import partial
from threading import Thread
from typing import Any, Callable, Dict, NoReturn, Optional, cast
from typing import Any, NoReturn, cast
from uuid import uuid4

import dill
Expand Down Expand Up @@ -171,9 +172,7 @@ def callback_publish(channel, delivery_tag, props, response):
channel.basic_ack(delivery_tag=cast(int, delivery_tag))

try:
device_entry: Optional[Dict[str, Any]] = self._device_view.get_device(
device
)
device_entry: dict[str, Any] | None = self._device_view.get_device(device)

# check if the device is currently occupied by this task
if self._check_status and (
Expand Down Expand Up @@ -224,7 +223,7 @@ def on_message(
"kwargs": Dict,
}
"""
body: Dict[str, Any] = dill.loads(_body)
body: dict[str, Any] = dill.loads(_body)

thread = Thread(
target=self._execute_command_wrapper,
Expand Down Expand Up @@ -273,15 +272,15 @@ def __init__(self, task_id: ObjectId, timeout: int = None):
# taskid, or can be random? I think this dies with the resourcerequest context manager anyways?
self._rpc_reply_queue_name = str(uuid4()) + DEFAULT_CLIENT_QUEUE_SUFFIX
self._task_id = task_id
self._waiting: Dict[ObjectId, Future] = {}
self._waiting: dict[ObjectId, Future] = {}

self._conn = get_rabbitmq_connection()
self._channel = self._conn.channel()
self._channel.queue_declare(
self._rpc_reply_queue_name, exclusive=False, auto_delete=True
)

self._thread: Optional[Thread] = None
self._thread: Thread | None = None

self._channel.basic_consume(
queue=self._rpc_reply_queue_name,
Expand Down
6 changes: 3 additions & 3 deletions alab_management/device_view/dbattributes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any

from pymongo.collection import Collection # type: ignore

Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
device_collection: Collection,
device_name: str,
attribute_name: str,
default_value: Union[list, None] = None,
default_value: list | None = None,
):
self._collection = device_collection
self.attribute_name = attribute_name
Expand Down Expand Up @@ -284,7 +284,7 @@ def __init__(
device_collection: Collection,
device_name: str,
attribute_name: str,
default_value: Union[dict, None] = None,
default_value: dict | None = None,
):
self._collection = device_collection
self.attribute_name = attribute_name
Expand Down
Loading

0 comments on commit c4c2820

Please sign in to comment.