rail-berkeley / rlkit

Collection of reinforcement learning algorithms
MIT License
2.45k stars 550 forks source link

launch different seeds simulateously #106

Open ChenyangRan opened 4 years ago

ChenyangRan commented 4 years ago

HI, I want to test different seeds for example/sac.py at the same time. I use the function named run_experiment_here, but the variant['seed'] should be int. I use a list such as following:

    for seed in seeds:
        run_experiment_here(experiment_function=experiment, variant=variant,
                        exp_id=seed, seed=seed, snapshot_mode='gap', snapshot_gap=10, exp_prefix='HalfCheetahEnv')

The error is

Traceback (most recent call last):
  File "/home/ur/RL_code/torch/rlkit/examples/il_sac.py", line 124, in <module>
    exp_id=seed, seed=seed, snapshot_mode='gap', snapshot_gap=10, exp_prefix='HalfCheetahEnv'+str(seed))
  File "/home/ur/RL_code/torch/rlkit/rlkit/launchers/launcher_util.py", line 166, in run_experiment_here
    return experiment_function(variant)
  File "/home/ur/RL_code/torch/rlkit/examples/il_sac.py", line 89, in experiment
    algorithm.train()
  File "/home/ur/RL_code/torch/rlkit/rlkit/core/rl_algorithm.py", line 46, in train
    self._train()
  File "/home/ur/RL_code/torch/rlkit/rlkit/core/il_batch_rl_algorithm.py", line 64, in _train
    gt.stamp('evaluation sampling')
  File "/home/ur/anaconda3/envs/rlkit/lib/python3.5/site-packages/gtimer/public/timer.py", line 151, in stamp
    _stamp(name, elapsed, unique, keep_subdivisions, quick_print)
  File "/home/ur/anaconda3/envs/rlkit/lib/python3.5/site-packages/gtimer/public/timer.py", line 698, in _stamp
    _loop_stamp(name, elapsed, unique)
  File "/home/ur/anaconda3/envs/rlkit/lib/python3.5/site-packages/gtimer/public/timer.py", line 714, in _loop_stamp
    _init_loop_stamp(name, unique)
  File "/home/ur/anaconda3/envs/rlkit/lib/python3.5/site-packages/gtimer/public/timer.py", line 725, in _init_loop_stamp
    raise UniqueNameError("Duplicate stamp name (in or at loop): {}".format(name))
gtimer.local.exceptions.UniqueNameError: Duplicate stamp name (in or at loop): evaluation sampling 

Maybe run_experiment can do it, but the same error happens again.

    for exp_id, variant in enumerate(sweeper.iterate_hyperparameters()):
        print('exp_id:{1},variant:{0}'.format(variant, exp_id))
        for seed in seeds:
            run_experiment(
                experiment,
                exp_prefix=exp_prefix,
                mode=mode,
                seed=seed,
                exp_id=exp_id,
                variant=variant,
                use_gpu=True,
                snapshot_gap=100,
                snapshot_mode='gap_and_last', 
            )

I run it by anaconda.

Could you please help me? Or is anyother function can launch different function that can do it?

kovacgrgur commented 3 years ago

I believe you can fix this by adding gt.reset_root()at the end of the BatchRLAlgorithm constructor. Add it at:rlkit/core/batch_rl_algorithm.py line 43 (or in your case il_batch_rl_algorithm.py)

snasiriany commented 3 years ago

I encountered this issue as well, and @kovacgrgur 's solution works! @vitchyr @anair13 would you mind adding this in?

vitchyr commented 3 years ago

Feel free to make a PR and I'll merge it in!

snasiriany commented 3 years ago

@vitchyr here it is: https://github.com/rail-berkeley/rlkit/pull/142