A patchflow is a collection of steps that are executed in a specific order. The steps are executed in a sequence and the output of one step is used as the input of the next step.
To create a patchflow "my patchflow", do the following:
-
Create
patchwork/patchflows/MyPatchflow/MyPatchflow.pyAny additional files required for theMyPatchflowshould be placed in the same folder. -
MyPatchflow.pyimplement the classMyPatchflowwhich inherits theStepfrom thepatchwork.stepmodule. The classMyPatchflowis expected to have two methods:__init__: The constructor of the class. It should accept aninputsdictionary as an argument, which contains user specified inputs for the patchflow. In the absence of user specified inputs, default inputs should be specified where feasible. Validation and processing of the inputs should be done here.run: The main method of the class. This method should contain the logic of the patchflow which executes a sequence ofStepsin a specific order and returns a dictionary with the results. Each step's output should be updated in theinputsdictionary and passed to the next step.
-
Update
patchwork/patchflows/__init__.pyto include the new patchflow by importing the classMyPatchflowand adding it to__all__.
from patchwork.step import Step
from patchwork.steps import
{
Step1,
Step2,
Step3
}
class MyPatchflow(Step):
def __init__(self, inputs):
super().__init__(inputs)
if 'input1' not in inputs:
raise ValueError("Missing required input: input1")
self.inputs = inputs
def run(self) -> dict:
out1 = Step1(self.inputs).run()
self.inputs.update(out1)
out2 = Step2(self.inputs).run()
self.inputs.update(out2)
out3 = Step3(self.inputs).run()
self.inputs.update(out3)
return self.inputsfrom .MyPatchflow.MyPatchflow import MyPatchflow
__all__ = [
...
'MyPatchflow',
]