Skip to content
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

Add scripts to run benchmark experiments #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse
import shlex
import subprocess


def parse_args():
# fmt: off
parser = argparse.ArgumentParser()
parser.add_argument("--env_names", nargs="+", default=["CartPole-v1", "Acrobot-v1", "MountainCar-v0"],
help="the ids of the environment to benchmark")
parser.add_argument("--command", type=str, default="poetry run python cleanrl/ppo.py",
help="the command to run")
parser.add_argument("--num-seeds", type=int, default=3,
help="the number of random seeds")
parser.add_argument('--workers', type=int, default=0,
help='the number of eval workers to run benchmark experimenets (skips evaluation when set to 0)')
args = parser.parse_args()
# fmt: on
return args


def run_experiment(command: str):
command_list = shlex.split(command)
print(f"running {command}")
fd = subprocess.Popen(command_list)
return_code = fd.wait()
assert return_code == 0


if __name__ == "__main__":
args = parse_args()
commands = []
for seed in range(1, args.num_seeds + 1):
for env_name in args.env_names:
commands += [" ".join([args.command, "--env_name", env_name, "--seed", str(seed)])]

print(commands)

if args.workers > 0:
from concurrent.futures import ThreadPoolExecutor

executor = ThreadPoolExecutor(max_workers=args.workers, thread_name_prefix="cleanrl-benchmark-worker-")
for command in commands:
executor.submit(run_experiment, command)
executor.shutdown(wait=True, cancel_futures=False)
7 changes: 7 additions & 0 deletions examples/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export WANDB_ENTITY=openrlbenchmark

xvfb-run -a python benchmark.py \
--env_names HalfCheetah-v2 Hopper-v2 Humanoid-v2 InvertedDoublePendulum-v2 InvertedPendulum-v2 Pusher-v2 Reacher-v2 Swimmer-v2 Walker2d-v2 \
--command "poetry run python train.py --track --save_video" \
--num-seeds 10 \
--workers 1