-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d7e29d
commit fe5feb4
Showing
25 changed files
with
995 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from examples.common.functions import read_parameter | ||
from runnable import NotebookTask, Pipeline, PythonTask, metric, pickled | ||
|
||
|
||
def main(): | ||
write_parameters_from_notebook = NotebookTask( | ||
notebook="examples/common/write_parameters.ipynb", | ||
returns=[ | ||
pickled("df"), | ||
"integer", | ||
"floater", | ||
"stringer", | ||
"pydantic_param", | ||
metric("score"), | ||
], | ||
name="set_parameter", | ||
) | ||
|
||
read_parameters = PythonTask( | ||
function=read_parameter, | ||
name="get_parameters", | ||
) | ||
|
||
read_parameters_in_notebook = NotebookTask( | ||
notebook="examples/common/read_parameters.ipynb", | ||
terminate_with_success=True, | ||
name="read_parameters_in_notebook", | ||
) | ||
|
||
pipeline = Pipeline( | ||
steps=[write_parameters_from_notebook, read_parameters, read_parameters_in_notebook], | ||
) | ||
|
||
_ = pipeline.execute() | ||
|
||
return pipeline | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
The below example shows how to set/get parameters in python | ||
tasks of the pipeline. | ||
The function, set_parameter, returns | ||
- simple python data types (int, float, str) | ||
- pydantic models | ||
- pandas dataframe, any "object" type | ||
pydantic models are implicitly handled by runnable | ||
but "object" types should be marked as "pickled". | ||
Use pickled even for python data types is advised for | ||
reasonably large collections. | ||
""" | ||
|
||
from examples.common.functions import read_parameter, write_parameter | ||
from runnable import Pipeline, PythonTask, metric, pickled | ||
|
||
|
||
def main(): | ||
write_parameters = PythonTask( | ||
function=write_parameter, | ||
returns=[ | ||
pickled("df"), | ||
"integer", | ||
"floater", | ||
"stringer", | ||
"pydantic_param", | ||
metric("score"), | ||
], | ||
name="set_parameter", | ||
) | ||
|
||
read_parameters = PythonTask( | ||
function=read_parameter, | ||
terminate_with_success=True, | ||
name="get_parameters", | ||
) | ||
|
||
pipeline = Pipeline( | ||
steps=[write_parameters, read_parameters], | ||
) | ||
|
||
_ = pipeline.execute() | ||
|
||
return pipeline | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from examples.common.functions import read_unpickled_parameter | ||
from runnable import Pipeline, PythonTask, ShellTask, metric | ||
|
||
|
||
def main(): | ||
export_env_command = """ | ||
export integer=1 | ||
export floater=3.14 | ||
export stringer="hello" | ||
export pydantic_param='{"x": 10, "foo": "bar"}' | ||
export score=0.9 | ||
""" | ||
write_parameters_in_shell = ShellTask( | ||
command=export_env_command, | ||
returns=[ | ||
"integer", | ||
"floater", | ||
"stringer", | ||
"pydantic_param", | ||
metric("score"), | ||
], | ||
name="write_parameter", | ||
) | ||
|
||
read_parameters = PythonTask( | ||
function=read_unpickled_parameter, | ||
name="read_parameters", | ||
terminate_with_success=True, | ||
) | ||
|
||
pipeline = Pipeline( | ||
steps=[write_parameters_in_shell, read_parameters], | ||
) | ||
|
||
_ = pipeline.execute() | ||
|
||
return pipeline | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
The below example showcases setting up known initial parameters for a pipeline | ||
of notebook and shell based commands. | ||
The initial parameters as defined in the yaml file are: | ||
integer: 1 | ||
floater : 3.14 | ||
stringer : hello | ||
pydantic_param: | ||
x: 10 | ||
foo: bar | ||
runnable exposes the nested parameters as dictionary for notebook based tasks | ||
as a json string for the shell based tasks. | ||
""" | ||
|
||
from runnable import NotebookTask, Pipeline, ShellTask | ||
|
||
|
||
def main(): | ||
read_params_in_notebook = NotebookTask( | ||
name="read_params_in_notebook", | ||
notebook="examples/common/read_parameters.ipynb", | ||
) | ||
|
||
shell_command = """ | ||
if [ "$integer" = 1 ] \ | ||
&& [ "$floater" = 3.14 ] \ | ||
&& [ "$stringer" = "hello" ] \ | ||
&& [ "$pydantic_param" = '{"x": 10, "foo": "bar"}' ]; then | ||
echo "yaay" | ||
exit 0; | ||
else | ||
echo "naay" | ||
exit 1; | ||
fi | ||
""" | ||
read_params_in_shell = ShellTask( | ||
name="read_params_in_shell", | ||
command=shell_command, | ||
terminate_with_success=True, | ||
) | ||
|
||
pipeline = Pipeline( | ||
steps=[read_params_in_notebook, read_params_in_shell], | ||
) | ||
|
||
_ = pipeline.execute(parameters_file="examples/common/initial_parameters.yaml") | ||
|
||
return pipeline | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
dag: | ||
description: | | ||
The below example showcases setting up known initial parameters for a pipeline | ||
of notebook and shell based commands. | ||
The initial parameters as defined in the yaml file are: | ||
integer: 1 | ||
floater : 3.14 | ||
stringer : hello | ||
pydantic_param: | ||
x: 10 | ||
foo: bar | ||
runnable exposes the nested parameters as dictionary for notebook based tasks | ||
as a json string for the shell based tasks. | ||
start_at: read_params_in_notebook | ||
steps: | ||
read_params_in_notebook: | ||
type: task | ||
command_type: notebook | ||
command: examples/common/read_parameters.ipynb | ||
next: read_params_in_shell | ||
read_params_in_shell: | ||
type: task | ||
command_type: shell | ||
command: | | ||
if [ "$integer" = 1 ] \ | ||
&& [ "$floater" = 3.14 ] \ | ||
&& [ "$stringer" = "hello" ] \ | ||
&& [ "$pydantic_param" = '{"x": 10, "foo": "bar"}' ]; then | ||
echo "yaay" | ||
exit 0; | ||
else | ||
echo "naay" | ||
exit 1; | ||
fi | ||
next: success | ||
success: | ||
type: success | ||
fail: | ||
type: fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
The below example showcases setting up known initial parameters for a pipeline | ||
of only python tasks | ||
The initial parameters as defined in the yaml file are: | ||
simple: 1 | ||
complex_param: | ||
x: 10 | ||
y: "hello world!!" | ||
runnable allows using pydantic models for deeply nested parameters and | ||
casts appropriately based on annotation. eg: read_initial_params_as_pydantic | ||
If no annotation is provided, the parameter is assumed to be a dictionary. | ||
eg: read_initial_params_as_json | ||
""" | ||
|
||
from examples.common.functions import ( | ||
read_initial_params_as_json, | ||
read_initial_params_as_pydantic, | ||
) | ||
from runnable import Pipeline, PythonTask | ||
|
||
|
||
def main(): | ||
read_params_as_pydantic = PythonTask( | ||
function=read_initial_params_as_pydantic, | ||
name="read_params_as_pydantic", | ||
) | ||
|
||
read_params_as_json = PythonTask( | ||
function=read_initial_params_as_json, | ||
terminate_with_success=True, | ||
name="read_params_json", | ||
) | ||
|
||
pipeline = Pipeline( | ||
steps=[read_params_as_pydantic, read_params_as_json], | ||
add_terminal_nodes=True, | ||
) | ||
|
||
_ = pipeline.execute(parameters_file="examples/common/initial_parameters.yaml") | ||
|
||
return pipeline | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
dag: | ||
description: | | ||
The below example showcases setting up known initial parameters for a pipeline | ||
of only python tasks | ||
The initial parameters as defined in the yaml file are: | ||
simple: 1 | ||
complex_param: | ||
x: 10 | ||
y: "hello world!!" | ||
runnable allows using pydantic models for deeply nested parameters and | ||
casts appropriately based on annotation. eg: read_initial_params_as_pydantic | ||
If no annotation is provided, the parameter is assumed to be a dictionary. | ||
eg: read_initial_params_as_json | ||
start_at: read_params_as_pydantic | ||
steps: | ||
read_params_as_pydantic: | ||
type: task | ||
command: examples.common.functions.read_initial_params_as_pydantic | ||
next: read_params_json | ||
read_params_json: | ||
type: task | ||
command: examples.common.functions.read_initial_params_as_json | ||
next: success | ||
success: | ||
type: success | ||
fail: | ||
type: fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.