[Edu-sig] Advice: is python suitable?

Paul Barrett barrett at stsci.edu
Thu Oct 7 16:11:17 CEST 2004

Peter Bowyer wrote:
> Hello list,
> This is semi off-topic, so I'd better introduce myself :-)
> I'm studying physics at the University of Southampton, and joined this 
> list as I hope to use my final year project to create physics 
> simulations in Python to aid students, or (even better) write course 
> material to teach the students how to think about the physics concepts 
> (and program at the same time...).  That is still a year away, and I've 
> not experimented much with Python yet to see how feasible it would be to 
> do this kind of thing.
> This year I'm taking a course in computational physics, which allows the 
> use of any programming language.  The notes however are skewed towards 
> the department's in-house languages (variations on BASIC and C).  I'm 
> hoping one of you could look at the course notes and tell me if there's 
> anything here that is not possible to do in Python?  They are at 
> http://www.phys.soton.ac.uk/teach/year3/notes/ph314/notes/phys3006b.pdf 
> for the BASIC version, and 
> http://www.phys.soton.ac.uk/teach/year3/notes/ph314/notes/phys3006c.pdf 
> for the C version.

I've been using Python for numerical work for over 8 years now without feeling 
constained.  Of course, I supplement Python with C which enables me to solve or 
implement the 10% of the problems that Python does not do well, such as improved 
numerical performance or very low level programming.

I'd suggest going to the SciPy website to get a feel for what is currently 
available.  They have made many numerical algorithms available to Python and to 
Python's numerical extension models.  One utility/application that you should 
also take a look at in order to improve numerical performance is 'Weave', which 
allows you to embed C code directly into your Python code.  Weave will then 
wrap, compile, and use this code fragment on-the-fly.  This eliminates the need 
for having to wrap your own C code to improve performance.

And finally, there is much work on improving the interface between C++ and 
Python, so that your C++ classes appear transparently as Python classes.  Python 
is used as a steering language in this case and the C++ does all of the heavy 
lifting.  There is a massively parallel 3D hydrocode being developed at 
Lawrence-Livermore Nat. Lab that is being implemented in this way.  The benefit 
of this approach is that the C++ classes can be used and tested interactively 
via Python.  Of course this is not possible in a pure C++ environment.  This 
approach provides a huge boost to productivity and reliability.

  -- Paul

Paul Barrett, PhD      Space Telescope Science Institute
Phone: 410-338-4475    ESS/Science Software Branch
FAX:   410-338-4767    Baltimore, MD 21218

More information about the Edu-sig mailing list