Tutorials:Code-04 Vistrails Package simple
In this tutorial we will use our Ising example to illustrate how one can create a Vistrails package. Go to your vistrails userpackages directory:
and copy the contents of the directory http://alps.comp-phys.org/static/tutorials2.0.0/code-04-vistrails-simple-package/ising-package ising-package] into it. Then add your python.py file from the Code-01 Tutorial tutorial.
By doing so we have derived "IsingSimulation" from a Vistrails Module class and specified the input ports for our input parameters as well the output port for our result file. If you now open your Vistrails application, choose "Preferences" from the Menu and go to "Module Packages". You will find a Package called "isingpackage", which you can enable. You can now start incorporating your own Module in a Vistrail! See simple_package.vt as an example.
Some more details
Vistrails packages must contain the two files __init__.py and init.py. These take care of separate tasks:
- __init__.py declares the package (name, identifier, version) and defines dependencies.
- init.py should initialize the package. This involves tasks such as registering modules etc.
The reason for this separation is to make the package reloadable. If all of the initialization is placed in __init__.py, the package cannot be reloaded after the first instantiation.
All Vistrails modules must, directly or indirectly, be derived from the class Module. They should contain
- a method compute(self), which is called on execution.
- a definition of input and output ports in the static variables _input_ports and _output_ports. These should be lists of tuples with the first element being the name of the port and the second element being a length-1 list containing the type (which must itself be a valid Module class). Other entries in this list could be used for more advanced options.
The easiest way to register a module with Vistrails is to add it to a global variable _modules in the init.py file.