April 13, 2018

GSPy: GoldSim/Python Interface for Scripting Support

Posted by 

We want to alert you to an exciting new addition to our model library, a ready-to-use GoldSim/Python interface that enables you to define external functions in pure Python which are called by GoldSim during a simulation. Both 32- and 64-bit binaries are available, so you can choose the appropriate one for your installation of Python. Source code is also included for reference (or further development), if you are interested to see how the interface is implemented.

The GSPy interface provides support for passing scalars, vectors and matrices as input and output arguments, which we anticipate will meet the majority of interested users' needs. For more extensive support of data types (such as Lookup Tables and Time Series Elements), refer to this related model library example: Python DLL. One key difference between the two examples is that Python DLL uses Cython, a code generation tool, and must be compiled before you can use it. In contrast, GSPy does not require Cython-generated compilation and it is distributed with binaries requiring minimal setup. It also supports error relay from the Python module to GoldSim.

The following steps are recommended to get started:

1) Install the 32- or 64-bit Python 3.6 Anaconda distribution here: https://www.anaconda.com/download/. A significant advantage of installing the Anaconda distribution is that it comes already with several widely-used Python libraries such as NumPy, Pandas and SciPy. One of the examples that comes with GSPy uses NumPy to do matrix arithmetic.

2) Download and unzip GSPy.zip and follow the setup and testing instructions in the README.txt file. Binaries include GSPy.pyd and TestGSPy.exe (32- and 64-bit versions). The README provides simple instructions for setting an environment variable (GSPY) with the path to your Python installation and running TestGSPy.exe from a command line console to confirm that everything is set up correctly.

3) After you have confirmed that the GSPy environment is set up correctly, be sure to go through the three GoldSim model examples included in the zip file: GSPyScalarAddition.gsm, GSPyMatrixAddition.gsm and GSPySnowmelt.gsm. It is strongly recommended that you read through the detailed comments in the corresponding Python module files: GSPyModule_ScalarAddition.py, GSPyModule_MatrixAddition.py and GSPyModule_Snowmelt.py (note, as described in the README, you must change the name of the Python file to GSPyModule.py before running the example).

Have fun and please send us questions and feedback at support@goldsim.com. Or better yet, come to our forum and post about it there where everyone can see it. We see great potential in combining the Monte Carlo simulation capabilities of GoldSim with the extensive well-supported and powerful scientific computing Python libraries that are freely available. The more chatter about this the better. So far, the topic has popped up in a couple places (here and here) in our forum. We hope to hear from you.

The following results were generated by GSPySnowmelt.gsm, which calls a Python implementation of the snow-17 snow accumulation and ablation model (Anderson, E. A. (1973), National Weather Service River Forecast System Snow Accumulation and Ablation Model, NOAA Tech. Memo. NWS HYDro-17, 217 pp., U.S. Dep. of Commer., Silver Spring, Md.).


No comments:

Post a Comment