Feeding the Python a Different Input

Author: Guy Shepherd

Back in April I published a short series of articles outlining how Mo.net and Python could be used together to develop potentially useful applications of interest to actuaries and other user communities.  Following those articles, a number of clients have approached us with ideas of how those building blocks might be extended to provide even richer applications and with questions about how this might be accomplished.  Most of these ideas will require some enhancement to the interface between Mo.net and Python, which we will start to roll out in the next release, but one request was how to change the input data used by the Mo.net projection when being called from Python, which I’m going to cover here.

Unfortunately, the solution to the problem isn’t quite as simple as it might have been, due largely to the primitive data types that Python traditionally uses.  While Mo.net can accept an array of string-based inputs to override those baked-into the model, the closest thing that Python can offer us is a list.  Regrettably, a Python list is not compatible with a .NET array.  This means that our solution must be rather more creative, until such time as we provide additional interfaces to the model that will accept more primitive data types.

Python Script

Using the Python script covered in Part 3 of the series as a basis, I have added some additional code that captures the new series of inputs as a Python list, then exports this to a tab delimited file, and then passes this file into the Mo.net input table.  The complete script, including the additional code is shown below.

Python

Running this script will produce similar output to before, but now it’s using the input values contained in the list defined at line 45.  Changing these input values and rerunning the script will produce different answers

What’s Going On?

The key elements of the Python script are as follows.

Line NumberCommentary
45- 46This defines a new two-dimensional list of input values with headings called inputarray
50-52Create a new output file into which to insert the list of inputs
54-61Write each of the list elements out to the file using a tab delimited (as defined by the \t in line 59)
65-66Create an instance of the Mo.net DataRequest object and pass the new file created above into it.  This overrides the inputtable used by the projection with the values defined in the list and passed into the file.

It’s possible to create multiple rows of inputs in this way by simply extending the inputarray list to hold multiple row of inputs.

Conclusion

I hope this small extension to the original series is helpful.  We will return to the integration potential of Mo.net and other platforms in further blog articles shortly.

Contact Us

Need a Mo.net licence? Get in touch with us today to discuss your modelling requirements.

Was this article helpful?
YesNo

Comments are closed.