pythonlab.pythonlab_reader module

Module with all necessary utility to parse a PythonLab process into a networkx graph. todo: use pydentic to parse it into defined dataclasses

class pythonlab.pythonlab_reader.PLProcessReader[source]

Bases: object

static ast_get_process(process_type, src=None)[source]
static contract_dummys(g: DiGraph)[source]

This function contracts the dummy nodes in the workflow graph. To keep track of which labware participated in which process step throughout exploring if-clauses, break commands, etc. the reader includes dummy nodes into the workflow graph. In this function (after the whole process was read) these dummies are removed by contraction, i.e., remove them and connect all sources of incoming edges to all targets of outgoing edges.

static execute_scope(body: List[AST], scope: Dict[str, Any], runtime_vars: List[str], src: str, devices: List[str], plp: PLProcessSimulator)[source]

Goes through the list of code lines and constructs the workflow graph by manipulation the process state and executing certain lines of process description code. Ment to be called recursively :param plp: :param devices: List of variables that correspond to ServiceResources :param src: source code of the process description :param body: list of parsed code fragments :param scope: variables assigned so var :param runtime_vars: list of variable names in current scope that are evaluated at runtime :return: Nothing

static handle_assign(asg: Assign, scope: Dict[str, Any], runtime_vars: List[str], src: str, devices: List[str], plp: PLProcessSimulator)[source]
static handle_break(scope: Dict[str, Any], plp: PLProcessSimulator)[source]
static handle_expr(expr: Expr, scope: Dict[str, Any], runtime_vars: List[str], src: str)[source]
static handle_for(node: For, scope: Dict[str, Any], runtime_vars: List[str], src: str, devices: List[str], plp: PLProcessSimulator)[source]
static handle_if(node: If, scope: Dict[str, Any], runtime_vars: List[str], src: str, devices: List[str], plp: PLProcessSimulator)[source]
static parse_process(plp: PLProcess, src=None, scope: dict | None = None)[source]

The main function. It takes a PythonLabProcess and derives a SMProcess from it. The Information is stored in Job and LabwareInfo classes from the structures-module.

static parse_process_from_file_path(file_path: str | Path)[source]
static parse_process_from_instance(plp: PLProcess)[source]
static parse_process_from_source_code(src: str)[source]
class pythonlab.pythonlab_reader.PLProcessSimulator(process_type: Type[PLProcess])[source]

Bases: PLProcess, ABC

A utility class to help going through actions in a PythonLabProcess while linking them correctly. This is done by systematically recursively exploring the abstract syntax tree and executing all functions of ServiceResources while keeping track of the labware. Each call of a function of a ServiceResource adds a new process step node to the workflow graph. The edges are determined by consecutive participation of labware in two steps.

_abc_impl = <_abc._abc_data object>
add_break_node()[source]
add_computation(name, var_names, fct_code, needed_scope)[source]
add_edge(s, t, **kwargs)[source]
add_if_node(var_names, decision_code, needed_scope)[source]
add_node(attr)[source]
add_process_step(resource: ServiceResource, labware: List[LabwareResource], is_movement: bool = False, **kwargs)[source]

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:

add_var_nodes(*args)[source]
finalize_break_node(break_node)[source]
finalize_if_construction(if_node, orig_state, last_break=-1)[source]
get_state()[source]
handle_labels(t, **kwargs)[source]

Very preliminary handling of relations between process steps independent of labware :param t: :param kwargs: :return:

join_state(status)[source]
prepare_false_execution(if_node)[source]
prepare_true_execution(if_node)[source]
register_labware_resource(resource)[source]
set_starting_position(resource: LabwareResource, device: ServiceResource, position: int)[source]

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:

set_state(status)[source]
visualize_workflow_graph(show=True)[source]
pythonlab.pythonlab_reader.find_pl_process_class(module: ModuleType) type[PLProcess][source]
pythonlab.pythonlab_reader.get_source_code(src: str, node: AST) str[source]