Skip to content

Commit fed8845

Browse files
authored
fix: docs and removing pytorch
* fix: mock executor fix * fix: remove pytorch, we will revisit later * docs: improved docs and examples * test: writting more unit tests
1 parent f77fb13 commit fed8845

34 files changed

+286
-2254
lines changed

docs/concepts/job_intro.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Jobs are isolated unit of work which can be python functions, jupyter notebooks or shell scripts.
2+
3+
4+
5+
Considering a simple function:
6+
7+
```python
8+
def add_numbers(x: int, y: int):
9+
# save some data in data.csv
10+
return x + y
11+
```
12+
13+
The runnable representation of it is:
14+
15+
```python
16+
from functions import add_numbers
17+
from runnable import PythonJob, Catalog
18+
19+
write_catalog = Catalog(put=["data.csv"])
20+
job = PythonJob(function=add_numbers,
21+
returns["sum_of_numbers"],
22+
catalog=write_catalog,
23+
)
24+
25+
```
26+
27+
```PythonJob``` requires a function to call. The input parameters are passed in
28+
from the parameters provided at the time of execution.
29+
30+
The return parameters are stored for future reference. Any data object generated in the
31+
process can be saved to the catalog.
32+
33+
<hr style="border:2px dotted orange">
34+
35+
36+
## Python functions
37+
38+
You can use Python functions as jobs in a pipeline, enabling flexible encapsulation of logic, parameter passing, result capturing, and cataloging of outputs.
39+
40+
=== "Basic Python Function as a Job"
41+
```python
42+
--8<-- "examples/11-jobs/python_tasks.py"
43+
```
44+
45+
The stdout (e.g., "Hello World!") and logs are captured and stored in the catalog for traceability.
46+
47+
=== "Writing Data to the Catalog"
48+
```python
49+
--8<-- "examples/11-jobs/catalog.py"
50+
```
51+
52+
The `Catalog` object specifies which files or data should be saved after job execution.
53+
54+
=== "Passing and Returning Parameters"
55+
56+
```python
57+
--8<-- "examples/11-jobs/passing_parameters_python.py"
58+
```
59+
60+
Parameters can be passed at execution time, and returned values can be automatically handled, serialized, and tracked as metrics.
61+
62+
---
63+
64+
## Notebooks
65+
66+
You can also use Jupyter notebooks as jobs in your pipeline. This allows you to encapsulate notebook logic, capture outputs, and integrate notebooks seamlessly into your workflow.
67+
68+
=== "Notebook as a Job"
69+
```python
70+
--8<-- "examples/11-jobs/notebooks.py"
71+
```
72+
The output of the notebook will be captured as execution log
73+
along with the actual notebook and stored in the catalog for traceability.
74+
75+
---
76+
77+
## Shell script
78+
79+
You can also use shell scripts or commands as jobs in your pipeline. This allows you to execute any shell command, capture its output, and integrate it into your workflow.
80+
81+
=== "Shell Script"
82+
```python
83+
--8<-- "examples/11-jobs/scripts.py"
84+
```
85+
The stdout and stderr of the shell command are captured as execution log and stored in the catalog for traceability.
86+
87+
For more advanced examples, see the files in `examples/11-jobs/`.

docs/concepts/nesting.md

Lines changed: 4 additions & 1326 deletions
Large diffs are not rendered by default.

docs/concepts/parallel.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ The step ```Train Models``` is a parallel step that has the ```branches``` as th
6464

6565
def main():
6666
train_models = Parallel(name="train models",
67-
branches={'baseline': get_baseline_pipeline, 'cnn': get_cnn_pipeline()},
67+
branches={
68+
'baseline': get_baseline_pipeline,
69+
'cnn': get_cnn_pipeline()
70+
},
6871
terminate_with_success=True)
6972
pipeline = Pipeline(steps=[train_models])
7073

@@ -123,12 +126,12 @@ The parallel step is considered successful only if all the branches of the step
123126

124127
=== "sdk"
125128

126-
```python linenums="1" hl_lines="53-57"
129+
```python linenums="1""
127130
--8<-- "examples/06-parallel/parallel.py"
128131
```
129132

130133
=== "yaml"
131134

132-
```yaml linenums="1" hl_lines="40-45"
135+
```yaml linenums="1""
133136
--8<-- "examples/06-parallel/parallel.yaml"
134137
```

