Tellurium Plugins
Python Wrapper for Tellurium Plugins
 All Data Structures Functions Properties Groups Pages
Working with RoadRunner Plugins

Introduction

The plugin API allows users to easily access roadrunner plugins. Only three concepts need to be understood:

  1. Loading a plugin
  2. Setting and Getting plugin properties
  3. Executing the plugin

Before using the plugin system the plugin library must be imported using the line:

1 import teplugins as tel

To load a plugin called "tel_add_noise" use the Python command:

1 p = tel.Plugin ("tel_add_noise")

The variable p now represents the plugin. Plugins expose a number of properties, these are variables that can be inspected or set. For example the add noise plugin has a property called Sigma. To set this to a particular value we would use:

1 p.Sigma = 0.5

Likewise, properties can be inspected:

1 print p.Sigma

To list all propreties in a plugin use the method listOfProperties. The following uses call together with pprint to make the output more understandable:

1 import pprint
2 pprint.pprint (p.listOfProperties())
3 [['NoiseType', 'Type of noise (Gaussian = 0, Psychological = 1).'],
4 ['Sigma', 'Standard deviation of applied noise'],
5 ['InputData', 'Data Series to apply the noise to'],
6 ['Progress', 'Indicate progress in (0-100%)']]

To run a plugin so that it carries out its function, use the execute method:

1 p.execute()

The results from an execute call will either be saved to a file or more likely via properties of the plugin. As a trivial example, consider a plugin called "add" that has three properties, x, y and z. When the execute() method is called the plugin will take the values stored in x and y, add them together and store the result in z. The following script illustrates how the plugin would be used from Python:

1 import teplugins as tel
2 p = tel.Plugin ("add")
3 p.x = 1.2
4 p.y = 4.5
5 p.execute()
6 print p.z

The following script illustrates a more substantial example using the add_noise plugin

1 import roadrunner
2 import teplugins as tel
3 
4 noisePlugin = tel.Plugin ("tel_add_noise")
5 
6 print noisePlugin.name()
7 print noisePlugin.hint()
8 print noisePlugin.description()
9 
10 print '==== List of properties ===='
11 print noisePlugin.listOfProperties()
12 
13 modelPlugin= tel.Plugin("tel_test_model")
14 test_model = modelPlugin.Model
15 
16 # Create a roadrunner instance
17 rr = roadrunner.RoadRunner()
18 rr.load(test_model)
19 
20 # Generate data
21 data = rr.simulate(0, 10, 50)
22 
23 # The plugin will need a handle to the underlying roadrunner data
24 d = tel.getDataSeries (data)
25 
26 noisePlugin.InputData = d
27 
28 # Get parameter for the 'size' of the noise
29 noisePlugin.Sigma = 5.e-6
30 
31 noisePlugin.InputData.plot()
32 noisePlugin.execute()
33 
34 noisePlugin.InputData.plot()
35 tel.show()
36 
37 print "done"

DataSeries

The plugin system supports a special data type called a Data Series. This is a convenient way to represent rows and colums of data. The data type also has the ability to label columns with a text string and to associate each value in the data series with an additional value called a weight. In practice the data series will usually store experimental data and the weights will represent a measure of undertaintly, perhaps a standard deviation, of the data point. A Data Series can be created using the call:

1 import teplugins as tel
2 data = tel.DataSeries()

Data can be entered into a data series either by loading the data from a specially formated file or from a Python NumPy array. For example:

1 data.readDataSeries ("mydata.txt")

To read numpy arrays into a data series use the code:

1 import numpy as py
2 values = py.array([[1,2],{2,5],[3,7]])
3 data = tel.DataSeries.fromNumPy (values)

The number of rows and columns in a Data Series can be obtained using:

1 print data.rows
2 print data.cols

Currently individual values in a data series can be accessed using the set and get methods:

1 p.setElement (1, 2, 4.567)
2 print p.getElement (1, 2)

Data series can be plotted using the plot method:

1 data.plot()

The following script is an example of using the add_noise plugin. This plugin takes a data series and add a given amount of Guassian noise to all data except the data in the first column.

1 import teplugins as *
2 p = Plugin ("tel_add_noise")
3 p.viewManual()
4 pl = p.listOfProperties()
5 for item in pl:
6  print item
7 
8 p.Sigma = 0.00005
9 series = DataSeries.loadDataSeries ("..\\Examples\\testData.dat")
10 series.plot()
11 p.InputData = series
12 p.execute()
13 p.InputData.plot()
14 
15 print "Test Finished"

Plugins

Plugin objects are instanciated using Plugin class. For example to instanciate a plugin called myplugin, we would use the code:

1 p = Plugin ("myplugin")

All interactions with plugins are via plugin properties. Values can be set and retrieved via plugin properties. For example, if a plugin has a property sigma, we can assign or access the value using the code:

1 p.sigma = 0.1
2 print p.sigma

Plugins have a single method that can be used to excecute the plugin's functionality:

1 p.execute()

Once a plugin has been executed, any output from the plugin can be retrieved via properties. Let's suppose for example there is a plugin all add, which has three properties called, x, y and result. When executed the plugin will take the values in x and y, compute the sum and assign it to result. The plugin can therefore be used as follows:

1 p = Plugin("add")
2 p.x = 3.4
3 p.y = 5.6
4 p.execute()
5 print p.result