'mujoco._structs.MjData' object has no attribute 'solver_iter'

1.5k views Asked by At

I'm following this tutorial from Jonny Codes and copied it exactly as shown: https://www.youtube.com/watch?v=OqvXHi_QtT0

My code is :

import gymnasium as gym
from stable_baselines3 import SAC, TD3, A2C
import os
import argparse

# Create directories to hold models and logs
model_dir = "models"
log_dir = "logs"
os.makedirs(model_dir, exist_ok=True)
os.makedirs(log_dir, exist_ok=True)

def train(env, sb3_algo):
    model = SAC('MlpPolicy', env, verbose=1, device='cpu', buffer_size=100000, tensorboard_log=log_dir)

    TIMESTEPS = 10000
    iters = 0
    while True:
        iters += 1

        model.learn(total_timesteps=TIMESTEPS, reset_num_timesteps=False)
        model.save(f"{model_dir}/{sb3_algo}_{TIMESTEPS*iters}")

def test(env, sb3_algo, path_to_model):
    model = SAC.load(path_to_model, env=env)

    obs = env.reset()[0]
    done = False
    extra_steps = 500
    while True:
        action, _ = model.predict(obs)
        obs, _, done, _, _ = env.step(action)

        if done:
            extra_steps -= 1

            if extra_steps < 0:
                break


if __name__ == '__main__':

    # Parse command line inputs
    parser = argparse.ArgumentParser(description='Train or test model.')
    parser.add_argument('gymenv', help='Gymnasium environment i.e. Humanoid-v4')
    parser.add_argument('sb3_algo', help='StableBaseline3 RL algorithm i.e. SAC, TD3')
    parser.add_argument('-t', '--train', action='store_true')
    parser.add_argument('-s', '--test', metavar='path_to_model')
    args = parser.parse_args()


    if args.train:
        gymenv = gym.make(args.gymenv, render_mode=None)
        train(gymenv, args.sb3_algo)

    if(args.test):
        if os.path.isfile(args.test):
            gymenv = gym.make(args.gymenv, render_mode='human')
            test(gymenv, args.sb3_algo, path_to_model=args.test)
        else:
            print(f'{args.test} not found.')


However, I'm getting the error:

    test(gymenv, args.sb3_algo, path_to_model=args.test)
...
...
    bottomleft, "Solver iterations", str(self.data.solver_iter + 1)
AttributeError: 'mujoco._structs.MjData' object has no attribute 'solver_iter'

I ommited the middle part of the error because I didn't think it was important but what am I doing wrong?

I tried to put it in a venv and use python vs python3 but nothing worked

1

There are 1 answers

0
Saran Tunyasuvunakool On BEST ANSWER

This is https://github.com/Farama-Foundation/Gymnasium/issues/749.

Either fix MuJoCo version to mujoco==2.3.0 or apply the fix mentioned on the Gymnasium repo.