0

Greetings!

I am new to stable-baselines3, but I have watched numerous tutorials on its implementation and the custom environment formulation.

After developing my model using gym and stable-baselines3 SAC algorithm, I applied (check_env) function to check for possible errors and everything is perfect. However, whenever I run the code, the only output I saw is:

Using cpu device Wrapping the env in a DummyVecEnv

And the training session will stop without any output or save the model into the directory file.

Please what can be wrong, I have already set the verbose to 1.

Best Regards, Mich

1 Answers1

0

I have a similar issue with my code. It shows only "Using cpu device", and not printing the monitoring variables inside my environment. Further, when I use env = make_vec_env(env_id, n_envs=num_cpu) instead of SubprocVecEnv, then it prints my variables but seems does not use all CPU cores!

thanks

import gym
import numpy as np

from stable_baselines3 import DQN, PPO, A2C, SAC
from stable_baselines3.common.evaluation import evaluate_policy

from stable_baselines3.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines3.common.utils import set_random_seed
from stable_baselines3.common.evaluation import evaluate_policy
from stable_baselines3.common.env_util import make_vec_env

from gym.envs.registration import load_env_plugins as _load_env_plugins
from gym.envs.registration import make, register, registry, spec

register(
    id="SmartCHP-v0",
    entry_point="SmartCHP_env:CHPEnv"
)


def make_env(env_id, rank, seed=0):
    """
    Utility function for multiprocessed env.

    :param env_id: (str) the environment ID
    :param num_env: (int) the number of environments you wish to have in subprocesses
    :param seed: (int) the inital seed for RNG
    :param rank: (int) index of the subprocess
    """
    def _init():
        env = gym.make(env_id)
        env.seed(seed + rank)
        return env
    set_random_seed(seed)
    return _init

env_id = "SmartCHP-v0"


if __name__ == '__main__':
    env_id = "SmartCHP-v0"
    num_cpu = 16  # Number of processes to use
    # Create the vectorized environment
    env = SubprocVecEnv([make_env(env_id, i) for i in range(num_cpu)])
    # env = make_vec_env(env_id, n_envs=num_cpu)   

    model = A2C('MlpPolicy', env, verbose=1).learn(total_timesteps=int(2*24*98))