docs/concepts/pipeline.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ This behavior can be over-ridden to follow a different path based on expected fa
108108

109109

110110
```step 1``` fails as the function raises an exception.
111-
```step 4``` is an alternate node to a successful execution.
112111

113-
```step 4``` is the step to execution in case of the failure.
112+
```step 4``` is a single node pipeline to execute if ```step1``` fails. The failure
113+
pipeline can have as many steps as needed.
114+
114115

115116
=== "pseudo code"
116117

@@ -126,7 +127,7 @@ This behavior can be over-ridden to follow a different path based on expected fa
126127

127128
=== "sdk"
128129

129-
```python linenums="1" hl_lines="24 29 34 31"
130+
```python linenums="1""
130131
--8<-- "examples/02-sequential/on_failure_succeed.py"
131132
```
132133

@@ -135,17 +136,18 @@ This behavior can be over-ridden to follow a different path based on expected fa
135136

136137
=== "yaml"
137138

138-
```yaml linenums="1" hl_lines="23 25 32-34"
139+
```yaml linenums="1""
139140
--8<-- "examples/02-sequential/on_failure_succeed.yaml"
140141
```
141142

142143

143144
### On failure fail
144145

145146
```step 1``` fails as the function raises an exception.
146-
```step 4``` is an alternate node to a successful execution.
147147

148-
```step 4``` is the step to execution in case of the failure.
148+
```step 4``` is a single node pipeline to execute if ```step1``` fails. The failure
149+
pipeline can have as many steps as needed.
150+
149151

150152
=== "pseudo code"
151153

@@ -162,15 +164,13 @@ This behavior can be over-ridden to follow a different path based on expected fa
162164

163165
=== "sdk"
164166

165-
```python linenums="1" hl_lines="24 29 34 31"
167+
```python linenums="1""
166168
--8<-- "examples/02-sequential/on_failure_fail.py"
167169
```
168170

169-
1. ```terminate_with_failure``` is ```true``` traverses to fail node.
170-
171171

172172
=== "yaml"
173173

174-
```yaml linenums="1" hl_lines="23 25 32-34"
174+
```yaml linenums="1""
175175
--8<-- "examples/02-sequential/on_failure_fail.yaml"
176176
```

docs/concepts/index.md renamed to docs/concepts/pipeline_intro.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### Pipeline
2+
13
Without any orchestrator, the simplest pipeline could be the below functions:
24

35

