[SciPy-dev] Python interface to COBYLA

Jean-Sebastien Roy js at jeannot.org
Tue Apr 13 15:04:28 CDT 2004

Pearu Peterson wrote:
> I have one suggestion: use F2PY to generate Python interfaces to Fortran 
> programs. There are several advantages for doing so. For example, the 
> interface is more efficient and less errorprone and easier to maintain 
> than handwritten wrappers. Let me know if you have any troubles using 
> F2PY.

You're absolutely right. I should have used F2PY.

In fact, I tried F2PY first but encountered a few problems. The most 
basic one was that F2PY didn't work right on my machine (A FreeBSD 4.9 
box. The F2PY port didn't recognize any F77 compiler. It's probably 
specific to my machine).

The other problem was that COBYLA expect the function to be minimized to 
be a Fortran function called CALCFC. Therefore, reentrancy was not easy 
to achieve without some modifications to the original code (passing a 
callback at least). So in the end, I ran f2c, modified the code and 
wrote my own wrapper.

A nice side effect is I can now use COBYLA in some of my C programs 
easily. But I agree it's clearly not the best solution for SciPy. I'll 
try harder to use F2PY next time (probably for Powell's NEWUOA).

In the mean time, feel free to replace my wrapper by a F2PY wrapper to 
the original Fortran COBYLA2 code: I would be myself very interessted in 
such wrapper as an example !



More information about the Scipy-dev mailing list