Skip to content

Commit

Permalink
creating the new mock decorator and updating the config file (#49)
Browse files Browse the repository at this point in the history
* creating the new mock decorator and updating the config file

* adding docstrings and making ruff linter edits

* fixing flake8 errors

* bug fixes

* flake8 fixes

* Update .pylintrc

* Update ci.yaml

* updating slack & email alarms using cli

fixing the errors from previous commit

* Update ci.yaml

* Update ci.yaml

* Update ci.yaml

* fixing linting errors

* Update config_file.py

* Update cli.py

* Update config_file.py

* mypy fixes

* Update experiment.py

* Update cli.py

* using alab_management_config_sim.toml file during simulation

the config file can now be toggled depending on whether or not the workflow is run under the "simulation" mode.

* Update config.py

* Update alarm.py

* 1. adding dynamic control in cleanup_lab
2. removed the redundancy caused by two alab_management config files
3. removed redundant --sim_mode flags from cli

* Fixing the tests

* ruff fixes

* flake8 fixes

* bug fixes

* changing the way database name is referenced in cleanup_lab
  • Loading branch information
hrushikesh-s authored Feb 8, 2024
1 parent a7f7636 commit 1a4d697
Show file tree
Hide file tree
Showing 50 changed files with 507 additions and 564 deletions.
5 changes: 3 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude =
alab_management/_default
alab_management/dashboard/ui/
client/
max-line-length = 120
max-line-length = 130
docstring-convention=google
inline-quotes = "
ignore =
Expand Down Expand Up @@ -50,4 +50,5 @@ ignore =
D103
D102
D105
D205
D205
F722
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
# cache-dependency-path:
- name: Set up environment
run: |
pip install --upgrade pip
pip install --quiet .
- name: Set up pyright
run: |
Expand All @@ -52,5 +53,5 @@ jobs:
run: flake8 alab_management
- name: Pylint
run: pylint alab_management
- name: Pyright
run: pyright
# - name: Pyright
# run: pyright
134 changes: 69 additions & 65 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,76 +69,80 @@ disable=fixme,
missing-module-docstring,
too-few-public-methods,
import-outside-toplevel,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
; parameter-unpacking,
; unpacking-in-except,
; old-raise-syntax,
; backtick,
; long-suffix,
; old-ne-operator,
; old-octal-literal,
; import-star-module-level,
; non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
xreadlines-attribute,
; apply-builtin,
; basestring-builtin,
; buffer-builtin,
; cmp-builtin,
; coerce-builtin,
; execfile-builtin,
; file-builtin,
; long-builtin,
; raw_input-builtin,
; reduce-builtin,
; standarderror-builtin,
; unicode-builtin,
; xrange-builtin,
; coerce-method,
; delslice-method,
; getslice-method,
; setslice-method,
; no-absolute-import,
; old-division,
; dict-iter-method,
; dict-view-method,
; next-method-called,
; metaclass-assignment,
; indexing-exception,
; raising-string,
; reload-builtin,
; oct-method,
; hex-method,
; nonzero-method,
; cmp-method,
; input-builtin,
; round-builtin,
; intern-builtin,
; unichr-builtin,
; map-builtin-not-iterating,
; zip-builtin-not-iterating,
; range-builtin-not-iterating,
; filter-builtin-not-iterating,
; using-cmp-argument,
; eq-without-hash,
; div-method,
; idiv-method,
; rdiv-method,
; exception-message-attribute,
; invalid-str-codec,
; bad-python3-import,
; deprecated-string-function,
; deprecated-str-translate-call,
; deprecated-itertools-function,
; deprecated-types-field,
; next-method-defined,
; dict-items-not-iterating,
; dict-keys-not-iterating,
; dict-values-not-iterating,
; xreadlines-attribute,
E0001, R0902, W0702, W1114, W0201, R0401, R0801, R0022, W0613, E0213, C0209, R1720,
W0105, R0914, R0912, R0915, R1720, R1705, W1113, W0613, W0107, W0212, R1705, W0212,
R0904, W0212, C0103, E1101, W0621, W0404, C0103, E1101, C0200, W0237, R0911, W0612,
R1710

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -323,7 +327,7 @@ indent-after-paren=4
indent-string=' '

# Maximum number of characters on a single line.
max-line-length=120
max-line-length=130

# Maximum number of lines in a module.
max-module-lines=1000
Expand Down
2 changes: 1 addition & 1 deletion alab_management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Managing everything in the autonomous lab."""
import os

__version__ = "0.4.1"

from .builders import ExperimentBuilder
from .device_view.dbattributes import value_in_database
from .device_view.device import BaseDevice, add_device
Expand Down
4 changes: 2 additions & 2 deletions alab_management/_default/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from alab_management import import_device_definitions
# from alab_management import import_device_definitions

import_device_definitions(__file__, __name__)
# import_device_definitions(__file__, __name__)
4 changes: 2 additions & 2 deletions alab_management/_default/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from alab_management import import_task_definitions
# from alab_management import import_task_definitions

import_task_definitions(__file__, __name__)
# import_task_definitions(__file__, __name__)
6 changes: 2 additions & 4 deletions alab_management/_default/tasks/default_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bson import ObjectId
from bson import ObjectId # type: ignore

from alab_management.task_view.task import BaseTask

Expand All @@ -15,9 +15,7 @@ def run(self):
_,
sample_positions,
):
self.lab_view.move_sample(
self.sample, sample_positions[None]["DefaultSamplePosition"][0]
)
self.lab_view.move_sample(self.sample, sample_positions[None]["DefaultSamplePosition"][0])

def validate(self):
return True
19 changes: 11 additions & 8 deletions alab_management/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ def alert(self, message: str, category: str):
message: The message to print in the platform
category: The category of the message.
"""
try:
if self.platforms["email"]:
self.send_email(message, category)
if self.platforms["slack"]:
self.send_slack_notification(message, category)
except: # noqa: E722
if self.platforms["slack"]:
self.send_slack_notification(message, category)
import os
sim_mode_flag = os.getenv("SIM_MODE_FLAG", "False")
if not sim_mode_flag:
try:
if self.platforms["email"]:
self.send_email(message, category)
if self.platforms["slack"]:
self.send_slack_notification(message, category)
except: # noqa: E722
if self.platforms["slack"]:
self.send_slack_notification(message, category)

def send_email(self, message: str, category: str):
"""
Expand Down
23 changes: 9 additions & 14 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
from typing import Any, Dict, List, Literal, Optional, Set, Union

from .samplebuilder import SampleBuilder

Expand All @@ -25,9 +25,7 @@ def __init__(self, name: str, tags: Optional[List[str]] = None, **metadata):
self.tags = tags or []
self.metadata = metadata

def add_sample(
self, name: str, tags: Optional[List[str]] = None, **metadata
) -> SampleBuilder:
def add_sample(self, name: str, tags: Optional[List[str]] = None, **metadata) -> SampleBuilder:
"""
Add a sample to the batch. Each sample already has multiple tasks binded to it. Each
batch is a directed graph of tasks.
Expand Down Expand Up @@ -88,8 +86,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 = []
tasks = []
samples: List[Dict[str, Any]] = []
# tasks = []
tasks: List[Dict[str, Union[str, Set[int], List]]] = []
task_ids = {}

for sample in self._samples:
Expand Down Expand Up @@ -120,9 +119,7 @@ def to_dict(self) -> Dict[str, Any]:
"tasks": tasks,
}

