Question about scientific calculations in Python

Michael Hudson mwh at python.net
Tue Mar 12 07:32:03 EST 2002


Martin Kaufmann <martinkaufmann at yahoo.com> writes:

> Hello Newsgroup
> 
> I'm trying to write a program to calculate diffraction patterns for
> electron diffraction on clusters (100-10'000 atoms). So far I used
> Python only for CGI programming and system tools (on a rather low
> level...). Therefore I don't know whether it's reasonable to program
> such a project in Python (I really like the language). Presently my
> man concern is speed as the main function of the program is a nested
> loop, the inner over several 1000 bins of a histogram and the outer
> over several 1000 values of scattering factors. In the end I should be
> able to simulate diffraction patterns and compare them to the
> experimental data (i.e. run this function several times).
> 
> Now my questions: Would it be best to
> 
> (a) write the whole program in C/C++ (I know only the basics of C but
> it would be a good "excuse" to learn it...)?

Well, you're unlikely to get advised to do this here :)

> (b) write the main program in Python but the heavy calculations in C
> (I played today with scipy.weave -- the speed is much better but I
> didn't really understand what I was doing...)?

This is probably the better option, but first...

> (c) program it in Python and don't care about speed (or buy a new
> workstation...)?

... I'd do this.  Write your algorithm in Python.  Run it on small
examples to test.  See if it's fast enough to run your real problems.
If it's not, go for (b).  It may be possible that modules already
exist to do the heavy lifting -- e.g. Numeric.  It's hard to say for
certain without knowing more about your algorithms.

Things like weave and PyInline may help.

> Are there any libraries or other resources that would help? I used the
> Scientific Python library for the histogram but it was much slower
> than my DIY approach.

Maybe you could submit better code to the SciPy project?

> I hope my questions are not too much OT. 

Don't think so myself.

Cheers,
M.

-- 
  CLiki pages can be edited by anybody at any time. Imagine the most
  fearsomely comprehensive legal disclaimer you have ever seen, and
  double it                        -- http://ww.telent.net/cliki/index



More information about the Python-list mailing list