Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into job-cache
- Loading branch information
Showing
74 changed files
with
42,098 additions
and
385 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,94 @@ | ||
.. _chap-list_handling: | ||
|
||
************************** | ||
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. | ||
|
||
.. topic:: 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: | ||
|
||
.. code-block:: python | ||
s1 = ['A', 'B', 'C'] | ||
s2 = ['+', '-', '*'] | ||
s3 = ['1', '2', '3'] | ||
.. topic:: 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 | ||
:ref:`fig-list_handling-list-combine-workflow`. | ||
|
||
.. _fig-list_handling-list-combine-workflow: | ||
|
||
.. figure:: figures/list_handling/list-combine-workflow.png | ||
:align: center | ||
:width: 1.8in | ||
|
||
The complete workflow | ||
|
||
.. topic:: 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 :ref:`fig-list_handling-list-combine`. | ||
|
||
.. _fig-list_handling-list-combine: | ||
|
||
.. figure:: figures/list_handling/list-combine.png | ||
:align: center | ||
|
||
A custom list combiner | ||
|
||
.. topic:: 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: :vtl:`(Open result) <list-handling.vt>` | ||
|
||
.. code-block:: python | ||
A+1 | ||
A-2 | ||
A*3 | ||
B+1 | ||
B-2 | ||
B*3 | ||
C+1 | ||
C-2 | ||
C*3 |
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,94 @@ | ||
.. _chap-streaming: | ||
|
||
********************** | ||
Streaming in VisTrails | ||
********************** | ||
|
||
Streaming data may be useful for a number of reasons, such as to incrementally | ||
update a visualization, or to process more data than fit into memory. | ||
VisTrails supports streaming data through the workflow. By implementing modules | ||
that supports streaming, data items will be passed through the whole workflow | ||
one at a time. | ||
|
||
Using Streaming | ||
=============== | ||
|
||
Streaming is similar to list handling (see Chapter | ||
:ref:`chap-list_handling`). Modules that create streams should output a port | ||
with list depth 1. Downstream modules that do not accept lists will be executed | ||
once for each item in the stream. Modules with multiple input streams will | ||
combine them pairwise. For this reason the input streams should contain the | ||
same number of items (or ben unlimited). | ||
|
||
Modules accepting a type with list depth 1, but does not support streaming, | ||
will convert input streams to lists and execute after the streaming have ended. | ||
|
||
.. topic:: Try it Now! | ||
|
||
Lets use PythonSources to create a simple example that incrementally sums up | ||
a sequence of numbers. First we will create a module that streams the | ||
natural numbers up to some value. Create a new workflow and add a | ||
``PythonSource`` module. Give it an input port named ``inputs`` of type | ||
Integer, which will specify the maxim number to stream, and an output port | ||
named ``out`` of type ``Integer`` with list depth 1, which will be the output | ||
stream. An output stream can be created by using | ||
``self.set_streaming_output``, which takes the port name, an iterator object, | ||
and an optional length of the input items. To create an integer iterator we | ||
can use xrange. Add this to the PythonSource: | ||
|
||
.. code-block:: python | ||
self.set_streaming_output('out', | ||
xrange(inputs).__iter__(), | ||
inputs) | ||
.. topic:: Next Step! | ||
|
||
Now lets create a module that captures the item in the string. Add a second | ||
``PythonSource`` module below the first one. Give it an input port named | ||
``integerStream`` of type Integer and list depth 1 that will be our input | ||
stream. An input stream can be captured by adding the magic string | ||
``#STREAMING`` to the PYthonSource code and calling ``self.set_streaming`` | ||
with a generator method as argument. The generator method should take the | ||
module as an input. It should first initialize its value, in our case set | ||
``intsum=0``. Then it should receive the inputs in a loop ending with yield. | ||
In each iteration the module will be updated to contain a new input in the | ||
stream. Similar to a normal module, the loop should: | ||
|
||
1. get inputs | ||
2. compute outputs | ||
3. set outputs | ||
4. call ``yield`` | ||
|
||
Below is the complete example. Add it to the PythonSource. | ||
|
||
.. code-block:: python | ||
#STREAMING - This tag is magic, do not change. | ||
def generator(module): | ||
intsum = 0 | ||
while 1: | ||
i = module.get_input('integerStream') | ||
intsum += i | ||
print "Sum so far:", intsum | ||
yield | ||
self.set_streaming(generator) | ||
.. topic:: Finally: | ||
|
||
Connect the two PythonSource's, set ``inputs`` to 100 in the first | ||
PythonSource, open the vistrails console and execute. See how the output is | ||
printed to the console while the stream runs and how the progress of the | ||
modules increase. The output should look like this: :vtl:`(open in vistrails) | ||
<streaming.vt>` | ||
|
||
.. code-block:: python | ||
Sum so far: 0 | ||
Sum so far: 1 | ||
Sum so far: 3 | ||
... | ||
Sum so far: 4851 | ||
Sum so far: 4950 |
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 @@ | ||
<vtlink filename="@examples/list-handling.vt" version="combine lists"/> |
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 @@ | ||
<vtlink filename="@examples/streaming.vt" version="add numbers"/> |
Binary file not shown.
Binary file not shown.
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
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.