StepsPipeline#
- class petpal.pipelines.steps_containers.StepsPipeline(name: str, step_containers: list[StepsContainer])#
A pipeline for managing and executing a sequence of steps organized in containers, with support for dependencies.
This class allows for the addition, removal, and execution of step containers, as well as managing dependencies between the steps.
- Variables:
name (str) – Name of the steps pipeline.
step_containers (dict[str, StepsContainer]) – Dictionary of step containers in the pipeline.
dependency_graph (nx.DiGraph) – Directed acyclic graph representing dependencies between steps.
See also
StepsContainerInitializes the StepsPipeline with a name and an optional list of step containers.
- Parameters:
name (str) – Name of the steps pipeline.
step_containers (list[StepsContainer]) – Optional list of step containers to add to the pipeline.
- __repr__()#
Provides an unambiguous string representation of the TACsFromSegmentationStep instance.
Important
This
reprdoes not include the dependency graph.- Returns:
str – A string representation showing how the instance can be recreated.
- __str__() str#
Returns a detailed string representation of the StepsPipeline instance.
- Returns:
str – A string describing the steps-pipeline, including its name, the steps in each of the steps-containers, and the output dependencies of each step.
- add_container(step_container: StepsContainer)#
Adds a step container to the pipeline.
- Parameters:
step_container (StepsContainer) – The step container to add.
- Raises:
TypeError – If the step container is not an instance of StepsContainer.
KeyError – If a container with the same name already exists.
- __call__()#
Executes all steps in the pipeline in topologically sorted order.
- add_step(container_name: str, step: StepType)#
Adds a step to a specified container in the pipeline.
- Parameters:
container_name (str) – The name of the container to add the step to.
step (StepType) – The step to add.
- Raises:
KeyError – If the container or step name does not exist or if the step name already exists.
- remove_step(step: str)#
Removes a step from the pipeline based on its name.
- Parameters:
step (str) – The name of the step to remove.
- Raises:
KeyError – If the step name does not exist.
- print_steps_names(container_name: str | None = None)#
Prints the names of all steps in the pipeline or a specific container.
- Parameters:
container_name (Union[str, None], optional) – The name of the container to print step names from. If None, prints step names from all containers.
- Raises:
KeyError – If the container name does not exist.
- print_steps_details(container_name: str | None = None)#
Prints the details of all steps in the pipeline or a specific container.
- Parameters:
container_name (Union[str, None], optional) – The name of the container to print step details from. If None, prints step details from all containers.
- Raises:
KeyError – If the container name does not exist.
- add_dependency(sending: str, receiving: str)#
Adds a dependency between two steps in the pipeline.
- Parameters:
sending (str) – The name of the sending step.
receiving (str) – The name of the receiving step.
- Raises:
KeyError – If either step name does not exist.
RuntimeError – If adding the dependency creates a cycle in the dependency graph.
- get_step_from_node_label(node_label: str) StepType#
Retrieves a step object based on its node label in the dependency graph.
- Parameters:
node_label (str) – The label of the node representing the step.
- Returns:
StepType – The step object.
- Raises:
KeyError – If the step name does not exist in the graph.
- update_dependencies_for(step_name: str, verbose=False)#
Updates the dependencies for a specified step, setting inputs from the outputs of its dependencies. Gets the list of steps that are sending outputs to this step. The order of dependency may matter depending on the implementation of set_input_as_output_from for the step.
- Parameters:
step_name (str) – The name of the step to update dependencies for.
verbose (bool, optional) – If True, prints detailed information during the update process. Defaults to False.
- update_dependencies(verbose=False)#
Updates the dependencies for all steps in the pipeline.
- Parameters:
verbose (bool, optional) – If True, prints detailed information during the update process. Defaults to False.
- get_steps_potential_run_state() dict#
Gets a dictionary representing the potential run state of all steps in topologically sorted order.
- Returns:
dict – Dictionary mapping step names to their potential run state (True if the step can potentially run, False otherwise).
- can_steps_potentially_run() bool#
Checks if all steps in the pipeline can potentially run.
- Returns:
bool – True if all steps can potentially run, False otherwise.
- plot_dependency_graph(figsize: tuple = (12, 12), node_options: dict | None = None, label_options: dict | None = None, draw_options: dict | None = None) None#
Plots the dependency graph of the steps pipeline.
- Parameters:
figsize (tuple, optional) – Figure size for the plot. Defaults to (12, 12).
node_options (dict, optional) – Additional options for drawing nodes. Defaults to None.
label_options (dict, optional) – Additional options for node labels. Defaults to None.
draw_options (dict, optional) – Additional options for the draw_networkx function. Defaults to None.
Notes
We have the following node options.
default_node_options = {'node_size': 2000, 'node_color': 'w', 'node_shape': 'o'} default_label_options = {'verticalalignment': 'center', 'clip_on': False, 'font_size': 15, 'bbox' : dict(facecolor='azure', edgecolor='blue', boxstyle='round', alpha=0.25, linewidth=2) } default_draw_options = {'with_labels': True, 'arrows': True, 'arrowsize': 30, 'width': 2}
- print_dependency_graph()#
Prints a textual representation of the dependency graph for the steps pipeline.
This method outputs the steps in the pipeline in topologically sorted order, showing their dependencies. For each step, it lists the subsequent steps that depend on it, formatted in a tree-like structure.
- classmethod default_steps_pipeline(name='PET-MR_analysis')#
Creates a default steps pipeline with predefined containers and dependencies.
- Contains the following step-containers:
Pre-processing.Kinetic modeling.
The pipeline has the following steps dependency:
from petpal.pipelines.steps_containers import StepsPipeline # Instantiate the default PET/MR pipeline my_pipe = StepsPipeline.default_steps_pipeline() # Plot the dependency graph of the steps pipeline my_pipe.plot_dependency_graph()
- Parameters:
name (str, optional) – Name of the steps pipeline. Defaults to ‘PET-MR_analysis’.
- Returns:
StepsPipeline – A new StepsPipeline instance with default setup.