Python for Scientific Computing

Jan 1, 2014

Scientific computing requires specialized programming languages and ecosystems of libraries/APIs. General purpose programming languages do get the job done, but a specialized ecosystem and language allows the scientist to be the scientist more often than being the programmer. Or better yet, to find the balance between both.

The programming work during the pursuit of my masters degree involved a lot of prototyping. The results had to be presented in charts. A typical work day would involve implementing five different variations of an idea, testing them all with random generated inputs and comparing the results on a chart. And there was tight deadline because the supervisor would like to know my progress tomorrow.

Up until then I used C/C++ and JAVA for most of my programming needs. But development was slow using those languages. I had used MATLAB too, but the quality of plots in MATLAB was not satisfactory. I couldn't control the appearance a lot either. So I decided to look for open source alternatives. There was R. But R was bulky and I was also not very hopeful that I will be able to use that skill when I get back to the industry.

Around that time, I was having discussions with my supervisor regarding my choice of programming language for implementing our ideas. He was interested in one of the compiled languages. I was interested in trying out something new, open source and of value in the software industry. One day I found out the Matplotlib website. A little playing around with Matplotlib convinced me that this is the way to go. I went to my supervisor the next day and declared that I'll be using Python and the SciPy environment from now on.

Over the next two years I did a lot of development in Python. Both for my studies and also hobby projects. By the end of my masters studies, I had formed some opinion on what comprises of a descent scientific computing platform. I used to suggest the following libraries and modules while mentoring other grad students.

Core Python Packages/Modules

sys

For passing command line arguments to your python script

time

For timestamping or for benchmarking

string

Read and write text in different formats including parsing

math

A very handy library for mathematical operations; also contains built in statistical functions.

random

Allows creating of randomized samples from various probability distribution functions.

External Packages/Modules

SciPy

A Python based ecosystem of open-source software for mathematics, science, and engineering.

NumPy

The fundamental package for scientific computing with Python. Linear algebra, N dimensional array etc. Member of the SciPy ecosystem.

Matplotlib

A library for producing publication quality 2D charts in Python. Can be integrated with GUI libraries like PyQt.

PyQt

Python bindings for a cross platform open source GUI toolkit called Qt. It comes with a standard set of widgets as well as the option of making custom ones. Meets the need for smart clean GUI for Scientific computing. PyQt has a good chance of becoming one of the leading GUI library for scientific and advanced computing. This video shows an impressive GUI for particle system in Maya.