[SciPy-dev] Python interface to COBYLA
Pearu Peterson
pearu at scipy.org
Thu Apr 15 01:10:10 EDT 2004
Jean, Travis,
On Tue, 13 Apr 2004, Jean-Sebastien Roy wrote:
> 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).
Please, let us know what are these problems with FreeBSD. I am sure there
is a easy fix.
> 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 !
The example wrapper to Fortran COBYLA2 code is attached (feel free to
suggest changes to the interface).
Below follow basic steps how I created this wrapper, the steps are quite
typical when creating a new scipy module (for more info, see
http://testing.scipy.org/development/developscipy):
1) Modified cobyla2.f: added calcfc as an argument
2) Generated initial .pyf file:
f2py cobyla2.f -m _cobyla -h _cobyla.pyf only: cobyla calcfc
3) Modified _cobyla.pyf so that f2py generates a wrapper
having the following signature:
x = minimize(calcfc,m,x,rhobeg,rhoend,
[iprint,maxfun,calcfc_extra_args])
where call-back function calcfc is expected to have the following
signature:
def calcfc(x,con):
# calculate scalar f=f(x)
# calculate m-vector con(x) in-place
return f
4) Created setup.py file
5) Created tests/test_cobyla.py
6) Build cobyla module:
python setup.py build
7) Run tests:
$ python tests/test_cobyla.py
Found 1 tests for __main__
Result: [-4.80580817 1.44539502] (exact result = -4.898979456, 1)
.
----------------------------------------------------------------------
Ran 1 test in 0.004s
OK
$
8) Created tar-ball that is attached:
python setup.py sdist
Bugs: when setting maxfun value higher than 10, the fortran code seem end
up into an infinite loop. Not sure what is going wrong.
Note that by the end of this week (probably tomorrow) we have Scipy
release 0.3 out and at the moment scipy CVS tree is in a freezed state
because of that. I think we can add cobyla to Scipy 0.3.1 (the bug fix
release) provided that the above bug gets resolved.
Regards,
Pearu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cobyla-0.1.tar.gz
Type: application/x-gzip
Size: 10993 bytes
Desc:
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20040415/5e13195d/attachment.bin>
More information about the SciPy-Dev
mailing list