Python advocacy in scientific computation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Kern

    #16
    Re: Python advocacy in scientific computation

    Brian Blais wrote:[color=blue]
    > here, I've found python to be good, but not great. matplotlib (pylab) is a really
    > great thing, but is not as straightforward as plotting in Matlab. Either, you have a
    > window which locks the process until you close it, or you do interactive mode, but
    > the window results disappear if any other window is put on top (like your shell), and
    > has to be manually redrawn. This makes it far less convenient to deal with in
    > interactive mode.[/color]

    All I can say is that I've never seen anything like that behavior. Are you tried
    using ipython in pylab mode?

    --
    Robert Kern
    robert.kern@gma il.com

    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter

    Comment

    • Brian Blais

      #17
      Re: Python advocacy in scientific computation

      Robert Kern wrote:[color=blue]
      >
      > That said, we have an excellent array object far superior to Matlab's.
      >
      > http://numeric.scipy.org/
      >[/color]

      I'd like to ask, being new to python, in which ways is this array object far superior
      to Matlab's? (I'm not being sarcastic, I really would like to know!)

      I've heard similar things about matplotlib, about how it surpasses Matlab's graphics.
      I haven't personally experienced this, but I'd like to know in which ways it is.



      bb



      --
      -----------------

      bblais@bryant.e du


      Comment

      • sturlamolden

        #18
        Re: Python advocacy in scientific computation


        Robert Kern wrote:
        [color=blue]
        > 1. Write grant proposals.
        >
        > 2. Advise and teach students.[/color]

        Sorry I forgot the part about writing grant applications. As for
        teaching students, I have thankfully not been bothered with that too
        much.


        [color=blue]
        > Yes, and this is why you will keep saying, "My simulation is running too
        > slowly," and "My simulation is running out of memory." All the vectorization you
        > do won't make a quadratic algorithm run in O(n log(n)) time. Knowing the right
        > algorithm and the right data structures to use will save you programming time
        > and execution time. Time is money, remember, and every hour you spend tweaking
        > Matlab code to get an extra 5% of speed is just so much grant money down the drain.[/color]

        Yes, and that is why I use C (that is ISO C99, not ANSI C98) instead of
        Matlab for everything except trivial tasks. The design of Matlab's
        language is fundamentally flawed. I once wrote a tutorial on how to
        implement things like lists and trees in Matlab (using functional
        programming, e.g. using functions to represent list nodes), but it's
        just a toy. And as Matlab's run-time does reference counting insted of
        proper garbage collection, any datastructure more complex than arrays
        are sure to leak memory (I believe Python also suffered from this as
        some point). Matlab is not useful for anything except plotting data
        quickly. And as for the expensive license, I am not sure its worth it.
        I have been considering a move to Scilab for some time, but it too
        carries the burden of working with a flawed language.

        Comment

        • Michael Tobis

          #19
          Re: Python advocacy in scientific computation

          > $ rm `find . -name "*.pyc"`

          Ouch. Is that a true story?

          While we're remeniscing about bad typos and DEC, I should tell the
          story about the guy who clobberred his work because his English wasn't
          very strong.

          Under RT-11, all file management was handled by a program called PIP.
          For example to get a list of files in the current working directory you
          would enter PIP *.* /LI . Well this fellow, from one of those countries
          where our long "e" sound is their "i" sound, mournfully announced

          "I vanted a deerectory so I typed 'PIP *.* /DE' "

          That one is true.

          mt

          Comment

          • Robert Kern

            #20
            Re: Python advocacy in scientific computation

            Michael Tobis wrote:[color=blue][color=green]
            >> $ rm `find . -name "*.pyc"`[/color]
            >
            > Ouch. Is that a true story?[/color]

            Yup. Fortunately, it was a small, purely personal project, so it was no huge
            loss. It was enough for me to start using CVS on my small, purely personal
            projects, though!

            --
            Robert Kern
            robert.kern@gma il.com

            "I have come to believe that the whole world is an enigma, a harmless enigma
            that is made terrible by our own mad attempt to interpret it as though it had
            an underlying truth."
            -- Umberto Eco

            Comment

            • Alex Martelli

              #21
              Re: Python advocacy in scientific computation

              sturlamolden <sturlamolden@y ahoo.no> wrote:
              [color=blue]
              > just a toy. And as Matlab's run-time does reference counting insted of
              > proper garbage collection, any datastructure more complex than arrays
              > are sure to leak memory (I believe Python also suffered from this as
              > some point).[/color]

              Yes, that was fixed in the move from 1.5.2 to 2.0 (I don't recall if the
              intermediate short-lived 1.6 also fixed it, but nobody used that
              anyway;-).
              [color=blue]
              > Matlab is not useful for anything except plotting data
              > quickly. And as for the expensive license, I am not sure its worth it.
              > I have been considering a move to Scilab for some time, but it too
              > carries the burden of working with a flawed language.[/color]

              There was a pyscilab once, still around at
              <http://pdilib.sourcefo rge.net/>, but I don't think it ever matured
              beyond a "proof of concept" release 0.1 or something.


              Alex

              Comment

              • Robert Kern

                #22
                Re: Python advocacy in scientific computation

                sturlamolden wrote:[color=blue]
                > Robert Kern wrote:[/color]
                [color=blue][color=green]
                >>Yes, and this is why you will keep saying, "My simulation is running too
                >>slowly," and "My simulation is running out of memory." All the vectorization you
                >>do won't make a quadratic algorithm run in O(n log(n)) time. Knowing the right
                >>algorithm and the right data structures to use will save you programming time
                >>and execution time. Time is money, remember, and every hour you spend tweaking
                >>Matlab code to get an extra 5% of speed is just so much grant money down the drain.[/color]
                >
                > Yes, and that is why I use C (that is ISO C99, not ANSI C98) instead of
                > Matlab for everything except trivial tasks. The design of Matlab's
                > language is fundamentally flawed. I once wrote a tutorial on how to
                > implement things like lists and trees in Matlab (using functional
                > programming, e.g. using functions to represent list nodes), but it's
                > just a toy. And as Matlab's run-time does reference counting insted of
                > proper garbage collection, any datastructure more complex than arrays
                > are sure to leak memory (I believe Python also suffered from this as
                > some point).[/color]

                Python still uses reference counting and has several very good data structures
                more complex than arrays. And yet, most programs don't leak memory.
                [color=blue]
                > Matlab is not useful for anything except plotting data
                > quickly. And as for the expensive license, I am not sure its worth it.
                > I have been considering a move to Scilab for some time, but it too
                > carries the burden of working with a flawed language.[/color]

                And you need to ask why Python is a better Matlab than Matlab?

                --
                Robert Kern
                robert.kern@gma il.com

                "I have come to believe that the whole world is an enigma, a harmless enigma
                that is made terrible by our own mad attempt to interpret it as though it had
                an underlying truth."
                -- Umberto Eco

                Comment

                • Robert Kern

                  #23
                  Re: Python advocacy in scientific computation

                  Brian Blais wrote:[color=blue]
                  > Robert Kern wrote:
                  >[color=green]
                  >>That said, we have an excellent array object far superior to Matlab's.
                  >>
                  >> http://numeric.scipy.org/[/color]
                  >
                  > I'd like to ask, being new to python, in which ways is this array object far superior
                  > to Matlab's? (I'm not being sarcastic, I really would like to know!)[/color]

                  Matlab takes the view that "everything is a rank-2 matrix of floating point values."

                  Our arrays have been N-dimensional since day one. They really are arrays, not
                  matrices. You have complete control over the types.

                  --
                  Robert Kern
                  robert.kern@gma il.com

                  "I have come to believe that the whole world is an enigma, a harmless enigma
                  that is made terrible by our own mad attempt to interpret it as though it had
                  an underlying truth."
                  -- Umberto Eco

                  Comment

                  • sturlamolden

                    #24
                    Re: Python advocacy in scientific computation

                    Robert Kern wrote:
                    [color=blue]
                    > And you need to ask why Python is a better Matlab than Matlab?[/color]


                    First there are a few things I don't like:

                    1. Intendation as a part of the syntax, really annoying.

                    2. The "self.something " syntax is really tedious (look to ruby)!

                    4. Multithreading and parallel execution is impossible AFAIK because of
                    the so-called GIL (global interpreter lock). Matlab is perhaps even
                    worse in this respect.

                    5. I don't like numpy's array slicing. Array operations should be a
                    part of the language, as in Matlab, Fortran 90, Ada 95, D, Octave.


                    And there is a couple of questions I need answered:

                    1. Can python do "pass by reference"? Are datastructures represented by
                    references as in Java (I don't know yet).

                    2. How good is matplotlib/pylab? I tried to install it but only get
                    error messages so I haven't tested it. But plotting capabilities is
                    really major issue.

                    3. Speed. I haven't seen any performance benchmarks that actually deals
                    with things that are important for scientific programs.

                    4. Are there "easy to use" libraries containing other stuff important
                    for scientific programs, e.q. linear algebra (LU, SVD, Cholesky),
                    Fourier transforms, etc. E.g. in Matlab I can just type,

                    [u,s,v] = svd(x) % which calls LAPACK linked to ATLAS or
                    vendor-optimized BLAS

                    Even though the language itself is very limited this type of library
                    functionality more than makes up for it.


                    I have looked for alternatives to Matlab for quite a while, mainly due
                    to the cost, the åpoor speed and poor memory management. I am not sure
                    it is Python but so far I have not found anything mor promising either.

                    Comment

                    • Duncan Booth

                      #25
                      Re: Python advocacy in scientific computation

                      sturlamolden wrote:
                      [color=blue]
                      > First there are a few things I don't like:
                      >
                      > 1. Intendation as a part of the syntax, really annoying.[/color]

                      Each to his own. I find having the compiler enforce indentation rules is a
                      real benefit. There's nothing quite so annoying as having 'coding
                      standards' you are supposed to be following which aren't enforced (so
                      nobody else working on the code followed them either). C code which never
                      executes a for loop because of a spurious ';' can be pretty annoying too.
                      [color=blue]
                      >
                      > 2. The "self.something " syntax is really tedious (look to ruby)![/color]

                      I find it really useful to use a similar style when programming in other
                      languages such as Java or C#. In particular it means that you can
                      instantly see when you are referring to a member variable (without
                      having to prefix them all with m_ or some other abomination) and when you
                      have method arguments which get assigned to member variables you don't have
                      to think of different names for each.
                      [color=blue]
                      >
                      > 4. Multithreading and parallel execution is impossible AFAIK because of
                      > the so-called GIL (global interpreter lock). Matlab is perhaps even
                      > worse in this respect.[/color]

                      Multithreading and parallel execution work fine. The only problem is that
                      you don't get the full benefit when you have multiple processors. This one
                      will become more of an annoyance in the future though as more systems have
                      hyperthreading and multi-core processors.
                      [color=blue]
                      >
                      > And there is a couple of questions I need answered:
                      >
                      > 1. Can python do "pass by reference"? Are datastructures represented by
                      > references as in Java (I don't know yet).
                      >[/color]
                      Python only does "pass by reference", although it is more normally referred
                      to as "pass by object reference" to distinguish it from language where the
                      references refer to variables rather than objects.

                      What it doesn't do is let you rebind a variable in the caller's scope which
                      is what many people expect as a consequence of pass by reference. If you
                      pass an object to a function (and in Python *every* value is an object)
                      then when you mutate the object the changes are visible to everything else
                      using the same object. Of course, some objects aren't mutable so it isn't
                      that easy to tell that they are always passed by reference.

                      Comment

                      • sturlamolden

                        #26
                        Re: Python advocacy in scientific computation

                        Dennis Lee Bieber wrote:
                        [color=blue][color=green]
                        > > 1. Can python do "pass by reference"? Are datastructures represented by
                        > > references as in Java (I don't know yet).
                        > >[/color]
                        > Everything in Python is a reference to an object. I think the
                        > question you want is more on the lines of: Can I change an object that
                        > has been passed? Short answer: depends on what type of object is at the
                        > end of the reference. A mutable container object (list, dictionary,
                        > maybe a class instance) can have its contents changed.[/color]

                        Thank you.

                        Comment

                        • Evan Monroig

                          #27
                          Re: Python advocacy in scientific computation

                          > First there are a few things I don't like:

                          Hi, I will respond to things that others haven't responded yet
                          [color=blue]
                          > 2. How good is matplotlib/pylab? I tried to install it but only get
                          > error messages so I haven't tested it. But plotting capabilities is
                          > really major issue.[/color]

                          I don't know because I haven't managed to get it working either. But
                          other people have and I guess it should not be so difficult.

                          I personally use gnuplot-py (gnuplot-py.sourceforge. net) which I adapted
                          to the new NumPy/SciPy (see below) by searching-and-replacing "Numeric"
                          by "numpy". It allows to use raw gnuplot commands.
                          [color=blue]
                          > 4. Are there "easy to use" libraries containing other stuff important
                          > for scientific programs, e.q. linear algebra (LU, SVD, Cholesky),
                          > Fourier transforms, etc. E.g. in Matlab I can just type,
                          >
                          > [u,s,v] = svd(x) % which calls LAPACK linked to ATLAS or
                          > vendor-optimized BLAS[/color]

                          Yes !

                          There is the excellent SciPy package, which you can get at www.scipy.org

                          Personnally I use it a lot for linear algebra (linked to
                          LAPACK/ATLAS/BLAS), but there are also libraries for statistics,
                          optimization, signal processing, etc.

                          There has been many changes recently, including package names, so don't
                          get confused and be sure to get recent versions of NumPy and SciPy ;).

                          Evan

                          Comment

                          • Alex Martelli

                            #28
                            Re: Python advocacy in scientific computation

                            Robert Kern <robert.kern@gm ail.com> wrote:
                            ...[color=blue][color=green]
                            > > just a toy. And as Matlab's run-time does reference counting insted of
                            > > proper garbage collection, any datastructure more complex than arrays
                            > > are sure to leak memory (I believe Python also suffered from this as
                            > > some point).[/color]
                            >
                            > Python still uses reference counting and has several very good data structures
                            > more complex than arrays. And yet, most programs don't leak memory.[/color]

                            Python uses reference counting *AND* cyclic-garbage collection for the
                            kind of garbage that wouldn't go away by RC due to reference-cycles
                            (plus, also, weak references for yet another helper). To leak memory
                            despite all of that, you really need to do it on purpose (e.g. via a
                            C-coded container extension-type that does NOT play nice with gc;-).


                            Alex

                            Comment

                            • Steve Holden

                              #29
                              Re: Python advocacy in scientific computation

                              sturlamolden wrote:[color=blue]
                              > Robert Kern wrote:
                              >
                              >[color=green]
                              >>And you need to ask why Python is a better Matlab than Matlab?[/color]
                              >
                              >
                              >
                              > First there are a few things I don't like:
                              >
                              > 1. Intendation as a part of the syntax, really annoying.
                              >[/color]
                              Troll. You think this is going away because *you* don't like it? Am I to
                              presume that you don't bother to indent your C code according to its
                              nested block structure? If you *do* indent your C code, perhaps you can
                              explain the additional benefits of the braces?
                              [color=blue]
                              > 2. The "self.something " syntax is really tedious (look to ruby)!
                              >[/color]
                              This is done because of a preference from explicit references over
                              implied ones. It does avoid a lot of namespace confusion.

                              By the way, anyone who can't count shouldn't be criticising programming
                              languages. What happened to "3"?
                              [color=blue]
                              > 4. Multithreading and parallel execution is impossible AFAIK because of
                              > the so-called GIL (global interpreter lock). Matlab is perhaps even
                              > worse in this respect.
                              >[/color]
                              Right. So kindly tell us how to write thread-safe code without using a
                              GIL. This is not an easy problem, and you shouldn't assume that all you
                              have to do to get rid of the GIL is to wave your magic wand. There are
                              deep reasons why the GIL is there.
                              [color=blue]
                              > 5. I don't like numpy's array slicing. Array operations should be a
                              > part of the language, as in Matlab, Fortran 90, Ada 95, D, Octave.
                              >[/color]
                              Slicing *is* a part of the language, inserted into the grammar (as far
                              as I know) precisely to support the numeric/scientific community.[color=blue]
                              >
                              > And there is a couple of questions I need answered:
                              >
                              > 1. Can python do "pass by reference"? Are datastructures represented by
                              > references as in Java (I don't know yet).
                              >[/color]
                              All assignments store references.
                              [color=blue]
                              > 2. How good is matplotlib/pylab? I tried to install it but only get
                              > error messages so I haven't tested it. But plotting capabilities is
                              > really major issue.
                              >[/color]
                              Good enough to keep you away, apparently ;-) (Sorry, I don't use these
                              features).
                              [color=blue]
                              > 3. Speed. I haven't seen any performance benchmarks that actually deals
                              > with things that are important for scientific programs.
                              >[/color]
                              The major fact here is that no matter how fast a language is there is
                              always a need for more speed in certain areas.

                              Suffice it to say that Python is being used for a wide range of
                              scientific and engineering problems to the evident satisfaction of its
                              users.
                              [color=blue]
                              > 4. Are there "easy to use" libraries containing other stuff important
                              > for scientific programs, e.q. linear algebra (LU, SVD, Cholesky),
                              > Fourier transforms, etc. E.g. in Matlab I can just type,
                              >
                              > [u,s,v] = svd(x) % which calls LAPACK linked to ATLAS or
                              > vendor-optimized BLAS
                              >
                              > Even though the language itself is very limited this type of library
                              > functionality more than makes up for it.
                              >[/color]
                              The more people who join in and write libraries to add to the growing
                              corpus of scientific and engineering libraries the sooner the answer to
                              this question will be "we have everything you want".

                              For the moment, however, since apparently Google isn't available where
                              you are, a quick search for "Python LAPACK" gave



                              as its first hit. This appears to include information about how to have
                              LAPACK make use of ATLAS' faster LAPACK routines. Satisfied?
                              [color=blue]
                              >
                              > I have looked for alternatives to Matlab for quite a while, mainly due
                              > to the cost, the åpoor speed and poor memory management. I am not sure
                              > it is Python but so far I have not found anything mor promising either.
                              >[/color]

                              You know, recently the Python community has acquired a reputation in
                              certain quarters for defensive support of the status quo. With
                              ill-informed criticism like this from self-confessed beginners it's not
                              hard to see how this myth has arisen.

                              I'd be very surprised if Python doesn't already give you 95% of what you
                              appear to want. If you prejudices about indented code and self-relative
                              references blind you to the clear advantages of the Python environment
                              then frankly you are a lost cause, and good riddance.

                              If, on the other hand, you are prepared to engage the community and do a
                              little bit of learning rather than just trolling, you may find that one
                              of the most valuable features of Python is its supportive user base,
                              whom at the moment you seem to be doing your best to offend.

                              regards
                              Steve
                              --
                              Steve Holden +44 150 684 7255 +1 800 494 3119
                              Holden Web LLC/Ltd www.holdenweb.com
                              Love me, love my blog holdenweb.blogs pot.com

                              Comment

                              • Michael Tobis

                                #30
                                Re: Python advocacy in scientific computation

                                1) indentation:

                                I claim that this is a trivial matter. Indentation is enforced, but if
                                you want to end all your blocks with #end, feel free.

                                Or write a preprocessor to go from your preferred block style to
                                python's

                                2) self.something tedious to look at.

                                Again, you can somewhat work around this if you like. Just use "s" or
                                "_" instead of "self".

                                3) missing

                                4) multithreading and parallel execution impossible

                                This is simply false, though admittedly the MPI libraries need a little
                                work. Mike Steder of our group is likely to release an alternative. A
                                good way to think of Python is as a powerful extension to C. So using
                                MPI from Python just amounts to setting up a communicator in C and
                                wrapping the MPI calls.

                                As for less tightly coupled threads on a single processor, Python is
                                adept at it. I think the issues with multiple processors are much more
                                those of a server farm than those of a computational cluster.

                                We have been encountering no fundamental difficulty in cluster programs
                                using Python.

                                5) "I don't like numpy's array slicing" ?

                                this is unclear. It is somewhat different form Matlab's, but much more
                                powerful.

                                1) pass by reference

                                Python names are all references. The model is a little peculiar to
                                Fortran and C people, but rather similar to the Java model.

                                2) matplotlib

                                A correct install can be difficult, but once it works it rocks. ipython
                                (a.k.a. pylab) is also a very nice work environment.

                                3D plots remain unavailable at present.

                                3) speed

                                Speed matters less in Python than in other languages because Python
                                plays so well with others. For many applications, NumPy is fine.
                                Otherwise write your own C or C++ or F77; building the Python bindings
                                is trivial. (F9* is problematic, though in fact we do some calling of
                                F90 from Python using the Babel toolkit)

                                4) useful libraries

                                yes. for your svd example see Hinsen's Scientific package. In general,
                                Python's claim of "batteries included" applies to scientific code.

                                mt

                                Comment

                                Working...