Ask Your Question
1

ACCC script for multiple cases - crashes depending on the order of cases. How do I debug?

asked 2013-10-16 01:18:41 -0500

Peter B gravatar image

updated 2013-10-19 20:54:36 -0500

JervisW gravatar image

Hi,

I've written a script to run ACCC studies on multiple cases. The script reads in from a .dat file the names of the relevant .sav, .sub, .mon and .con files and then creates .dfx, .acc and .xlsx files also based on specifications in the .dat file.

Below is a screen shot of the .dat file contents:

image description

The weird issue I'm having is that my script works fine (i.e. produces all three ACCC reports in excel) if the order of cases listed in the data file begins with Test_case_2.sav.

But if Test_case_1.sav or Test_case_3.sav are listed first (as in the screenshot example), the script will create only one ACCC report and then just stop running (without throwing up any errors) when it is part way through making the second .acc file.

My question is, what debugging techniques can I use to try and find out why this is happening?

My code is below, I'm already using psspy.throwPsseExceptions = True, I've had a go at using logging but you can probably tell from the code I don't know what I'm doing with it.

Thanks,

Peter

import math, sys, csv,os, logging

# Location of libraries
sys.path.append("C:\Program Files (x86)\PTI\PSSE32\PSSBIN")   # psspy

PSSE_LOCATION = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['path'] + ';' + PSSE_LOCATION

import psspy, pssexcel, excelpy
import redirect      #redirects popups
redirect.psse2py()
psspy.psseinit()     #initialise PSSE so psspy commands can be called
psspy.throwPsseExceptions = True

def clearall():
    all = [var for var in globals() if (var[:2], var[-2:]) != ("__", "__")]
    for var in all:
        del globals()[var]

class IOFile:

    #To retrieve data from input.csv input file
    def Input_File(self):
        try:
            fileinput_tmp = open('input_ACCC_123.dat','rb')
            fileinput = csv.reader(fileinput_tmp)

        except IOError:
            psspy.lines_per_page_one_device(2,10000000)
            psspy.progress_output(1,"",[0,0])
            print ' **************** Input File Not Found **************** '
        else:
            pass

        #To store sav,sub,mon,con,dfx,accc,excel
        sav=[]
        sub=[]
        mon=[]
        con=[]
        dfx=[]
        accc=[]
        excel=[]


        for numcase, row in enumerate(fileinput):
            if row[0]=='0':
                break
            sav.append(row[0]) 
            sub.append(row[1])
            mon.append(row[2])
            con.append(row[3])
            dfx.append(row[4])
            accc.append(row[5])
            excel.append(row[6])


        #To close input file
        fileinput_tmp.close()

        return sav,sub,mon,con,dfx,accc,excel,numcase

class Run:

    #To perform ACCC in all cases 
    def multi_ACCC(self,sav,sub,mon,con,dfx,accc,excel,numcase):
        #newcase=[]

        for i in range(0,numcase,1):
            psspy.base_frequency( 50.0)
            psspy.case(sav[i])
            print'sav file opened'

            """Run ACCC"""
            psspy.dfax([1,1], sub[i], mon[i], con[i], dfx[i])
            print'dfx file created'
            psspy.accc( 0.5,[1,1,0,1,1,1,0],dfx[i],accc[i],"")
            print'acc file created'

            # 's' or 'summary' ACCC Analysis Summary
            # 'e' or 'events' Contingency Events Description
            # 'b' or 'branch' Monitored Branch Flow (MVA)
            # 'i' or 'interface' Monitored Interface Flow (MW)
            # 'v' or 'voltage' Monitored Bus Voltage
            # 'l' or ...
(more)
edit retag flag offensive close merge delete

Comments

For some reason when I write underscoreX, what comes out is an italicised X. That's why the case names in the question look a bit different to what's in the .dat file. I don't know how to fix that.

Peter B gravatar imagePeter B ( 2013-10-16 01:22:34 -0500 )edit

just want to know whether you run the code from PSS/E GUI. I noticed that some strange things could happen if I run some python code from Python IDLE, although all the modules were properly imported.

yfwing gravatar imageyfwing ( 2013-10-18 10:50:15 -0500 )edit

I just ran it from inside PSS/E and it did work, strange. As a matter of principle I'll still try and do some debugging as suggested by @JervisW, so that hopefully I can get it working properly from outside PSS/E. Thanks for the reminder to try the simple solution first @yfwing!

Peter B gravatar imagePeter B ( 2013-10-20 22:07:44 -0500 )edit

Peter B, regarding to the strange behavior of PSS/E, I talked to technical support of PSS/E sometime ago. The problem comes from the different version of compilers when python module and PSS/E main engine were built. There are some inconsistent internally. It is hard for the user to debug.

yfwing gravatar imageyfwing ( 2013-10-21 19:34:43 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-19 21:04:33 -0500

JervisW gravatar image

The psspy module isn't written in pure Python. It calls on the core PSSE code which was written in another language.

This means, there is a point in your program where Python isn't running at all, it's executing PSSE code (as in the accc function). If there is an error deep inside accc and PSSE doesn't correctly handle it, and return it to Python, then it can crash your program without reporting anything at all.

One technique I use is pdb to step through line by line and check on the variables. In your code, I'd put these lines just above your accc function call

import pdb
pdb.set_trace()

Then you will be given an interactive Python prompt that looks like this (pdb) where you can type any python code you like and step through the program line by line using the n command for "next" and c for continue until next breakpoint

edit flag offensive delete link more

Comments

I tried this technique, when it got to the second iteration of executing the accc function call the Python Shell just gave me a ">>> ======= RESTART ======" message, as it had when I ran the script through in full without using pdb. So I'm none the wiser but I'll probably just run the script from inside PSS/E just to get it working smoothly.

Peter B gravatar imagePeter B ( 2013-10-20 22:23:54 -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

Stats

Asked: 2013-10-16 01:18:41 -0500

Seen: 2,813 times

Last updated: Oct 19 '13