Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:38+00:00 2026-06-18T07:21:38+00:00

I have a python program running under Jython (to use a third party Java

  • 0

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:

def func(x, sign=1.0):
    """ Objective function -- minimize this """
    return sign*(2*x[0]*x[1] + 2*x[0] - x[0]**2 - 2*x[1]**2)

def func_deriv(x, sign=1.0):
    """ Derivative of objective function """
    dfdx0 = sign*(-2*x[0] + 2*x[1] + 2)
    dfdx1 = sign*(2*x[0] - 4*x[1])
    return np.array([ dfdx0, dfdx1 ])

cons = ({'type': 'eq',
         'fun' : lambda x: np.array([x[0]**3 - x[1]]),
         'jac' : lambda x: np.array([3.0*(x[0]**2.0), -1.0])}, #partial derivative of fun
        {'type': 'ineq',
         'fun' : lambda x: np.array([x[1] - 1]),
         'jac' : lambda x: np.array([0.0, 1.0])})   #partial derivative of fun

res = minimize(func, [-1.0,1.0], args=(-1.0,), jac=func_deriv, 
               method='SLSQP', constraints=cons, options={'disp': True})

Thanks! -Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:21:39+00:00Added an answer on June 18, 2026 at 7:21 am

    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

    import jpype
    import os.path
    
    jarpath = os.path.join(os.path.abspath('.'), 'build/jar')
    jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
    
    # get the class
    hello_world = jpype.JClass('com.stackoverflow.HelloWorld')
    t = hello_world()  # create an instance of the class
    t.helloWorld("Say hello")  # try to call one of the class methods
    jpype.shutdownJVM()
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running my Python program and have a point where it would be useful
I have quite a 'heavy' python program that I would like compiled to an
I have a python script that ends with running a program (iexpress.exe) in a
I have a python program that I am currently working on which is working
I have a python program which calls a C function. I send some structures
Let's imagine i have a program in Python like this one ( first.py ):
I have a python program that does something like this: Read a row from
I have a Python program running a thread that consistently outputs the following: (my_program.py:12313):
I have a Python program for Linux almost looks like this one : import
I have a python program running using a parallel python. This module scales my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.