Skip to content

Commit

Permalink
update page dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
idocx committed Jul 30, 2024
1 parent da37824 commit 9f3c6db
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python -m sphinx -T -E -b html -d _build/doctrees -D language=en ./docs/source _build/html
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/master' }}
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/html
Expand Down
15 changes: 9 additions & 6 deletions alab_management/builders/samplebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ def to_dict(self) -> dict[str, Any]:
"""Return Sample as a dictionary.
This looks like:
{
"_id": str(ObjectId),
"name": str,
"tags": List[str],
"metadata": Dict[str, Any],
}
.. code-block::
{
"_id": str(ObjectId),
"name": str,
"tags": List[str],
"metadata": Dict[str, Any],
}
Returns
-------
Expand Down
6 changes: 3 additions & 3 deletions alab_management/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ def create_device_wrapper(

def call(self, device_name: str, method: str, *args, **kwargs) -> Any:
"""
Call a method inside the device with name ``device_name``. *args, **kwargs will be feeded into
Call a method inside the device with name ``device_name``. args, kwargs will be feeded into
the method directly.
Args:
device_name: the name of device, which is defined by administer.
method: the class method to call
*args: positional arguments to feed into the method function
**kwargs: keyword arguments to feed into the method function
args: positional arguments to feed into the method function
kwargs: keyword arguments to feed into the method function
Returns
-------
Expand Down
31 changes: 15 additions & 16 deletions alab_management/device_view/dbattributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,27 @@ def value_in_database(name: str, default_value: Any) -> property:
Example usage when defining a new Device:
.. code-block:: python
from alab_management.device_view import BaseDevice, value_in_database
class MyDevice(BaseDevice):
my_attribute = value_in_database("my_attribute", 0)
from alab_management.device_view import BaseDevice, value_in_database
def __init__(self, name: str, **kwargs):
super().__init__(name, **kwargs)
self.name = name
self.my_attribute #initial call to the property, which sets the default value in the database
class MyDevice(BaseDevice):
my_attribute = value_in_database("my_attribute", 0)
....
#first instantiation
def __init__(self, name: str, **kwargs):
super().__init__(name, **kwargs)
self.name = name
self.my_attribute #initial call to the property, which sets the default value in the database
mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute = 5 #sets the value in the database
....
#future instantiation
mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute #retrieves value from db and returns 5
....
#first instantiation
mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute = 5 #sets the value in the database
....
#future instantiation
mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute #retrieves value from db and returns 5
"""

def getter(self) -> Any:
Expand Down
31 changes: 18 additions & 13 deletions alab_management/device_view/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def __init__(self, address: str, port: int = 502, *args, **kwargs):
@property
@abstractmethod
def description(self) -> str:
"""A short description of the device. This will be stored in the database + displayed in the dashboard. This
"""
A short description of the device. This will be stored in the database + displayed in the dashboard. This
must be declared in subclasses of BaseDevice!.
"""
return self._description
Expand Down Expand Up @@ -380,18 +381,21 @@ def request_maintenance(self, prompt: str, options: list[Any]):
def retrieve_signal(
self, signal_name: str, within: datetime.timedelta | None = None
):
"""Retrieve a signal from the database.
Args: signal_name (str): device signal name. This should match the signal_name passed to the
`@log_device_signal` decorator within (Optional[datetime.timedelta], optional): timedelta defining how far
back to pull logs from (relative to current time). Defaults to None.
Returns ------- Dict: Dictionary of signal result. Single value vs lists depends on whether `within` was None
or not, respectively. Form is: { "device_name": "device_name", "signal_name": "signal_name",
"value": "signal_value" or ["signal_value_1", "signal_value_2", ...]], "timestamp": "timestamp" or [
"timestamp_1", "timestamp_2", ...] }
"""
Retrieve a signal from the database.
Args:
signal_name (str): device signal name. This should match the signal_name passed to the
``@log_device_signal`` decorator
within (Optional[datetime.timedelta], optional):
timedelta defining how far back to pull logs from (relative to current time). Defaults to None.
Returns
-------
Dict: Dictionary of signal result. Single value vs lists depends on whether ``within`` was None
or not, respectively. Form is: { "device_name": "device_name", "signal_name": "signal_name",
"value": "signal_value" or ["signal_value_1", "signal_value_2", ...]], "timestamp": "timestamp" or [
"timestamp_1", "timestamp_2", ...] }
"""
return self._signalemitter.retrieve_signal(signal_name, within)

Expand Down Expand Up @@ -441,11 +445,12 @@ def __init__(self, device: BaseDevice):

def get_methods_to_log(self):
"""
Log the data from all methods decorated with `@log_signal` to the database.
Log the data from all methods decorated with ``@log_signal`` to the database.
Collected all the methods that are decorated with `@log_signal` and return a dictionary of the form:
Collected all the methods that are decorated with ``@log_signal`` and return a dictionary of the form:
.. code-block::
{
<method_name>: {
"interval": <interval_seconds>,
Expand Down
11 changes: 6 additions & 5 deletions alab_management/lab_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ def update_sample_metadata(self, sample: ObjectId | str, metadata: dict[str, Any
def run_subtask(
self, task: type[BaseTask], samples: list[ObjectId | str], **kwargs
):
"""Run a task as a subtask within the task. basically fills in task_id and lab_view for you.
this command blocks until the subtask is completed.
"""
Run a task as a subtask within the task. basically fills in task_id and lab_view for you.
this command blocks until the subtask is completed.
Args:
task (Type[BaseTask]): The type/class of the Task to run.
samples (List[Union[ObjectId, str]]): List of sample IDs or names.
**kwargs: will be passed to the Task method via the parameters entry in the task collection.
task (Type[BaseTask]): The type/class of the Task to run.
samples (List[Union[ObjectId, str]]): List of sample IDs or names.
**kwargs: will be passed to the Task method via the parameters entry in the task collection.
"""
if not issubclass(task, BaseTask):
raise TypeError("task must be a subclass of BaseTask!")
Expand Down
3 changes: 3 additions & 0 deletions alab_management/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def get_latest_device_signal(
Optional[Any]: dictionary with result.
dict example:
.. code-block::
{
"device_name": device_name,
"signal_name": signal_name,
Expand Down
35 changes: 19 additions & 16 deletions alab_management/resource_manager/resource_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,25 @@ class ResourceRequestItem(BaseModel):
class ResourcesRequest(RootModel):
"""
This class is used to validate the resource request. Each request should have a format of
[
{
"device":{
"identifier": "name" or "type" or "nodevice",
"content": string corresponding to identifier
},
"sample_positions": [
{
"prefix": prefix of sample position,
"number": integer number of such positions requested.
},
...
]
},
...
].
.. code-block::
[
{
"device":{
"identifier": "name" or "type" or "nodevice",
"content": string corresponding to identifier
},
"sample_positions": [
{
"prefix": prefix of sample position,
"number": integer number of such positions requested.
},
...
]
},
...
].
See Also
--------
Expand Down
2 changes: 1 addition & 1 deletion alab_management/task_view/task_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CancelingProgress(Enum):
PENDING: The canceling process has been initiated.
WORKER_NOTIFIED: The worker has been notified to cancel the request, which means an
abort error has been raised in the worker.
abort error has been raised in the worker.
"""

PENDING = auto()
Expand Down
File renamed without changes
10 changes: 10 additions & 0 deletions docs/source/advance_topics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Advance Topics

In this section, we will discuss some of the more advanced topics that can help you better set up the lab.

```{toctree}
:maxdepth: 1
:hidden:
test
```
Loading

0 comments on commit 9f3c6db

Please sign in to comment.