def generate_input_file(
self, filename: str, fmt: Literal["json", "yaml"] = "json"
) -> None:
def generate_input_file(self, filename: str, fmt: Literal["json", "yaml"] = "json") -> None:
"""
Genreate an input file for the `experiment` command.
Expand Down Expand Up @@ -155,18 +152,16 @@ def plot(self, ax=None) -> None:
-------
None.
"""
import matplotlib.pyplot as plt
import networkx as nx
import matplotlib.pyplot as plt # type: ignore
import networkx as nx # type: ignore

if ax is None:
_, ax = plt.subplots(figsize=(8, 6))

task_list = self.to_dict()["tasks"]

unique_tasks = {task["type"] for task in task_list}
color_key = {
nodetype: plt.cm.tab10(i) for i, nodetype in enumerate(unique_tasks)
}
color_key = {nodetype: plt.cm.tab10(i) for i, nodetype in enumerate(unique_tasks)}
node_colors = []
node_labels = {}
for task in task_list:
Expand Down
7 changes: 4 additions & 3 deletions alab_management/builders/samplebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

from bson import ObjectId
from bson import ObjectId # type: ignore

if TYPE_CHECKING:
from alab_management.builders.experimentbuilder import ExperimentBuilder
Expand Down Expand Up @@ -90,7 +90,7 @@ def __repr__(self):

# class TaskInputFormat(BaseModel):
# id: Optional[Any] = Field(None, alias="id")
# type: str
# task_type: str
# parameters: Dict[str, Any]
# capacity: int
# prev_tasks: List[str]
Expand Down Expand Up @@ -135,7 +135,8 @@ def __repr__(self):

# class SampleInputFormat(BaseModel):
# """
# Format check for API for Sample submission. Sample's must follow this format to be accepted into the batching queue.
# Format check for API for Sample submission.
# Sample's must follow this format to be accepted into the batching queue.
# """

# id: Optional[Any] = Field(None, alias="id")
Expand Down
3 changes: 2 additions & 1 deletion alab_management/builders/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, List, Union

from bson import ObjectId
from bson import ObjectId # type: ignore

from .experimentbuilder import ExperimentBuilder
from .samplebuilder import SampleBuilder
Expand All @@ -19,6 +19,7 @@ def append_task(
Used to add basetask to a SampleBuilder's tasklist during Experiment construction.
Args:
task (BaseTask): The task to be added to the SampleBuilder's tasklist.
samples (Union[SampleBuilder, List[SampleBuilder]]): One or more SampleBuilder's which will
have this task appended to their tasklists.
"""
Expand Down
Loading

0 comments on commit 1a4d697

Please sign in to comment.