Closed Hello-World-Py closed 4 years ago
Hello,
This is not a bug on lightsim side, so I marked it as enhancement.
Lightsim is not compatible with multi processing / multi threading yet because for this support it needs to be compatible with pickle (and today it is not)
That being say, i am not sure the error you point out is related to this feature.
Hello, after a look to your code, it appears to not be related to pickle or anything, but rather to the use of grid2op you are trying to do.
You need to build one backend per environment, otherwise yes, there will be some issue for sure.
So this is a correct working code:
import threading
import grid2op
from lightsim2grid import LightSimBackend
class A3CAgent:
def __init__(self, env_name="l2rpn_neurips_2020_track1_small"):
self.threads = 3
self.env_name = env_name
self.env = grid2op.make(self.env_name)
def test_multi(self):
agents = [Agent(i, env_name=self.env_name) for i in range(self.threads)]
for agent in agents:
agent.start()
class Agent(threading.Thread):
def __init__(self, index, env_name):
threading.Thread.__init__(self)
self.index = index
self.env_name = env_name
def run(self):
print("Running Thread ", self.index)
backend = LightSimBackend()
env = grid2op.make(self.env_name, backend=backend, difficulty=0) # does not raise error
env.reset()
if __name__ == '__main__':
env_name = "l2rpn_neurips_2020_track1_small"
global_agent = A3CAgent(env_name)
global_agent.test_multi()
Thanks!
Environment
1.2.3
ubuntu18.04
0.2.3
Bug description
I am unable to run grid2op in a multi-threaded manner using the light2sim backend. The following code replicates the error I am seeing. The code works without any error using
self.threads=1
or with thepandapower
backendCurrent output
There are different errors depending on the number of threads. One error raised is the following:
Expected output
There should be no error in the code.