@@ -47,8 +49,8 @@ pipeline.execute()
4749
- Tasks can [access and return](parameters.md/#access_returns) parameters.
4850
- Tasks can also share files between them using [catalog](catalog.md).
4951
- Tasks are stitched together as [pipeline](pipeline.md)
50-
- The execution environment is configured via # todo
51-
52+
- The execution environment is configured via
53+
# TODO: figure this link
5254

5355
## Examples
5456

docs/concepts/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Uses python functions as tasks.
2626
than the pipeline definition, if you are using Python SDK.
2727

2828

29-
```python linenums="1" hl_lines="29-33"
29+
```python linenums="1""
3030
--8<-- "examples/01-tasks/python_tasks.py"
3131
```
3232

@@ -54,7 +54,7 @@ Uses python functions as tasks.
5454

5555
```
5656

57-
```yaml linenums="1" hl_lines="20-23"
57+
```yaml linenums="1""
5858
--8<-- "examples/01-tasks/python_tasks.yaml"
5959
```
6060

@@ -77,13 +77,13 @@ the name of the notebook and is also saved in the ```catalog``` for logging and
7777

7878
=== "sdk"
7979

80-
```python linenums="1" hl_lines="29-33"
80+
```python linenums="1""
8181
--8<-- "examples/01-tasks/notebook.py"
8282
```
8383

8484
=== "yaml"
8585

86-
```yaml linenums="1" hl_lines="27-31"
86+
```yaml linenums="1""
8787
--8<-- "examples/01-tasks/notebook.yaml"
8888
```
8989

@@ -102,13 +102,13 @@ ecosystem while shell provides a interface to non-python executables.
102102

103103
=== "sdk"
104104

105-
```python linenums="1" hl_lines="22-26"
105+
```python linenums="1""
106106
--8<-- "examples/01-tasks/scripts.py"
107107
```
108108

109109
=== "yaml"
110110

111-
```yaml linenums="1" hl_lines="16-23"
111+
```yaml linenums="1""
112112
--8<-- "examples/01-tasks/scripts.yaml"
113113
```
114114

@@ -135,12 +135,12 @@ Stub nodes can take arbitrary number of parameters and is always a success.
135135

136136
=== "sdk"
137137

138-
```python linenums="1" hl_lines="23 28 30"
138+
```python linenums="1""
139139
--8<-- "examples/01-tasks/stub.py"
140140
```
141141

142142
=== "yaml"
143143

144-
```yaml linenums="1" hl_lines="19-29"
144+
```yaml linenums="1""
145145
--8<-- "examples/01-tasks/stub.yaml"
146146
```

docs/usage.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ They can be installed by ```"pip install runnable[<extra>]"```
2020
- ```notebook``` : enables notebooks as tasks/jobs
2121
- ```k8s``` : enables running jobs in kubernetes or minikube clusters
2222
- ```s3``` : enables using ```s3``` buckets for ```run log store``` and ```catalog```
23-
- ```torch``` : enables to run pytorch jobs or as tasks in pipeline
2423

2524

2625
## Usage
@@ -53,26 +52,7 @@ runnable execute
5352
5453
### Execute a job
5554
56-
Jobs defined in **runnable** can be either via [python sdk](reference.md) or ```yaml``` based definitions.
57-
58-
The options are detailed below:
59-
60-
```shell
61-
Usage: runnable submit-job [OPTIONS] JOB_DEFINITION_FILE
62-
63-
╭─ Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
64-
* job_definition_file TEXT The yaml file containing the job definition [default: None] [required] │
65-
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
66-
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
67-
│ --config -c TEXT The configuration file specifying the services │
68-
│ --parameters -p TEXT Parameters, in yaml, accessible by the application │
69-
│ --log-level [INFO|DEBUG|WARNING|ERROR|FATAL] The log level [default: WARNING] │
70-
│ --tag TEXT A tag attached to the run │
71-
│ --run-id TEXT An optional run_id, one would be generated if its not provided │
72-
│ --help Show this message and exit. │
73-
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
74-
```
75-
55+
Jobs defined in **runnable** can be via [python sdk](reference.md)
7656
7757
<hr style="border:2px dotted orange">
7858

examples/01-tasks/stub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
1414
You can run this pipeline by:
1515
python examples/01-tasks/stub.py
16+
17+
You can execute this pipeline by:
18+
19+
python examples/01-tasks/stub.py
1620
"""
1721

1822
from runnable import Pipeline, Stub

examples/02-sequential/conditional.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ def when_tails_function():
1010

1111

1212
def toss_function():
13+
import os
1314
import random
1415

16+
if "FIX_RANDOM_TOSS" in os.environ:
17+
# Use the fixed value for testing
18+
toss = os.environ["FIX_RANDOM_TOSS"]
19+
print(f"Using fixed toss result: {toss}")
20+
return toss
21+
1522
# Simulate a coin toss
1623
toss = random.choice(["heads", "tails"])
1724
print(f"Toss result: {toss}")
@@ -52,3 +59,4 @@ def main():
5259

5360
if __name__ == "__main__":
5461
main()
62+
main()

examples/02-sequential/traversal.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
44
python examples/02-sequential/traversal.py
55
6-
A pipeline can have any "tasks" as part of it. In the
7-
below example, we have a mix of stub, python, shell and notebook tasks.
8-
9-
As with simpler tasks, the stdout and stderr of each task are captured
10-
and stored in the catalog.
6+
A pipeline can have any "tasks" as part of it. In the
7+
below example, we have a mix of stub, python, shell and notebook tasks.
118
9+
As with simpler tasks, the stdout and stderr of each task are captured
10+
and stored in the catalog.
1211
"""
1312

1413
from examples.common.functions import hello

0 commit comments

Comments
 (0)