Using Python for programming algorithms

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Mon May 19 16:35:55 EDT 2008


On 19 mai, 18:11, Henrique Dante de Almeida <hda... at gmail.com> wrote:
> On May 19, 7:03 am, Bruno Desthuilliers <bruno.
>
>
>
> 42.desthuilli... at websiteburo.invalid> wrote:
> > Vicent Giner a écrit :
>
> > > Hello.
>
> > > I am new to Python. It seems a very interesting language to me. Its
> > > simplicity is very attractive.
>
> > > However, it is usually said that Python is not a compiled but
> > > interpreted programming language
>
> > cf my answer to you and Henrique on this.
>
> > > I am working on my PhD Thesis, which is about Operations Research,
> > > heuristic algorithms, etc., and I am considering the possibility of
> > > programming all my algorithms in Python.
>
> > > The usual alternative is C,  but I like Python more.
>
> > Then use it.
>
> > > The main drawbacks I see to using Python are these:
>
> > > * As far as I understand, the fact that Python is not a compiled
> > > language makes it slower than C, when performing huge amounts of
> > > computations within an algorithm or program.
>
> > In which way is this a problem here ? I thought your thesis was about
> > algorithm, not about implementation optimisation ? And if it's the
> > later, then even C might sometimes be too high level - you should drop
> > to assembly language.
>
> > > * I don't know how likely it is to find libraries in Python related to
> > > my research field.
>
> > I can't tell but you'd be surprised by the quantity of available Python
> > libs.
>
> > > * I know Python is a "serious" and mature programming language, of
> > > course. But I do not know if it is seen as "just funny" in a research
> > > context. Is Python considered as a good programming language for
> > > implementing Operations Research algorithms, such as heuristics and
> > > other soft-computing algorithms?
>
> > Don't know if this answers your question, but it seems that at least
> > some authors consider it a good choice:http://www.oreilly.com/catalog/9780596529321/
>
> > All code examples in this books are in Python - very badly written
> > Python, alas...
>
> > > Maybe this is not the right forum, but maybe you can give me some
> > > hints or tips...
>
> > Hem... Obviously, most people here will have a little biased, you know ?-)
>
>  I agree with what most people here said, that the language doesn't
> really matter, etc., but that simply does not apply to the specific
> case of optimization research.
>
>  The little I know about optimization, even trivial problems may be
> hairy problems. Naïve implementations simply don't finish and the
> performance bottlenecks are not necessarily in the numeric computation
> algorithms (so numpy doesn't help much here). If the guy is doing
> research on that, it possible that he will work with thousands (or
> millions) of weird constraints.
>
>  I'm pretty sure about that: when the algorithms take 4 hours to test
> a single execution, you value processor time.

I'm no expert here, but this sounds like a sensible argument to me.

OTHO, if the OP ends up spending more time writing boilerplate code
and fighting with gory implementation details than working on the
algorithm themselves, he might find than relative difference between
two possible algorithms (like one takes 4 hours and the second take 2
1/2 hours, but each took less than one hour to implement) is much more
important than having the first one taking 4 minutes, the second 2 1/2
minutes, and each having take 15 days to write and debug...

>  The situation would be simpler if there were good well-known toolkits
> for optimization in python (like numpy for matrix operations), but
> that's not the case.

There's at least Psyco (if you're willing and able to restrict
yourself from using some of the most dynamic parts of Python - which
might not be a problem here).  One could also mention stuff like Pyrex
and Cython.



More information about the Python-list mailing list