Stable-baselines: SubprocVecEnv with different envrionmental variables for each gym environment

Created on 1 Jul 2020  路  5Comments  路  Source: hill-a/stable-baselines

It seems to me that using SubprocVecEnv is only possible to have multiple gym environments all of which use the same environmental variables.

I have a gym environment that if I want to instantiate it more than once, I have to give another environmental variables to it, that is for example start it in a separate terminal with different environmental variables or use python subprocess Popen multiple times each with different environments given to it(which won't let me access the gym environment object then to call step for example.

But is there a way to use SubprocVecEnv for such case?

custom gym env question

All 5 comments

Yes you can create different environments for VecEnvs, just see how make_env works in this docs example. As for your particular case, you _could_ try setting the environment variable with os.environ["VARIABLE_NAME"] = "value" inside the environment __init__ function, but I have no idea if it would work.

I think using os.environ["VARIABLE_NAME"] = "value" will change the environmental variable for all the previously initialized evironments also if it's called by the same process.

like when we useSubprocVecEnv([make_env(env_id, i) for i in range(num_cpu)]) the make_env(env_id, i) will is called first by the same process for every environment, and each time setting the environmental variable will likely change the other ones too.

Yes, but the environment's __init__ is called in a new process when using a subprocvecenv.

In any case, this is bit outside of stable-baselines. If there are no issues/bugs/suggestions to raise regarding stable-baselines itself, you can close this issue.

you're right, is there also a way that when the new process calls __init__, it gives also a particular argument to this call?

At the moment it would work for me if each process would call __init__ with a different argument (like __init__(_id=0).

The example above demonstrate just that (see how rank is passed).

Was this page helpful?
0 / 5 - 0 ratings