Ask Your Question
2

Error checking while running faults in a loop

asked 2013-08-01 15:24:04 -0500

drsieb01 gravatar image

updated 2013-08-08 20:48:56 -0500

JervisW gravatar image

I have a script that uses a for loop to iterate through a list of faults on a case. I was wondering if there was a way to check if pss/e is getting hung up on the fault it is running and move on to the next iteration of the loop?

(edit to include code from @drsieb01 's comment)

Example:

for fault in os.listdir('faultfile'):
    psspy.runrspnsfile(...file path..)
edit retag flag offensive close merge delete

Comments

Sorry, I forgot to say that I am running dynamics. By "hung up" I mean that some error in the fault file has caused pss/e to pause and wait for some input, basically anything that would not return from the psspy.runrspnsfile command.

drsieb01 gravatar imagedrsieb01 ( 2013-08-02 07:55:28 -0500 )edit

Example: for fault in os.listdir('faultfile'): psspy.runrspnsfile(...file path..) I'm just unsure if handling the exception with a try/except would handle this case since it is waiting on a return from another function.

drsieb01 gravatar imagedrsieb01 ( 2013-08-02 07:58:51 -0500 )edit

So the problem lies in your response file? Those files can be waiting on user input, and 'hang' indefinitely

JervisW gravatar imageJervisW ( 2013-08-08 20:50:47 -0500 )edit

5 answers

Sort by ยป oldest newest most voted
2

answered 2013-08-09 17:12:53 -0500

cajief gravatar image

In the past I've gone the path Jervis has recommended. In my case, the issue was that PSSE would crash during the fault list or have a criteria violation.

Python was in control using the subprocess command to launch PSSE with an IDEV argument. It was kind of a hack-job but basically it would periodically check if the PSSE process was still running and also scan the log file for violation notifications. If violations were detected, then it would kill the process, make some modifications, and re-run it.

I guess the important question is - what is causing your simulations to hang? What is the best way to detect this condition?

Here's some code below that can be improved upon. The idev it's launching is "run_stab_wvoltage". I remember the first argument to Popen being somewhat sensitive to special characters.

import subprocess
try: #to open pss/e with the newly created idv.
        pssdsInstance = subprocess.Popen(
         ["C:\\progra~1\\pti\\psse30\\pssbin\\PSSDS430.exe",  '-buses','80000','-inpdev', 'run_stab_wvoltage.idv'],
         cwd= activation_path + "\\" + case + "\\", #path where launching PSSE from
         shell=False,
         creationflags=512|16 #CREATE_NEW_PROCESS_GROUP|CREATE_NEW_TERMINAL
        )
        logging.info( "PSSE Successfully Launched! Running %s\%s\%s at %d MW" % (case, condition, faultName, faultMW))
except:
        logging.warning( "ERROR WITH POPEN and PSS/E")

I then used the following commands to see/modify what the process was up to, although you could certainly do something fancier.

pssdsInstance.poll()       #Still running?
pssdsInstance.terminate()  #Kill the process

Good luck!

edit flag offensive delete link more

Comments

The only thing I'd add is that the `subprocess32` module has the option for a timeout parameter which would catch a class of error where the program hasn't exited (i.e. Still running) but is waiting for user input (Hung).

jtrain gravatar imagejtrain ( 2013-08-11 21:30:23 -0500 )edit

Right on - I wasn't aware of the subprocess32 module when I did this. Sounds like it'll be useful for further iterations! Thanks

cajief gravatar imagecajief ( 2013-08-12 09:53:31 -0500 )edit
2

answered 2013-08-11 17:11:06 -0500

EBC gravatar image

PSS/E has a feature PDEV and ODEV commands where you can output to a text file which basically logs everything that is happening in the dynamic runs/simulations. This is a good practice in North America where they review this log file before even looking at the outputs or plots.

edit flag offensive delete link more

Comments

I love this idea, what is an example of something suspicious you'd see in the logs? < I'll ask a dedicated question.

jtrain gravatar imagejtrain ( 2013-08-11 21:22:31 -0500 )edit
1

answered 2013-08-08 21:29:03 -0500

JervisW gravatar image

Based on your edit,

The response files can be waiting on user input, like you suggest, and unless it gets some input will wait forever.

It sounds like you'd prefer to skip the result if it takes too long. Perhaps you could consider running the response in a subprocess and interrupting when an error occurs?

http://stackoverflow.com/questions/11...

This question here considers how to interrupt a command that is taking too long. It looks like there is a great library called subprocess32http://pypi.python.org/pypi/subproces...

which has a timeout parameter included. Then you'd need to write your PSS/E command the same way you'd call it from the commandline:

from subprocess32 import STDOUT, check_output
seconds = 5
env = {"PATH": "c:\Program Files\PTI\PSSE32\PSSBIN"}
output = check_output("psse32 -rspfile %s -nogui" % rspnsfilename, 
                      timeout=seconds, shell=True, stderr=STDOUT, env=env)
edit flag offensive delete link more
0

answered 2013-08-01 18:07:43 -0500

EBahr gravatar image

Are you talking about dynamics or powerflow?

edit flag offensive delete link more
0

answered 2013-08-01 16:28:11 -0500

nyga0082 gravatar image

I'd comment if I could, but I think it'd be helpful if you could post your script and elaborate on what you mean by getting "hung up" on a fault.

edit flag offensive delete link more

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

Stats

Asked: 2013-08-01 15:24:04 -0500

Seen: 1,782 times

Last updated: Aug 11 '13