0

Open several psspy-instances from Python

Is it possible to have open several sav-files in Python, and do operations on them in parallel. For instance, I may want to run load flow analysis on two different load scenarios, or different topologies for the same power system and compare them. I would like to do something like:

psspy1.fnsl()
psspy2.fnsl()

And compare the branch flows etc. Is this possible? Any help is greatly appreciated!

Transmission Impossible's avatar
71
Transmission Impossible
asked 2015-02-19 05:50:15 -0500, updated 2015-02-24 04:49:24 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Thank you both jconto and sheng! I think I understand how it works now, and how I can solve the issues I'm having.

Transmission Impossible's avatar Transmission Impossible (2015-02-23 05:52:45 -0500) edit
add a comment see more comments

3 Answers

1

I'm not sure what you have proposed will work.

Try using the Python Multiprocessing module--I have used it to run multiple instances of PSSE to perform tasks currently.

However if you are only solving couple of load flows, it is probably not worth the trouble.

sheng's avatar
141
sheng
answered 2015-02-19 06:26:52 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks for the answer. I'm new to Python, so I don't really understand how the information is stored. I assume it's inside some object in the module psspy, but I'm not really sure. Is psspy a module that can only handle one object at a time? If the terminology I'm using is wrong, please correct it=)

Transmission Impossible's avatar Transmission Impossible (2015-02-20 03:37:59 -0500) edit
add a comment see more comments
1

You cannot access the memory data in one PSSe GUI instance from a second PSSe GUI instance. Complementing Sheng's answer:

step1: run your LF activities (in parallel, distributed in several pcs or serially). Save the cases.

step2: run a python script to work on comparing (PSSe has an activity to compare two cases) the cases - you can process the cases within a loop to extract the information to be compared and write it to a csv file.

step3: The output csvfile can be loaded to excel for quick comparison of the variables of interest (or post-processed with a third python code)

jconto's avatar
2.9k
jconto
answered 2015-02-22 10:40:41 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

A posible workaround could be using the multiprocessing module in this way:

import multiprocessing

class psspy_worker(multiprocessing.Process):

    def __init__(self, pipe_conn):
        multiprocessing.Process.__init__(self)
        self.pipe = pipe_conn

    def run(self):
        import psse34
        import psspy

        while True:
            msg = self.pipe.recv()
            command = msg.get("command")

            if command == "kill":
                break

            if command == "call":
                func_name = msg.get("func_name")
                args = msg.get("args", [])
                kwargs = msg.get("kwargs", {})
                func = getattr(psspy, func_name)
                result = func(*args, **kwargs)
                self.pipe.send({"status": "success", "result": result})


class isolated_psspy(object):

    def __init__(self):
        self.parent_conn, self.child_conn = multiprocessing.Pipe()
        self.worker = psspy_worker(self.child_conn)
        self.worker.start()


    def __getattr__(self, name):
        if name.startswith("__"):
            raise AttributeError(name)

        def wrapper(*args, **kwargs):
            self.parent_conn.send({
                "command": "call",
                "func_name": name,
                "args": args,
                "kwargs": kwargs,
                })
            response = self.parent_conn.recv()
            return response["result"]

        return wrapper


    def close(self):
        self.parent_conn.send({"command": "kill"})
        self.worker.join()


if __name__ == "__main__":

    psspy1 = isolated_psspy()
    psspy2 = isolated_psspy()

    psspy1.psseinit()
    psspy2.psseinit()

    psspy1.case("case1.sav")
    psspy2.case("case2.sav")

    line11, _ = psspy1.titldt()
    line12, _ = psspy2.titldt()

    assert line11 != line12
jbarberia's avatar
38
jbarberia
answered 2026-07-03 13:49:21 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer