Source code for pythonlab.process
"""_____________________________________________________________________
:PROJECT: pythonLab
*process base class*
:details:
:authors: mark doerr (mark@uni-greifswald.de)
Stefan Maak
:date: (creation) 20210410
________________________________________________________________________
"""
import logging
from enum import Enum
from typing import List
from abc import ABC, abstractmethod
# should be done through plugin system
from pythonlab.resource import ServiceResource, LabwareResource
[docs]
class ExecutionConstraint(Enum):
immediate = 1
parallel = 2
[docs]
class PLProcess(ABC):
def __init__(self, priority=10):
self._priority = priority # 0 has the highest priority
self._service_resources = []
self._labware_resources = []
self._substance_resources = []
self._data_resources = []
# indicates that the samples have to started in the same order,as they are added
self.preserve_order = False
self.labware_nodes = {} # dict labware_name --> labware_start_node
self._service_resources = []
self.create_resources()
self.init_service_resources()
[docs]
@abstractmethod
def create_resources(self):
raise NotImplementedError
[docs]
@abstractmethod
def init_service_resources(self):
"""calling all init routines.
If no additional code is required,
this can be called, using
super().init_resources() in an overwriting method.
"""
for resource in self._service_resources:
resource.init()
[docs]
def set_starting_position(
self, resource: LabwareResource, device: ServiceResource, position: int
):
"""
This method gets called when setting the starting position of a labware resource. It exists to be overwritten.
:param resource:
:param device:
:param position:
:return:
"""
[docs]
def add_process_step_priorities(self):
"""we add waiting costs to all jobs, so these will be prioritised by scheduler
should be also add waiting costs before the start, so they will be started first?
:raises NotImplementedError: _description_
"""
[docs]
@abstractmethod
def process(self):
raise NotImplementedError
[docs]
def add_process_step(
self,
service: ServiceResource,
labware: List[LabwareResource],
is_movement: bool = False,
**kwargs,
):
"""
This Method will be overwritten when the process is parsed. It is designed for service resources to add
process steps to the workflow.
:param service:
:param labware:
:param is_movement:
:param kwargs:
:return:
"""
# todo: extend description since this is key to parsing and implementation on new service resources
[docs]
def register_service_resource(self, resource):
logging.debug(f"reg service. res: {resource.name}")
self._service_resources.append(resource)
[docs]
def register_labware_resource(self, resource):
logging.debug(f"reg labware res: {resource.name}")
self._labware_resources.append(resource)
[docs]
def register_substance_resource(self, resource):
logging.debug(f"reg subst res: {resource.name}")
self._substance_resources.append(resource)
[docs]
def register_data_resource(self, resource):
logging.debug(f"reg data res: {resource.name}")
self._data_resources.append(resource)
[docs]
def shutdown_resources(self):
for resource in self._service_resources:
resource.shutdown()
@property
def service_resources(self):
return self._service_resources
@property
def labware_resources(self):
return self._labware_resources
@property
def substance_resources(self):
return self._substance_resources
@property
def data_resources(self):
return self._data_resources
@property
def priority(self):
return self._priority