MushroomRL / mushroom-rl-benchmark

Benchmarking suite for MushroomRL Deep RL algorithms
MIT License
15 stars 4 forks source link

TypeError: Gym.__init__() missing 1 required positional argument: 'name' #8

Open davidenitti opened 1 year ago

davidenitti commented 1 year ago

I have this error

Traceback (most recent call last):
  File "/home/davide/code/ML/RL/bench.py", line 37, in <module>
    exp.run(
  File "/home/davide/code/mushroom-rl-benchmark/mushroom_rl_benchmark/core/experiment.py", line 63, in run
    run_fn(**executor_params, **run_params)
  File "/home/davide/code/mushroom-rl-benchmark/mushroom_rl_benchmark/core/experiment.py", line 157, in run_parallel
    runs = parallel(
  File "/home/davide/code/mushroom-rl-benchmark/mushroom_rl_benchmark/utils/tqdm_parallel.py", line 9, in __call__
    return joblib.Parallel.__call__(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/joblib/parallel.py", line 1098, in __call__
    self.retrieve()
  File "/usr/local/lib/python3.10/dist-packages/joblib/parallel.py", line 975, in retrieve
    self._output.extend(job.get(timeout=self.timeout))
  File "/usr/local/lib/python3.10/dist-packages/joblib/_parallel_backends.py", line 567, in wrap_future_result
    return future.result(timeout=timeout)
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
TypeError: Gym.__init__() missing 1 required positional argument: 'name'

With this code:

import time
from mushroom_rl_benchmark.core import BenchmarkExperiment, BenchmarkLogger
from mushroom_rl_benchmark.builders import EnvironmentBuilder, PPOBuilder

if __name__ == '__main__':

    logger = BenchmarkLogger(
        log_dir='./logs',
        log_id='ppo_pendulum'
    )

    agent_builder = PPOBuilder.default(
        actor_lr=3e-4,
        critic_lr=3e-4,
        n_features=32
    )

    env_name = 'Gym'
    env_params = dict(
        env_id='Pendulum-v0',
        horizon=200,
        gamma=.99
    )

    parallel = dict(
            max_concurrent_runs=10
    )

    env_builder = EnvironmentBuilder(env_name, env_params)
    logger.info('Environment is imported')

    exp = BenchmarkExperiment(agent_builder, env_builder, logger)
    logger.info('BenchmarkExperiment was built successfully')

    start_time = time.time()
    exp.run(
        exec_type='parallel',
        n_runs=10,
        n_epochs=100,
        n_steps=30000,
        n_episodes_test=5,
        parallel=parallel
    )
    end_time = time.time()
    logger.info('Execution time: {} SEC'.format(end_time-start_time))

    exp.save_plot()
boris-il-forte commented 1 year ago

Dear @davidenitti

This code uses the old version of the benchmark (master branch) that is not supported anymore. The new version is almost ready, you can find it in the new_benchmark branch. Unfortunately, it has not been tested yet. Indeed, our experiment-launcher package, upon which we base our new benchmark, has some issues with wandb, causing some random seeds to crash. We are solving the issue right now.

to fix the current issue in your code, you could just change the lines specifying the environment:

env_name = 'Gym.Pendulum-v1'
    env_params = dict(
        horizon=200,
        gamma=.99
    )

Unfortunately, the code is still crashing with the newest version of mushroom, as we performed some minor changes in the interface.

nb: I set v1 in the code as the version of gym I'm using does not have Pendulum-v0