-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] new feature: runner to launch over multiple virtual environments #377
base: main
Are you sure you want to change the base?
[WIP] new feature: runner to launch over multiple virtual environments #377
Conversation
* fix bug dill and compress always * change version
Now included: a decorator for running things in a guix container, (guix is like a very powerful package manager). Example: from rlberry.manager import with_guix, run_guix_xp
@with_guix(import_libs=["stable-baselines3"])
def run_sb():
import gymnasium as gym
from stable_baselines3 import A2C
env = gym.make("CartPole-v1")
model = A2C("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=1_500)
vec_env = model.get_env()
obs = vec_env.reset()
cum_reward = 0
for i in range(1000):
action, _state = model.predict(obs, deterministic=True)
obs, reward, done, info = vec_env.step(action)
cum_reward += reward
print(cum_reward)
if __name__ == "__main__":
run_guix_xp(keep_build_dir=True) |
For now, let us take it one at a time, I removed everything guix and this is only for venv. I will do guix in a separate PR. |
Hello, |
Hello, |
Hello, |
Hello, |
Hello, |
Hello, |
return filename | ||
|
||
|
||
def with_venv(import_libs=None, requirements=None, python_ver=None, verbose=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify how 'import_libs' and 'requirements' work in the doc (only one to be used, or which takes priority over the other)?
In addition, maybe add an 'if' to force only one of the parameters to be used.
for RL experimentation with several separated environments. | ||
|
||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe explain how 'run_venv_xp' is linked to 'run_sb' and 'run_mushroom'.
- explain : scripts are generated at compile time (through annotation), but functions 'run_sb' / 'run_mushroom' are not directly called.
- explain more 'run_venv_xp': run scripts in a folder where functions have added 'run_sb' / 'run_mushroom' content. (perhaps add the parameter for folder_name in the example to make it more readable?)
In this PR I add code meant to simplify running experiments over multiple virtual environment. The main tool for this is nox that I wrap using decorators. You just need to wrap a function with
@with_venv
decorator to execute it in a separate virtual environment. This could become an alternative torlberry.experiments
with some work. This is also nice for deployment purpose because all the libraries are automatically installed, you just need to run the script and have python and rlberry installed all the other libraries are automatically installed as needed.Example of code:
The first time this is run, virtual environments are created in the directory in which the script is, subsequent call reuse the virtual environments. The initial environment I am in only needs to have rlberry installed, but not stablebaselines3 or mushroom-rl. For now, I use it to run code from these libraries without trying to interface further with rlberry. The virtual environments can contain different libraries and can be run using different python executables (as in the example).
The result is then
@mmcenta : this is what I had in mind while saying that rlberry could handle virtual environments.
This is a proof of concept, it works, but this is very preliminary work.