Package PythonFrom VLEpyvle, Python-Package for VLE
DescriptionPyVLE is a Python package for using VLE framework into Python. It provides functionnalities such as loading vpz files, modifying conditions values of models, simulating vle models and recovering simulation results. It provides other functionnalities regarding the experiment such as modifying duration or seed, obtaining informations on models and views. PyVLE is one component of a generic solution for developping web applications for VLE framework. UsageThe remaining of this section is based on PyVLE-1.0, the version of PyVLE for VLE-1.0. For download and installation instructions of vle1.0 and pyvle1.0, go to http://www.vle-project.org/wiki/VLE-1.0 First useOnce VLE and PyVLE are installed, you can launch python and import pyvle. $ python Python 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pyvle or >>> from pyvle import Vle The package is mostly based on a Python class Vle. In order to know what functions are available into this package. >>> dir(pyvle.Vle) First simulationIn this first example:
Outputs are not recovered since the output plugin of the view is not storage. Here is a Python script. >>> from pyvle import Vle >>> f = Vle("scale1.vpz","glue") >>> print(f) <pyvle.Vle instance at 0x7fe231515e60> >>> f.listConditions() ['condA', 'condB', 'condScale'] >>> f.listConditionPorts('condScale') ['InputTimeStep', 'OutputTimeStep'] >>> f.getConditionPortValues('condScale', 'OutputTimeStep') 1.0 >>> f.clearConditionPort('condScale', 'OutputTimeStep') >>> f.addRealCondition('condScale', 'OutputTimeStep', 0.5) >>> f.getConditionPortValues('condScale', 'OutputTimeStep') 0.5 >>> f.run() [] Notes:
But this use is deprecated. >>> from pyvle import Vle >>> f=Vle('/tmp/myModel.vpz', 'glue') >>> ... Recover resultsIt can be usefull to recover the results of a simulation. To do this, the output plugin of views of the vpz (or at least the view that is expected) should be set to 'storage'. Call to function 'run' will return dictionaries (one per view) odf results. Here is an example: >>> from pyvle import Vle >>> f = Vle("scale1.vpz","glue") >>> f.setOutputPlugin('view', '', 'local', 'storage') >>> result = f.run() >>> result['view']['Top model:B4.b'][5] 20.0 To access to the ith value of observables 'obs' into the view 'view', the syntax to use is result['view']['obs'][i]:
Simulation of experiment plansExamples above show how to launch one simulation. Nevertheless it is possible to launch a bag of simulations with one call of command In the case only one simulation is required, method 'run()' can be used. In the other case, methods 'runManager' or 'runManagerMatrix' are available to simulate one bag of simulations. For one simulation (see above for interpreting results): >>> import pyvle >>> v=pyvle.Vle('weed1.vpz','weed') >>> result=v.run() # result['view']['path:model.port'][index] For a bag of simulations, results is more complex since they are as many view dictionaries as couples replica, combination. >>> import pyvle >>> v=pyvle.Vle('weed1.vpz','weed') >>> result=v.runManager() # result[replicat_index][combinaison_index]['view']['path:model.port'][index] One can find the connection between 'combinaison_index' and the initial conditions values it corresponds to. >>> import pyvle >>> v=pyvle.Vle('weed1.vpz','weed') >>> v.getCombinations() # n tuples containing the list of initial conditions of the n combinations >>> v.getCombinations()[0] # the list of initial conditions of the first combination >>> v.listConditions() #the list of combinations >>> listConditionPorts('xxx') # the list of names of conditions port of condtion 'xxx' where 'xxx' is the first condition Web applicationsPyVLE can be used for developping web applications, see frameworks Web Python. The package Pylons is the base of a generic solutions for developping web application for VLE : (in french) vle-web. Here is a simple example for cretaing a web application with Pylons : (in french) création d'une application Web References |