Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Does Scipy conflict with PSS/E ?

Hi all,

Thank you for coming to watch the question. I am trying to optimize the output from PSS/E then send the results back to PSS/E for further operations.

I found PSS/E doesn't with Scipy package (a very popular optimization package in python), does anyone encounter the same problem before?

The code below is a concise example that shows the problem, in my IDE (Spyder), as long as you initialize PSS/E, the program is going to be stuck and die.

You are welcome to try the code:

import os, sys
# Set environment for psse33.04
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN'
sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH
import psspy
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
import redirect
redirect.psse2py()
psspy.psseinit(buses=50)  # the optimization code doexn't work as long as you keep this line!!!

from scipy.optimize import minimize
import numpy as np

fun = lambda x : (x[0] - 0.667) / (x[0] + x[1] + x[2] - 2) # obj: min (x−2/3)/(x+y+z−2)
cons = ({'type': 'eq', 'fun': lambda x: x[0] * x[1] * x[2] - 1}, # xyz=1
        {'type': 'ineq', 'fun': lambda x: x[0] }, #x>0
        {'type': 'ineq', 'fun': lambda x: x[1] },#y>0
        {'type': 'ineq', 'fun': lambda x: x[2] }#z>0
       )
x0 = np.array((1.0, 1.0, 1.0)) # 
res = minimize(fun, x0, method='SLSQP', constraints=cons)
print('min value:',res.fun)
print('solution:',res.x)
print('success or not:', res.success)
print('message:', res.message)

Thanks in advance, any help will be appreciated.

Does Scipy conflict with PSS/E ?

Hi all,

Thank you for coming to watch the question. I am trying to optimize the output from PSS/E then send the results back to PSS/E for further operations.

I found PSS/E doesn't work with Scipy package (a very popular optimization package in python), does anyone encounter the same problem before?

The code below is a concise example that shows the problem, in my IDE (Spyder), as long as you initialize PSS/E, the program is going to be stuck and die.

You are welcome to try the code:

import os, sys
# Set environment for psse33.04
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN'
sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH
import psspy
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
import redirect
redirect.psse2py()
psspy.psseinit(buses=50)  # the optimization code doexn't work as long as you keep this line!!!

from scipy.optimize import minimize
import numpy as np

fun = lambda x : (x[0] - 0.667) / (x[0] + x[1] + x[2] - 2) # obj: min (x−2/3)/(x+y+z−2)
cons = ({'type': 'eq', 'fun': lambda x: x[0] * x[1] * x[2] - 1}, # xyz=1
        {'type': 'ineq', 'fun': lambda x: x[0] }, #x>0
        {'type': 'ineq', 'fun': lambda x: x[1] },#y>0
        {'type': 'ineq', 'fun': lambda x: x[2] }#z>0
       )
x0 = np.array((1.0, 1.0, 1.0)) # 
res = minimize(fun, x0, method='SLSQP', constraints=cons)
print('min value:',res.fun)
print('solution:',res.x)
print('success or not:', res.success)
print('message:', res.message)

Thanks in advance, any help will be appreciated.