Why Python?

In the past year, I have increasingly been using Python to develop a variety of OR-related scientific software. In particular, the Coopr library has been a major focus of this software development.

Recently, I have written a paper that will appear in the proceedings of the INFORMS Computing Society Conference 2009:
W. Hart, Python Optimization Modeling Objects (Pyomo), Proc. INFORMS Computing Society Conference, 2009, (to appear).
In this paper, I describe Pyomo, an open-source tool for modeling optimization applications in Python. A key goal of Pyomo is to provide an open-source math programming modeling capability. Although open-source optimization solvers are widely available in packages like COIN-OR, surprisingly few open-source tools have been developed to model optimization applications.

Pyomo has been developed in Python because it is a well-used modern programming language that provides a robust foundation for developing and applying scientific software. In this paper, I noted that Python meets some basic criteria that relate to how Pyomo will be used and managed:
  • Open Source License: Python is freely available, and its liberal open source license lets you modify and distribute a Python-based application with few restrictions.
  • Features: Python has a rich set of datatypes, support for object oriented programming, namespaces, exceptions, and dynamic loading.
  • Support and Stability: Python is highly stable, and it is well supported through newsgroups and special interest groups.
  • Documentation: Users can learn about Python from extensive online documentation, and a number of excellent books that are commonly available.
  • Standard Library: Python includes a large number of useful modules.
  • Extendability and Customization: Python has a simple model for loading Python code developed by a user. Additionally, compiled code packages that optimize computational kernels can be easily used. Python includes support for shared libraries and dynamic loading, so new capabilities can be dynamically integrated into Python applications.
  • Portability: Python is available on a wide range of compute platforms, so portability is typically not a limitation for Python-based applications.
Another factor, not to be overlooked, is the increasing acceptance of Python in the scientific community. Large Python projects like SciPy and SAGE strongly leverage a diverse set of Python packages.

Several other popular programming languages were also considered for Pyomo. However, in most cases Python appears to have distinct advantages:
  • .Net: As mentioned earlier, the .Net languages are not portable to Linux platforms, and thus they were not suitable for Pyomo.
  • Ruby: At the moment, Python and Ruby appear to be the two most widely recommended scripting languages that are portable to Linux platforms, and comparisons suggest that their core functionality is similar. Our preference for Python is largely based on the fact that it has a nice syntax that does not require users to type weird symbols(e.g. \$, \%, @). Thus, we expect this will be a more natural language for expressing math programming models.
  • Java: Java has a lot of the same strengths as Python, and it is arguably as good a choice for Pyomo. However, two aspects of Python recommended it for Pyomo instead of Java. First, Python has a powerful interactive interpreter that allows realtime code development and encourages experimentation with Python software. Thus, users can work interactively with Pyomo models to become familiar with these objects and to diagnose bugs. Second, it is widely acknowledged that Python's dynamic typing and compact, concise syntax makes software development quick and easy. Although some very interesting optimization modeling tools have been developed in languages like C++ and Java, there is anecdotal evidence that users will not be as productive in these languages as they will when using tools developed in languages like Python (see Python vs Java).
  • C++: Models formulated with the FlopC++ package are similar to models developed with Pyomo. They are be specified in a declarative style using classes to represent model components (e.g. sets, variables and constraints). However, C++ requires explicit compilation to execute code, and it does not support an interactive interpreter. Thus, we believe that Python will provide a more flexible language for users.

Comments

  1. I recently came across another interesting comparison between Python and Java: Why is Python more fun than Java?. Although this is a personal reflection on Java vs. Python, the author has actively used Java for some time, and he is not particularly negative about Java per se.

    ReplyDelete

Post a Comment

Popular posts from this blog

Python Plugin Frameworks

SBOMs for Scientific Software: C++

Using AsciiDoc for Mathematical Publications