paulinho
paulinho

Reputation: 1

Connection is already active in Supersuit Vectorized environment with SUMO for Multi Agent Reinforcement Learning

I have created a PettingZoo custom parallel environment to do multi-agent reinforcement learning which uses the traffic simulator SUMO with traci, inspired by the sumo_rl library.

Then, to apply different algorithms on it, I want to use the stable-baselines3 python library.

As shown in this sb3 tutorial, I used Supersuit library to convert my custom env into Vectorized environment with methods ss.pettingzoo_env_to_vec_env_v1() and ss.concat_vec_envs_v1().

However, when I try to train agents, I have this traci error :

Traceback (most recent call last):
  File "\src\test.py", line 47, in <module>
    model.learn(total_timesteps=100)
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\stable_baselines3\ppo\ppo.py", line 315, in learn
    return super().learn(
           ^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\stable_baselines3\common\on_policy_algorithm.py", line 264, in learn
    total_timesteps, callback = self._setup_learn(
                                ^^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\stable_baselines3\common\base_class.py", line 423, in _setup_learn
    self._last_obs = self.env.reset()  # type: ignore[assignment]
                     ^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\stable_baselines3\common\vec_env\vec_monitor.py", line 70, in reset
    obs = self.venv.reset()
          ^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\supersuit\vector\sb3_vector_wrapper.py", line 22, in reset
    observations, self.reset_infos = self.venv.reset()
                                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\supersuit\vector\concat_vec_env.py", line 46, in reset
    _obs, _info = self.vec_envs[i].reset(options=options)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Local\anaconda3\envs\RL\Lib\site-packages\supersuit\vector\markov_vector_wrapper.py", line 57, in reset
    _observations, infos = self.par_env.reset(seed=seed, options=options)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\src\FpfEnv.py", line 196, in reset
    self._start_simulation()
  File "\src\FpfEnv.py", line 90, in _start_simulation
    traci.start(sumo_cmd, label=self.label)
  File "C:\Program Files (x86)\Eclipse\Sumo\tools\traci\main.py", line 139, in start
    raise TraCIException("Connection '%s' is already active." % label)
traci.exceptions.TraCIException: Connection '0' is already active..`

Indeed, when I print the index of the current env which launch the reset() method, it has index 1.

So I understand that the first env create the connection with the self.label parameter and the second one try to do the same but as the self.label does not change, it tries to open a connection already existing.

Inside of my env class, I tried to change the label each time the reset() is called but it did not succeed. Should I conclude that it is the same instance of my custom env which is (idk how) concatenate ?

More generally, my question is : how to deal with that problem ?

Thanks

Upvotes: 0

Views: 73

Answers (0)

Related Questions