forked from PolusAI/workflow-inference-compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PolusAI#219 from vjaganat90/pyapi
Python API : Full scattering support (with example)
- Loading branch information
Showing
4 changed files
with
115 additions
and
36 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 |
---|---|---|
|
@@ -12,4 +12,4 @@ steps: | |
in: | ||
message1: !* filt_message | ||
message2: !* filt_message | ||
message3: !ii scalar | ||
message3: !ii scalar |
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,58 @@ | ||
from pathlib import Path | ||
|
||
from wic.api.pythonapi import Step, Workflow | ||
|
||
|
||
def build_workflow() -> Workflow: | ||
# scatter on all inputs | ||
# step array_ind | ||
array_ind = Step(clt_path='../../cwl_adapters/array_indices.cwl') | ||
array_ind.input_array = ["hello world", "not", "what world?"] | ||
array_ind.input_indices = [0, 1] | ||
# step echo | ||
echo = Step(clt_path='../../cwl_adapters/echo.cwl') | ||
echo.message = array_ind.output_array | ||
# set up inputs for scattering | ||
scatter_inps = echo.inputs[0] | ||
# assign the scatter and scatterMethod fields | ||
echo.scatter = [scatter_inps] | ||
|
||
# arrange steps | ||
steps = [array_ind, echo] | ||
|
||
# create workflow | ||
filename = 'scatter_pyapi_py' # .yml | ||
wkflw = Workflow(steps, filename) | ||
return wkflw | ||
|
||
|
||
def build_workflow_e3() -> Workflow: | ||
# scatter on a subset of inputs | ||
# step array_indices | ||
array_ind = Step(clt_path='../../cwl_adapters/array_indices.cwl') | ||
array_ind.input_array = ["hello world", "not", "what world?"] | ||
array_ind.input_indices = [0, 2] | ||
# step echo_3 | ||
echo_3 = Step(clt_path='../../cwl_adapters/echo_3.cwl') | ||
echo_3.message1 = array_ind.output_array | ||
echo_3.message2 = array_ind.output_array | ||
echo_3.message3 = 'scalar' | ||
# set up inputs for scattering | ||
msg1 = echo_3.inputs[0] | ||
msg2 = echo_3.inputs[1] | ||
# assign the scatter and scatterMethod fields | ||
echo_3.scatter = [msg1, msg2] | ||
echo_3.scatterMethod = 'flat_crossproduct' | ||
|
||
# arrange steps | ||
steps = [array_ind, echo_3] | ||
|
||
# create workflow | ||
filename = 'scatter_pyapi_py' # .yml | ||
wkflw = Workflow(steps, filename) | ||
return wkflw | ||
|
||
|
||
scatter_wic = build_workflow_e3() | ||
scatter_wic.compile(True) # Do NOT .run() here | ||
scatter_wic.run() |
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
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