Python as a numerical prototyping language.

Discussion in 'Python' started by Carl, Dec 16, 2003.

  1. Carl

    Carl Guest

    I have been using Python for quite some time now and I love it. I use it
    mainly for explorative computing and numerical prototyping, ie testing and
    trying out different kinds of algorithms and computational schemes. The use
    of Python as my first-choice language has made me extremely productive.

    Now, I have always believed that Python is a poor performer in terms of
    numerical speed. My experience, however, is that the efficient use of
    dictionaries, lists, precompiled numerical libraries, etc makes Python a
    higly competitive language for scientific computing (in comparison with
    more traditional languages such as C, C++ and different versions of
    Fortran).

    Where is Python heading? Will it be a viable replacement for traditional
    number-crunching languages in the near-term future?

    Carl
     
    Carl, Dec 16, 2003
    #1
    1. Advertising

  2. Carl

    Oren Tirosh Guest

    On Tue, Dec 16, 2003 at 09:16:33PM +0100, Carl wrote:
    > I have been using Python for quite some time now and I love it. I use it
    > mainly for explorative computing and numerical prototyping, ie testing and
    > trying out different kinds of algorithms and computational schemes. The use
    > of Python as my first-choice language has made me extremely productive.
    >
    > Now, I have always believed that Python is a poor performer in terms of
    > numerical speed. My experience, however, is that the efficient use of
    > dictionaries, lists, precompiled numerical libraries, etc makes Python a
    > higly competitive language for scientific computing (in comparison with
    > more traditional languages such as C, C++ and different versions of
    > Fortran).
    >
    > Where is Python heading? Will it be a viable replacement for traditional
    > number-crunching languages in the near-term future?


    It already is. When dealing with large vectors Numerical Python is your
    friend. The overhead of the interpreter is negligible since most of the
    time is spent in highly optimized vector operations.

    When operations are done on individual objects Python is significantly
    slower than compiled languages but psyco is making great progress in this
    area. It already approaches the performance of C for simple code using
    only integers and floats.

    Oren
     
    Oren Tirosh, Dec 17, 2003
    #2
    1. Advertising

  3. Carl

    Mark Dufour Guest

    > When operations are done on individual objects Python is significantly
    > slower than compiled languages but psyco is making great progress in this
    > area. It already approaches the performance of C for simple code using
    > only integers and floats.


    What are the opinions about Psyco being able to achieve the same great
    speedups for non-simple code at some point in the future? Is the looking up
    of methods/attributes during run-time the biggest problem here? I would
    assume that with ever-increasing computer speeds there's no theoretical limit
    to what might be possible here.. exciting stuff, this!


    Mark Dufour.
    --
    "The employment agency has selected an immature and unproven software package
    and its functionality is at the best close to Office 97," said Microsoft
    representatives.
     
    Mark Dufour, Dec 17, 2003
    #3
  4. Carl

    Lou Pecora Guest

    In article <>,
    Oren Tirosh <> wrote:

    > > Where is Python heading? Will it be a viable replacement for traditional
    > > number-crunching languages in the near-term future?

    >
    > It already is. When dealing with large vectors Numerical Python is your
    > friend. The overhead of the interpreter is negligible since most of the
    > time is spent in highly optimized vector operations.
    >
    > When operations are done on individual objects Python is significantly
    > slower than compiled languages but psyco is making great progress in this
    > area. It already approaches the performance of C for simple code using
    > only integers and floats.
    >
    > Oren


    This is good news. I, too, use Python preferentially for numerics,
    especially exploration of algorithms and numerical techniques. I gave
    up on Mathematica long ago (powerful, but awful for programming) and
    I've avoided MatLab so far (good, but not as nice as Python to program
    and expensive). Only problem ocassionally is that many engineers were
    raised on MatLAB and expect to be handed MatLab files/scripts to just
    run on their data.

    I'll have to check Psyco. If it does what you say, that would be a BIG
    step.

    --
    -- Lou Pecora
    My views are my own.
     
    Lou Pecora, Dec 17, 2003
    #4
  5. Carl

    Oren Tirosh Guest

    On Wed, Dec 17, 2003 at 11:41:16AM +0100, Mark Dufour wrote:
    > > When operations are done on individual objects Python is significantly
    > > slower than compiled languages but psyco is making great progress in this
    > > area. It already approaches the performance of C for simple code using
    > > only integers and floats.

    >
    > What are the opinions about Psyco being able to achieve the same great
    > speedups for non-simple code at some point in the future? Is the looking up
    > of methods/attributes during run-time the biggest problem here?


    Object semantics are indeed the issue. I think that there are tricks that
    could bring it very close to the performance of statically typed languages,
    though. Something like caching of object attribute accessors using hash
    tables indexed by the object type and the interned method name, possibly
    combined with some dynamically generated code.

    > I would assume that with ever-increasing computer speeds there's no
    > theoretical limit to what might be possible here.. exciting stuff, this!


    Improvement in computer speeds will do nothing to the performance gap
    between Python and a compiled language running on the same computer. It
    could make them irrelevant because both are fast enough. This is already
    true for Python on modern processors for all but a handful of compute-
    intensive applications - the original subject of this thread.

    Oren
     
    Oren Tirosh, Dec 18, 2003
    #5
  6. Carl

    Mark Dufour Guest


    > Improvement in computer speeds will do nothing to the performance gap
    > between Python and a compiled language running on the same computer. I


    Computer speeds in itself will not help much in closing the gap, but that was
    not what I meant. When computers become faster though, it becomes possible do
    shift more and more optimization techniques into run-time. Java does a lot of
    optimization during run-time, as does Psyco. I don't think these would have
    been acceptible were computers much slower than they are today. Psyco and
    Java both require enormous amounts of memory too I believe, especially Psyco,
    although that's improving.

    > could make them irrelevant because both are fast enough. This is already
    > true for Python on modern processors for all but a handful of compute-
    > intensive applications - the original subject of this thread.


    Absolutely, Python will become more and more viable, and hence more popular,
    just because of computers becoming faster all the time. Sort of like how C
    and some other languages I forgot became more popular than assembly language,
    I guess :)


    Thanks,
    Mark Dufour.
    --
    "The employment agency has selected an immature and unproven software package
    and its functionality is at the best close to Office 97," said Microsoft
    representatives.
     
    Mark Dufour, Dec 18, 2003
    #6
  7. Carl

    Guest

    Carl <> writes:

    > Now, I have always believed that Python is a poor performer in terms of
    > numerical speed. My experience, however, is that the efficient use of
    > dictionaries, lists, precompiled numerical libraries, etc makes Python a
    > higly competitive language for scientific computing (in comparison with
    > more traditional languages such as C, C++ and different versions of
    > Fortran).


    First, look at http://www.python.org/topics/scicomp/ .

    I am using Python + Numeric since a few years for really
    computing-intensive signal processing and real-time audio processing
    (explorative noise reduction for hearing aids). I code at least twenty
    times faster than I did in pure C. It works great and on some
    occations execution speed has been five times faster than Matlab; on a
    Linux system with kernel modifications, Python with C extensios can
    achieve worst-case latencies of 20 milliseconds or less for
    full-duplex audio processing. At the other hand side, I use it for
    really computing-intensive stuff on a Linux cluster (LAM) with 32
    nodes. Plus, it runs neatly on multiprocessor Alpha or Opteron
    systems, and can run in embedded systems; no need for a graphic card.

    Another quality of Numerical Python that it is very easy to integrate
    C code and very mature stuff from Netlib. Scientfic code can be very
    difficult to test and verify so a good code base for numerical
    routines is paramount. An interesting project for Python would be to
    integrate the GNU scientific library and important Netlib routines as
    far as possible. The module philosophy of Python, as well as Python's
    community culture, supports it very well to use existing code again.

    One thing that is quite easy to do is to start coding everything in
    Python and develop the algorithm; then identify the hot spots by using
    the profiler, and move them to C. Something of the complexity of a MP3
    player with net access and graphic user interface can be easily
    implemented in Python+C today.

    One point about Matlab: The basic Matlab is _expensive_. But in a
    commercial environment Matlab with signal processing extensions costs
    _tens of thousands of dollars_. If I were founding an engineering
    startup, I would avoid Matlab if possible at all.

    >
    > Where is Python heading? Will it be a viable replacement for traditional
    > number-crunching languages in the near-term future?
    >


    For applications like audio, script languages will replace C and C++
    widely in few years, because processors are just fast enough.

    In my eyes, what Python, and Open Source in general, is still lacking
    is an very easy, fast and very high-quality library for scientific and
    financial plotting, although there are lots of good and thougthful
    beginnings like Gnuplot, OpenDX, and many more. This would be an
    essential building block to foster the use of Python in science.

    Another thing that is a hassle for real-time programming on
    multiprocessor systems is the Global Interpreter Lock (GIL). For
    signal processing and real time replacing the GIL by per-object locks
    would be an advance comparable to Linux-2.0. Currently the best
    workaround seems to be the use of shared memory and LAM (by the pypar
    module).

    Johannes

    P.S.

    The mail address above traps spam. Mail to
    string.replace(address, 'web', 'uni-oldenburg')
     
    , Jan 2, 2004
    #7
  8. Carl

    Carl Guest

    wrote:

    > In my eyes, what Python, and Open Source in general, is still lacking
    > is an very easy, fast and very high-quality library for scientific and
    > financial plotting, although there are lots of good and thougthful
    > beginnings like Gnuplot, OpenDX, and many more. This would be an
    > essential building block to foster the use of Python in science.


    I agree! I use Gnuplot, it works OK, but is not perfect. I am also not that
    enthusiastic about the algebra syntax of the Numerics module. I wish it was
    closer to the Matlab syntax, which is much easier to grasp.

    Python + Numeric + pygsl + FFTW + ... is, according to my view, a very good
    alternative to using Matlab, Scilab, or R. What is missing is a large, rich
    scientific library, and a better syntax for manipulating matrices and
    vectors. On the other hand, what Python has got is an enormous amount of
    modules for doing almost anything. For instance, there are Python libraries
    for reading and writing to databases and building interfaces (very
    important for building industry strength applications). So, if only Python
    had a very large, rich, and fast library for numerical calculations and
    scientific plotting I would be as happy as one can be.

    I have used Matlab, Scilab, and R for quite some time. The last year,
    however, I have started to use Python more and more. I wonder why? My guess
    is that Python already is a viable environment for doing explorative data
    analyses and testing numerical algorithms.

    When it comes to speed, I feel that Python + Numeric is up to the task. For
    example, I have been playing around with Monte Carlo simulation using list,
    dictionaries, an numerical vectors and matrices as much as possible, and
    have experienced performance very close to comparable code in C.

    Carl
     
    Carl, Jan 3, 2004
    #8
  9. Johannes.Nix wrote in message news:
    >
    > One point about Matlab: The basic Matlab is _expensive_. But in a
    > commercial environment Matlab with signal processing extensions costs
    > _tens of thousands of dollars_. If I were founding an engineering
    > startup, I would avoid Matlab if possible at all.


    Absolutely.

    About a year ago, I attempted to answer the question "Can Python
    replace Matlab?" for my workplace. The conclusion was "Not quite
    yet", for two reasons.

    The first was purely human: Matlab is entrenched, and there's always
    resistance to change (note: lots of people here still swear by Fortran
    '77).

    The second reason: there's no unified Python environment that gives
    you easy access to plotting capability and an interpreter, a la
    Matlab. Python has the ability to do everything Matlab can (and much
    more!) but it still requires just enough expertise to find, install,
    and learn the various scipy and plotting modules that only the
    early-adopter types are willing to do it.

    Matlab projects around here have a tendency to start as a few .m
    scripts, and to eventually mature into some kind of end-user
    application complete with a simple GUI. This is where Python really
    outshines Matlab: Tkinter and wxPython are far superior to the GUI
    library that's built into Matlab, and the OO nature of Python makes
    these more sophisticated applications much easier to develop and
    maintain.
     
    Lonnie Princehouse, Jan 4, 2004
    #9
  10. Lonnie Princehouse wrote:

    > About a year ago, I attempted to answer the question "Can Python
    > replace Matlab?" for my workplace. The conclusion was "Not quite
    > yet", for two reasons.
    >
    > The first was purely human: Matlab is entrenched, and there's always
    > resistance to change (note: lots of people here still swear by Fortran
    > '77).
    >
    > The second reason: there's no unified Python environment that gives
    > you easy access to plotting capability and an interpreter, a la
    > Matlab. Python has the ability to do everything Matlab can (and much
    > more!) but it still requires just enough expertise to find, install,
    > and learn the various scipy and plotting modules that only the
    > early-adopter types are willing to do it.


    <plug>
    While I completely agree with you that it still requires a fair amount of
    manual labor to get a nice scientific python environment going, you may want
    to take a look at ipython at http://ipython.scipy.org. It tries to provide as
    good of an interactive shell as is feasible, along with improving on the
    default Gnuplot support which Gnuplot.py provides (basically giving simpler
    syntax for the plotting commands). With its concept of profiles, you can
    simply say

    ipython --profile numeric

    and have a command-line shell which preloads a complete matlab-like
    environment. It's not perfect, but users seem to like it.
    </plug>

    Regards,

    Fernando.
     
    Fernando Perez, Jan 6, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Allison
    Replies:
    37
    Views:
    793
    Warren W. Gay VE3WWG
    Mar 4, 2004
  2. Ludovic Brenta
    Replies:
    86
    Views:
    1,372
    Jan C. =?iso-8859-1?Q?Vorbr=FCggen?=
    Feb 19, 2004
  3. Dave Allison

    Announcing new scripting/prototyping language

    Dave Allison, Feb 5, 2004, in forum: C Programming
    Replies:
    35
    Views:
    875
    Warren W. Gay VE3WWG
    Mar 4, 2004
  4. Ludovic Brenta
    Replies:
    77
    Views:
    1,460
    Hyman Rosen
    Feb 26, 2004
  5. Dave Benjamin

    Simple prototyping in Python

    Dave Benjamin, Apr 30, 2004, in forum: Python
    Replies:
    10
    Views:
    500
    Michael Geary
    May 5, 2004
Loading...

Share This Page