Ask Your Question
0

Python Parallel Dynamics Simulations

asked 2015-04-15 16:44:27 -0500

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.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2015-04-15 20:39:02 -0500

jconto gravatar image

updated 2021-06-29 12:31:58 -0500

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.

edit flag offensive delete link more

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 ( 2015-04-17 05:57:19 -0500 )edit

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 ( 2015-04-17 08:48:18 -0500 )edit
1

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

sheng gravatar imagesheng ( 2015-05-04 21:00:48 -0500 )edit
1

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

Linzhi gravatar imageLinzhi ( 2017-07-06 21:18:54 -0500 )edit

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

jconto gravatar imagejconto ( 2017-07-07 10:29:53 -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: 2015-04-15 16:44:27 -0500

Seen: 52,843 times

Last updated: Jun 29 '21