Ask Your Question
0

Does Scipy conflict with PSS/E ?

asked 2019-11-13 22:09:53 -0500

Gary22212 gravatar image

updated 2019-11-13 22:10:44 -0500

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.

edit retag flag offensive close merge delete

Comments

I have not used PSS/E from within Spyder, but I have never had any issue running PSS/E from within IDLE. If you try running the code from within IDLE, and it runs successfully, then you know that it's an issue with the Spyder IDE.

jfconroy gravatar imagejfconroy ( 2019-11-14 01:35:07 -0500 )edit

Thank you very much, the problem was solved.

Gary22212 gravatar imageGary22212 ( 2019-11-14 17:57:11 -0500 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2019-11-14 04:14:38 -0500

drsgao gravatar image

updated 2019-11-14 04:16:00 -0500

You probably ran into the annoying 32bit/64bit problem.

scipy by default, prefers 64bit (since it is a lot more percise), so as numpy.

But, this is a big but, psspy runs on 32bit (though some other modules provided by PSSE can run on 64bit).

If you google it, you will see a lot of posts regarding issues with scipy with 32bit Python.

In short, this is the answer: https://stackoverflow.com/a/25057693

What you need to do is to go to here https://sourceforge.net/projects/scip... , and download the "superpack" installer and install it.

I could reproduce your problem in command line before installing the superpack.

After installing the superpack, the problem went away:

Screenshot

You can see that PSSE is initialised and then your calcluations performed with the messages printed. By the way, when in doubt, throw away the IDE and just run the code with the Python intepreter.

If you do not want to install the superpack, then you may need to call the 64bit Python to run the optimisation with 64bit Scipy and then return the results. See https://psspy.org/psse-help-forum/que... for this.

If you cannot see the image, it is a cmd screenshot with the following messages (I change the init bus from 50 to 50000). You can see PSSE is initalised and then the optimisation performed:

  PSS(R)E Version 33
 Copyright (c) 1976-2019
 Siemens Industry, Inc.,
 Power Technologies International                            (PTI)
 This program is a confidential  unpublished  work  created  and  first
 licensed in 1976.  It is a trade secret which is the property of  PTI.
 All use,  disclosure,  and/or reproduction not specifically authorized
 by  PTI  is prohibited.   This  program is protected  under  copyright
 laws  of  non-U.S.  countries  and  by  application  of  international
 treaties.  All  Rights  Reserved  Under  The  Copyright  Laws.


           SIEMENS POWER TECHNOLOGIES INTERNATIONAL

      50000 BUS POWER SYSTEM SIMULATOR--PSS(R)E-33.4.0

             INITIATED ON THU, NOV 14 2019  10:08
('min value:', -0.18814357989751096)
('solution:', array([0.29250894, 1.84897232, 1.84897233]))
('success or not:', True)
('message:', 'Optimization terminated successfully.')
edit flag offensive delete link more

Comments

Thank you for your excellent work. Indeed, the problem lies in what seems to be the incompatibility between the Scipy (version 1.2.2) and PSSPY. Both are 32-bit versions. As you have suggested, I installed scipy version 0.16.0, and the problem is then solved.

Gary22212 gravatar imageGary22212 ( 2019-11-14 17:46:59 -0500 )edit

A slight digression, I think psspy/psse really need to be updated to be compatible with 64-bit, 3.7 or higher version Python, given that python 2.7 is very old which will be out of maintenance from Jan 2020. ( ͡° ͜ʖ ͡°)

Gary22212 gravatar imageGary22212 ( 2019-11-14 18:06:23 -0500 )edit

Complete agreed. Especially with all the AI and ML packs all in 64bit. Siemens tried to support PY3.4 in v34 but there are tons of bugs reported. And Siemens' documentation is appalling.

drsgao gravatar imagedrsgao ( 2019-11-15 03:08:49 -0500 )edit

Exactly!!!

Gary22212 gravatar imageGary22212 ( 2019-11-15 09:33:59 -0500 )edit
0

answered 2019-11-14 10:14:58 -0500

jconto gravatar image

It did run OK on PSSe v.33.12.1 with Python 2.7.13 and Scipy 0.16.1 (32 bit):

       1000 BUS POWER SYSTEM SIMULATOR--PSS(R)E-33.12.1

             INITIATED ON THU, NOV 14 2019   9:45
('min value:', -0.18814357989751096)
('solution:', array([0.29250894, 1.84897232, 1.84897233]))
('success or not:', True)
('message:', 'Optimization terminated successfully.')

If you got Spyder (and Scipy) with Anaconda 64-bit, uninstall and install the 32-bit version.

edit flag offensive delete link more

Comments

You don't need to uninstall it. Just use a 32bit virtual environment.

drsgao gravatar imagedrsgao ( 2019-11-14 10:57:12 -0500 )edit

Thank you JConto and drsgao, The problem lies in the incompatibility between the new version of Scipy (version 1.2.2) and PSSPY. Actually, both are 32-bit versions in my PC. I degraded the Scipy to V 0.16.0, the same version as you used, then it worked.

Gary22212 gravatar imageGary22212 ( 2019-11-14 18:03:14 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2019-11-13 22:09:53 -0500

Seen: 53 times

Last updated: Nov 14