RyanNavillus/reward-surfaces

AttributeError: 'int' object has no attribute 'parent'

Opened this issue · 3 comments

Hello,
when I tried to train an agent with this command line

python3 scripts/train_agent.py "./runs/cartpole_checkpoints" SB3_ON CartPole-v1 cuda '{"ALGO": "PPO"}' --save_freq=10000

the following error occurred :

(base) cyl@WP:~/reward-surfaces-master$ python3 scripts/train_agent.py "./runs/cartpole_checkpoints" SB3_ON CartPole-v1 cuda '{"ALGO": "PPO"}' --save_freq=10000
/home/cyl/anaconda3/lib/python3.9/site-packages/stable_baselines3-1.6.0-py3.9.egg/stable_baselines3/__init__.py
False
Default hyperparameters for environment (ones being tuned will be overridden):
OrderedDict([('batch_size', 256),
             ('clip_range', 'lin_0.2'),
             ('ent_coef', 0.0),
             ('gae_lambda', 0.8),
             ('gamma', 0.98),
             ('learning_rate', 'lin_0.001'),
             ('n_envs', 8),
             ('n_epochs', 20),
             ('n_steps', 32),
             ('n_timesteps', 100000.0),
             ('policy', 'MlpPolicy')])
Using 8 environments
cuda
Log path: ./runs/cartpole_checkpoints/ppo/CartPole-v1_5
Traceback (most recent call last):
  File "/home/cyl/reward-surfaces-master/scripts/train_agent.py", line 71, in <module>
    main()
  File "/home/cyl/reward-surfaces-master/scripts/train_agent.py", line 67, in main
    agent.train(steps, args.save_dir, save_freq=args.save_freq)
  File "/home/cyl/anaconda3/lib/python3.9/site-packages/reward_surfaces-0.0.1-py3.9.egg/reward_surfaces/agents/SB3/sb3_on_policy_train.py", line 371, in train
    checkpoint_callback = self.create_callbacks(save_dir, save_freq=save_freq, prefix=save_prefix)
  File "/home/cyl/anaconda3/lib/python3.9/site-packages/reward_surfaces-0.0.1-py3.9.egg/reward_surfaces/agents/SB3/sb3_on_policy_train.py", line 353, in create_callbacks
    eval_callback = EvalParamCallback(
  File "/home/cyl/anaconda3/lib/python3.9/site-packages/reward_surfaces-0.0.1-py3.9.egg/reward_surfaces/agents/SB3/sb3_on_policy_train.py", line 142, in __init__
    super(EvalParamCallback, self).__init__(eval_env, callback_on_new_best, n_eval_episodes, eval_freq, log_path,
  File "/home/cyl/anaconda3/lib/python3.9/site-packages/stable_baselines3-1.6.0-py3.9.egg/stable_baselines3/common/callbacks.py", line 310, in __init__
    super().__init__(callback_after_eval, verbose=verbose)
  File "/home/cyl/anaconda3/lib/python3.9/site-packages/stable_baselines3-1.6.0-py3.9.egg/stable_baselines3/common/callbacks.py", line 134, in __init__
    self.callback.parent = self
AttributeError: 'int' object has no attribute 'parent'

I hope I can get your help,Thanks.

Did you solve this issue? I clone this code to my local computer. But I still suffer from this issue. I tried to solve this issue but I failed. :(

I got the same error

A late response here.
Change the super init function of class EvalParamCallback in sb3_on_policy_train.py from:

super(EvalParamCallback, self).__init__(eval_env, callback_on_new_best, n_eval_episodes, eval_freq, log_path,
                                                best_model_save_path, deterministic, render, verbose, warn)

to

super(EvalParamCallback, self).__init__(eval_env, callback_on_new_best, 
                                                n_eval_episodes = n_eval_episodes, 
                                                eval_freq = eval_freq, 
                                                log_path = log_path,
                                                best_model_save_path = best_model_save_path, 
                                                deterministic = deterministic, 
                                                render = render, 
                                                verbose = verbose, 
                                                warn = warn)

The problem is due to the class EvalParamCallback and its parent class EvalCallback.

EvalCallback init() can pass an additional callback_after_eval function but not in EvalParamCallback. So it's getting n_eval_episodes as the callback function.