Skip to content

Commit

Permalink
working experiment definition with labgraph subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
rekumar committed Aug 30, 2023
1 parent b3ebe1a commit 268f58d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
26 changes: 15 additions & 11 deletions alab_management/labgraph_types/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def __init__(
lab_view=lab_view,
priority=priority,
simulation=simulation,
*args,
**kwargs,
labgraph_type="Action",
)

Action.__init__(
self,
name=self.__class__.__name__,
actor=placeholder_actor,
description="An Action Task defined in ALabOS", # TODO add description
*args,
**kwargs,
parameters=kwargs,
# description="An Action Task defined in ALabOS", # TODO add description
# *args,
# **kwargs,
)

# def get_ingredients(self) -> List[Ingredient]:
Expand All @@ -67,9 +67,13 @@ def __init__(
# def create_materials(self) -> List[Material]:
# return [] # TODO

# def to_dict(self):
# return {
# "type": self.__class__.__name__,
# "labgraph_type": "Action",
# "parameters": self.subclass_kwargs,
# }
def to_dict(self):
d = BaseTask.to_dict(self)
d.update(Action.to_dict(self))
return d

def __eq__(self, other):
try:
return self.to_dict() == other.to_dict()
except:
return False
20 changes: 9 additions & 11 deletions alab_management/labgraph_types/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,25 @@ def __init__(
lab_view=lab_view,
priority=priority,
simulation=simulation,
*args,
**kwargs,
labgraph_type="Analysis",
# *args,
# **kwargs,
)

Analysis.__init__(
self,
name=self.__class__.__name__,
analysis_method=placeholder_actor,
description="An Analysis Task defined in ALabOS", # TODO add description
*args,
**kwargs,
parameters=kwargs,
)

def to_dict(self):
d = BaseTask.to_dict(self)
d.update(Analysis.to_dict(self))
return d

# def to_dict(self):
# return {
# "type": self.__class__.__name__,
# "labgraph_type": "Analysis",
# "parameters": self.subclass_kwargs,
# }
def __eq__(self, other):
try:
return self.to_dict() == other.to_dict()
except:
return False
27 changes: 16 additions & 11 deletions alab_management/labgraph_types/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ def __init__(
lab_view=lab_view,
priority=priority,
simulation=simulation,
*args,
**kwargs,
labgraph_type="Measurement",
# *args,
# **kwargs,
)

Measurement.__init__(
self,
name=self.__class__.__name__,
description="A Measurement Task defined in ALabOS", # TODO add description
actor=placeholder_actor,
*args,
**kwargs,
# parameters=self.subclass_kwargs,
# *args,
parameters=kwargs,
)

# def to_dict(self):
# return {
# "type": self.__class__.__name__,
# "labgraph_type": "Measurement",
# "parameters": self.subclass_kwargs,
# }
def to_dict(self):
d = BaseTask.to_dict(self)
d.update(Measurement.to_dict(self))
return d

def __eq__(self, other):
try:
return self.to_dict() == other.to_dict()
except:
return False
7 changes: 4 additions & 3 deletions alab_management/task_view/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from abc import ABC, abstractmethod
import inspect
from typing import Dict, List, Type, TYPE_CHECKING, Optional, Union, Any
from typing import Dict, List, Type, TYPE_CHECKING, Optional, Union, Any, Literal
from bson.objectid import ObjectId
from alab_management.task_view.task_enums import TaskPriority
from inspect import getfullargspec
Expand Down Expand Up @@ -50,6 +50,7 @@ def __init__(
priority: Optional[Union[TaskPriority, int]] = TaskPriority.NORMAL,
simulation: bool = True,
no_parameters: bool = False,
labgraph_type: Literal["Action", "Analysis", "Measurement", None] = None,
*args,
**subclass_kwargs,
):
Expand All @@ -71,7 +72,7 @@ def __init__(self, sample_1: ObjectId, sample_2: Optional[ObjectId],
self.samples = [sample_1, sample_2, sample_3, sample_4]
"""
self.__simulation = simulation

self.labgraph_type = labgraph_type
self.__samples = samples or []
if self.is_simulation:
task_id = task_id or ObjectId() # if None, generate an ID now
Expand Down Expand Up @@ -332,7 +333,7 @@ def add_to(
def to_dict(self) -> Dict[str, Any]:
return {
"type": self.__class__.__name__,
"labgraph_type": None,
"labgraph_type": self.labgraph_type,
"parameters": self.subclass_kwargs,
}

Expand Down

0 comments on commit 268f58d

Please sign in to comment.