I have a python program running under Jython (to use a third party Java API), inside which I would like to calculate a constrained minimization of a multivariate function.

Scipy has a module for this that works perfectly (scipy.optimize) but unfortunately you cannot use scipy within Jython. Does anyone know of a good library/any other way to do this in Jython? If I could just run this under Jython, I'd be all set:

1 Answer
1

This may not be the most optimal solution to your particular use case as you already have your application in Jython but JPype (link) allows a CPython program to talk to a program running on JVM, I haven't tried it my self but found a hello world example here.

Basically you make your Java class, compile it into a jar and then in CPython do

I realise though that inverts your application logic. The other option would be to use subprocess and serialise the inputs/outputs.

UPDATE

I came across a similar problem recently and decided to give JPype a go and can now say that it's well worth using, although there are some issues installing it at least on OSX, see help here (some of the JVM paths need to be altered in setup.py).