Skip to content

ConnectionResetError: [Errno 104] Connection reset by peer #648

@cncPomper

Description

@cncPomper

In colab:

!pip install highway-env
!pip install stable-baselines3
import gymnasium as gym
from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.vec_env import SubprocVecEnv
from metadrive.envs.metadrive_env import MetaDriveEnv
from metadrive.envs.gym_wrapper import createGymWrapper
import highway_env  # noqa: F401

# ==================================
#        Main script
# ==================================

n_cpu = 6
batch_size = 64
env = make_vec_env("highway-fast-v0", n_envs=n_cpu, vec_env_cls=SubprocVecEnv)
model = PPO(
    "MlpPolicy",
    env,
    policy_kwargs=dict(net_arch=[dict(pi=[256, 256], vf=[256, 256])]),
    n_steps=batch_size * 12 // n_cpu,
    batch_size=batch_size,
    n_epochs=10,
    learning_rate=5e-4,
    gamma=0.8,
    verbose=2,
    tensorboard_log="highway_ppo/",
)
# Train the agent
model.learn(total_timesteps=int(2e4))
# Save the agent
model.save("highway_ppo/model")

model = PPO.load("highway_ppo/model")
env = gym.make("highway-fast-v0")
for _ in range(5):
    obs, info = env.reset()
    done = truncated = False
    while not (done or truncated):
        action, _ = model.predict(obs)
        obs, reward, done, truncated, info = env.step(action)
        env.render()
---------------------------------------------------------------------------
ConnectionResetError                      Traceback (most recent call last)
[<ipython-input-15-736b91dfab08>](https://localhost:8080/#) in <cell line: 0>()
     30 n_cpu = 6
     31 batch_size = 64
---> 32 env = make_vec_env("highway-fast-v0", n_envs=n_cpu, vec_env_cls=SubprocVecEnv)
     33 model = PPO(
     34     "MlpPolicy",

4 frames
[/usr/lib/python3.11/multiprocessing/connection.py](https://localhost:8080/#) in _recv(self, size, read)
    393         remaining = size
    394         while remaining > 0:
--> 395             chunk = read(handle, remaining)
    396             n = len(chunk)
    397             if n == 0:

ConnectionResetError: [Errno 104] Connection reset by peer

Can anyone fix it or explain how it works? Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions