[SciPy-dev] Python interface to COBYLA

Jean-Sebastien Roy js at jeannot.org
Thu Apr 15 13:52:49 CDT 2004


Pearu Peterson wrote:
> Please, let us know what are these problems with FreeBSD. I am sure there 
> is a easy fix.

I had installed the version in the FreeBSD ports ("2.37.233.1545").
Running: python setup.py build_ext --inplace
Returned:
running build_ext
error: Fortran compiler not available: None

I have now installed the latest version (no port is available for it on 
FreeBSD), an it worked fine besides apparently harmful errors such as:
Could not locate executable 
/usr/home/js/devel/optimisation/cobyla2_f/cobyla-0.1/g77
or:
invalid command 'build_src' (no module named 'distutils.command.build_src')

(on a side note, is it possible to get f2py messages in black instead of 
yellow (the color I'm seeing on my machine) which is very difficult to 
read on white background ?)

> The example wrapper to Fortran COBYLA2 code is attached (feel free to 
> suggest changes to the interface). 

Many thanks ! It's obviously much simpler than writting a custom C wrapper.

About changes to the interface, only a few things may be missing : 
maxfun is also a value to be returned (it's the number of iterations 
effectively done). Also, the reason for exiting COBYLA should be 
returned, as else optimization may fail without warning the caller 
(beside a printed message). This may require modifications to the 
Fortran source.

Is it normal that the Fortran Wrapper does not complain when None is 
returned by the python function instead of a float ?

> Bugs: when setting maxfun value higher than 10, the fortran code seem end 
> up into an infinite loop. Not sure what is going wrong.

FWIW, I cannot reproduce this bug, neither in my nor in your wrapper, 
which seems to run fine on my machine.

Nevertheless, when trying a nested optimization problem, I encountered 
an error I cannot explain. Please find below a simple example:

import cobyla
def f1(x, con):
	global a
	f = (x[0]-a)**2
	return f

def f2(x, con):
	global a
	a = x[0]
	z = cobyla.minimize(f1, m=0, x=[0], iprint = 
1,rhobeg=0.5,rhoend=1e-6,maxfun=100)
	f = z[0]**2+abs(x[1])**3
	return f

print cobyla.minimize(f2, m=0, x=[1,1], iprint = 
1,rhobeg=0.5,rhoend=1e-4,maxfun=1000)

Returns:

    Normal return from subroutine COBYLA

    NFVALS =   23   F = 1.000000E-12    MAXCV = 0.000000E+00
    X = 1.000001E+00
capi_return is NULL
Call-back cb_calcfc_in_cobyla__user__routines failed.
Traceback (most recent call last):
   File "tst5.py", line 18, in ?
     print cobyla.minimize(f2, m=0, x=[1,1], iprint = 
1,rhobeg=0.5,rhoend=1e-4,maxfun=1000)
   File "tst5.py", line 10, in f2
     z = cobyla.minimize(f1, m=0, x=[0], iprint = 
1,rhobeg=0.5,rhoend=1e-6,maxfun=100)
TypeError: minimize argument calcfc must be callable

This doesn't seem to happen with the C wrapper.

Regards,

js




More information about the Scipy-dev mailing list