Skip to content

Latest commit

 

History

History
94 lines (72 loc) · 3.58 KB

list_handling.rst

File metadata and controls

94 lines (72 loc) · 3.58 KB

List Handling in VisTrails

VisTrails supports passing typed lists between modules. Ports on modules have a depth parameter specifying the list depth it expects. 0 means no list, 1 is a list, 2 is a list of lists etc. Port depth can be specified either by module creators or in a PythonSource or similar module.

Iterating over lists

Passing a list to a module that does not support lists will cause that module to be executed once for each element in the list. When passing lists on multiple input ports, the inputs will be combined. The default combination is cartesian product, where each element in a list is combined with each element in another list. This combination can be changed by selecting "Looping Options" in the module menu. The options are Cartesian, Pairwise (where the elements are combined pairwise), and Custom. Custom gives you complete control over how inputs are combined and allows you to use both pairwise/cartesian combiners as well as reordering them. The output of an iterated module will be an ordered list with the individual results of the module execution. This will cause modules downstrean to also be iterated over, unless they accept a list as input. Iterated modules will have duplicated connections to show that they are being iterated over. A list of lists will have the connection triplicated etc.

Try it Now!

Lets create a simple example showing how to combine strings. First we will create a module that generates lists of strings. Create a new workflow and add a PythonSource module. Give it three output ports named s1, s2, s3 of type String and set their list depth to 1. Enter this code:

s1 = ['A', 'B', 'C']
s2 = ['+', '-', '*']
s3 = ['1', '2', '3']

Next Step!

Add a ConcatenateString module, connect s1->str1, s2->str2, s3->str3. Notice how the connections going into ConcatenateString are duplicated. This indicates that ConcatenateString will iterate over the list inputs. Add a StandardOutput module and connect ConcatenateString.value to StandardOutput.value. This connection will be duplicated in both ends, indicating they will both be iterated over. Your workflow should now look like Figure fig-list_handling-list-combine-workflow.

The complete workflowThe complete workflow

Next Step!

By default ConcatenateString will combine the inputs using cartesian product ["A+1", "A+2", "A+3", "A-1", ...]. Lets change this. Go to Module Menu->Looping Options and click custom. Right click in the port list and add a pairwise product. Rearrange the ports so that it looks like Figure fig-list_handling-list-combine.

A custom list combinerA custom list combiner

Finally:

str2 and str3 will now be combined pairwise and then combined with str1 using cartesian product. Open the vistrails console and execute the workflow. You should see this output: (Open result) <list-handling.vt>

A+1
A-2
A*3
B+1
B-2
B*3
C+1
C-2
C*3