SofaDefrost / SofaGym

Machine Learning framework for Sofa
72 stars 10 forks source link

ConcentricTubeRobot Example Error #58

Open katahar opened 5 months ago

katahar commented 5 months ago

Current configuration: Ubuntu 20.04 Sofa v23.06.00 (From Binary) Python 3.8.10

When running example (python test_env.py -e concentrictuberobot-v0 -ep 100 -s 100), simulation runs successfully, but when throws this error when training (python rl.py -e concentrictuberobot-v0 -a DQN)

  [SofaRuntime] UFuncTypeError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('<U1'), dtype('float64')) -> None
Traceback (most recent call last):
  File "rl.py", line 114, in <module>
    agent.fit(total_timesteps)
  File "/home/ubuntu20_sofa/SofaGym/agents/SB3Agent.py", line 309, in fit
    self.model.learn(total_timesteps=total_timesteps, reset_num_timesteps=False,
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/dqn/dqn.py", line 265, in learn
    return super().learn(
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/off_policy_algorithm.py", line 334, in learn
    rollout = self.collect_rollouts(
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/off_policy_algorithm.py", line 567, in collect_rollouts
    new_obs, rewards, dones, infos = env.step(actions)
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 163, in step
    return self.step_wait()
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/vec_monitor.py", line 76, in step_wait
    obs, rewards, dones, infos = self.venv.step_wait()
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/vec_normalize.py", line 197, in step_wait
    infos[idx]["terminal_observation"] = self.normalize_obs(infos[idx]["terminal_observation"])
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/vec_normalize.py", line 240, in normalize_obs
    obs_ = self._normalize_obs(obs, self.obs_rms).astype(np.float32)
  File "/home/ubuntu20_sofa/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/vec_normalize.py", line 216, in _normalize_obs
    return np.clip((obs - obs_rms.mean) / np.sqrt(obs_rms.var + self.epsilon), -self.clip_obs, self.clip_obs)

Any advice here? I'm pretty sure that I have installed all of the dependencies correctly according to the readme, and this issue is confirmed on multiple installs/machines.

samuelmyoussef commented 4 months ago

Hello,

It looks like you're running a newer version of stable baselines3, can you make sure you're using v1.7.0 since SofaGym is not compatible with newer versions at the moment.

katahar commented 4 months ago

I am using V1.7.0

Is there anything else that I should look out for?

(pip show stable_baselines3 output below)

Name: stable-baselines3
Version: 1.7.0
Summary: Pytorch version of Stable Baselines, implementations of reinforcement learning algorithms.
Home-page: https://github.com/DLR-RM/stable-baselines3
Author: Antonin Raffin
Author-email: antonin.raffin@dlr.de
License: MIT
Location: /home/ubuntu20_sofa/.local/lib/python3.8/site-packages
Requires: cloudpickle, gym, importlib-metadata, matplotlib, numpy, pandas, torch
Required-by:
samuelmyoussef commented 4 months ago

You can check if you're running the correct gym version as well. and what is the numpy version?

katahar commented 4 months ago

I'm using: numpy version 1.24.4 gym version 0.21.0

And to clarify, I am able to run the Catheter Beam example and with learning.