First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Python Parallel Dynamics Simulations

asked Apr 15 '15

Jacde gravatar image

I am trying to get PSSE to run multiple simulations to compare the results to one another. As there will be many simulations, I want to "parallelize" the simulations. I have given multiprocessing.Process and multiprocessing.pool a shot and can not get it working.

Here is base code I've been trying to get to work. It solves and creates an out file in the folder if I have the pool function only iterate once. If I try to change it to multiple values, I start getting invalid temporary file or visual fortran errors.

Do I have something incorrect in the coding? Is my understanding of the pool function not correct?

import psspy,redirect,multiprocessing as m

def run_fault(x):
    case, snp, out, log = x
    # Redirect output from PSSE to Python
    redirect.psse2py()
    psspy.psseinit(12000)
    # Initialize PSSE
    psspy.report_output(2,out,[])
    psspy.progress_output(2,out,[])
    psspy.alert_output(2,out,[])
    psspy.prompt_output(2,out,[])
    # Load case
    psspy.case(case)
    psspy.rstr(snp)
    psspy.conl(-1,1,1)
    psspy.conl(-1,1,2,[0,0],[100,0,0,100])
    psspy.conl(-1,1,3)
    # Convert generators:
    psspy.cong()
    # Solve for dynamics
    psspy.ordr()
    psspy.fact()
    psspy.tysl()
    # Initialize and run the case
    psspy.strt(0,out)
    psspy.run(0,1,1,1,1)
    psspy.pssehalt_2()

if __name__ == "__main__":
    folder = r"C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\dyn"

    redirect.psse2py()
    psspy.psseinit()
    # Generate processes to run
    size = 2
    arglist = []
    for i in range(size):
        arglist.append((folder+`i+1`+r"\savnw.sav",folder+`i+1`+r"\savnw.snp",
                        folder+`i+1`+r"\savnw.out",folder+`i+1`+r"\savnw.log"))
    pool = m.Pool()
    P = pool.map(func=run_fault, iterable=arglist)
    pool.close()
    pool.join()

Any help would be appreciated.

1 answer

Sort by » oldest newest most voted
1

answered Apr 16 '15

jconto gravatar image

updated Jun 29 '1

I have written a python code, named MPjobs, that allow running as many instances of PSSe as CPU’s in a pc, in other words, runs PSSe in parallel at the process level. It uses pool.apply_async and a dictionary to pass the arguments. This tool is suitable for repetitive studies where the changing variable is known, like during benchmarking models, sensitivity runs or dynamic fault simulations.

You can download the MPjobs code with a demo set compatible with PSSe v33, v34 and v.35 from [copy the link into your browser if it does not work by clicking on it]:

JContogoogledrive, select "MPjobs PSSe in Parallel" and then select “MPjobsjconto_xxxxx.zip”. An icon on the top-center screen will perform the download.

As it is, MPjobs can be used to parallelize runs from ‘almost’ any application that can run from a DOS window with an input file or line arguments.

Follow the instruction in the read.me file and in the wiki doc to run the demos included.

link

Comments

I did something similar but I do experience few race conditions with PSSE32. Do you experience any? Another issue is zombie processes in multiprocessing module--how do you manage it?

sheng gravatar imagesheng (Apr 17 '15)

For PSSe 32, I have install the module 'multiprocessing', a port to allow python 2.5 use multiprocessing calls. The race conditions, two processes accessing the same data, are minimized by introducing a 1 sec delay for each new process call. Zombie processes are a problem. Tracking PID maybe?

jconto gravatar imagejconto (Apr 17 '15)
1

Issue is multiprocessing.Pool hang forever if a worker process dies unexpectedly

sheng gravatar imagesheng (May 5 '15)
1

Your demo code with the link "https://drive.google.com/drive/folders/0B7uS9L2Woq7YzYzcGhXT2VQYXc" is invalid. Has it been deleted?

Linzhi gravatar imageLinzhi (Jul 7 '17)

I updated the link! Same combination of alpha-numerics but in a link format. It works now.!

jconto gravatar imagejconto (Jul 7 '17)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Apr 15 '15

Seen: 52,906 times

Last updated: Jun 29 '21