Skip to content

A KeyError occurred when running the example code. #66

@JixiongRen

Description

@JixiongRen

Hi everyone, @samuelmyoussef @alxbilger @EulalieCoevoet @damienmarchal @ChristianDuriez

I encountered several issues while using SofaGym:

Issue 1:

I frequently get a KeyError when running example code with SofaGym. For instance, when running the following code (consistent with the README example):

import gym
import sofagym.envs

path = "data"

env = gym.make('trunk-v0')
env.seed(42)
observation = env.reset()

done = False
while not done:
    action = env.action_space.sample()  # this is where you would insert your policy
    observation, reward, done, info = env.step(action)
    env.render()
   
env.close()

I receive the following exception:

ub20@JixiongRenPC:~/SOFA_v23.06.00_Linux/bin/SofaGym$ /bin/python /home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/test.py
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: /home/ub20/SOFA_v23.06.00_Linux
---------------------------------------
pygame 2.6.1 (SDL 2.28.4, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
[INFO]    [PluginManager] Loaded plugin: /home/ub20/SOFA_v23.06.00_Linux/lib/libSofa.Component.so
[ERROR]   [SofaRuntime] AttributeError: 'NoneType' object has no attribute 'get'
Traceback (most recent call last):
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/test.py", line 6, in <module>
    env = gym.make('trunk-v0')
  File "/home/ub20/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 235, in make
    return registry.make(id, **kwargs)
  File "/home/ub20/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 129, in make
    env = spec.make(**kwargs)
  File "/home/ub20/.local/lib/python3.8/site-packages/gym/envs/registration.py", line 90, in make
    env = cls(**_kwargs)
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/sofagym/envs/Trunk/TrunkEnv.py", line 53, in __init__
    super().__init__(config)
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/sofagym/AbstractEnv.py", line 134, in __init__
    self.config["dt"] = self.config.get('dt', 0.01)

Initially, I tried adding configurations to the gym.make() , like this:

env = gym.make('trunk-v0', config={"scene": "Trunk",
                                "deterministic": True,
                                "source": [300, 0, 80],
                                "target": [0, 0, 80],
                                "goalList": [[40, 40, 100], [-10, 20, 80]],
                                "start_node": None,
                                "scale_factor": 5,
                                "timer_limit": 250,
                                "timeout": 50,
                                "display_size": (1600, 800),
                                "render": 1,
                                "save_data": False,
                                "save_image": False,
                                "save_path": path + "/Results" + "/Trunk",
                                "planning": False,
                                "discrete": True,
                                "seed": None,
                                "start_from_history": None,
                                "python_version": "python3",
                                "dt": 0.01,
                                "nb_actions": 2, 
                                "dim_state": 3,
                                "goalPos": [0, 0, 80],
                                "randomize_states": False,})

Most of these config options were copied from TrunkEnv.py. However, this did not resolve the issue, and I still encountered:

[ERROR]   [SofaRuntime] KeyError: 'goal'
Traceback (most recent call last):
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/test.py", line 31, in <module>
    observation = env.reset()
  File "/home/ub20/.local/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 16, in reset
    return self.env.reset(**kwargs)
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/sofagym/envs/Trunk/TrunkEnv.py", line 75, in reset
    super().reset()
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/sofagym/AbstractEnv.py", line 392, in reset
    self.init_simulation()
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/sofagym/AbstractEnv.py", line 507, in init_simulation
    if self.config["goal"]:

Clearly, this exception cannot be fixed by simply adding missing configurations.


Issue 2:

When attempting to run python3 test_env.py -e trunk-v0 -ep 100 -s 100, I get:

ub20@JixiongRenPC:~/SOFA_v23.06.00_Linux/bin/SofaGym$ python3 test_env.py -e trunk-v0 -ep 100 -s 100
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: /home/ub20/SOFA_v23.06.00_Linux
---------------------------------------
pygame 2.6.1 (SDL 2.28.4, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
[INFO]    [PluginManager] Loaded plugin: /home/ub20/SOFA_v23.06.00_Linux/lib/libSofa.Component.so
[ERROR]   Environment name does not exist.
Available environments:
['bubblemotion-v0', 'cartstem-v0', 'cartstemcontact-v0', 'catchtheobject-v0', 'concentrictuberobot-v0', 'diamondrobot-v0', 'gripper-v0', 'maze-v0', 'multigaitrobot-v0', 'simple_maze-v0', 'stempendulum-v0', 'trunk-v0', 'trunkcup-v0', 'cartpole-v0', 'catheter_beam-v0']

I tried adding sofagym/ to the environment variables, but it did not work.


Issue 3:

When trying to train with python rl.py -e trunk-v0 -a PPO, I encounter:

ub20@JixiongRenPC:~/SOFA_v23.06.00_Linux/bin/SofaGym$ python rl.py -e trunk-v0 -a PPO
Traceback (most recent call last):
  File "rl.py", line 18, in <module>
    from agents.RLberryAgent import RLberryAgent
  File "/home/ub20/SOFA_v23.06.00_Linux/bin/SofaGym/agents/RLberryAgent.py", line 12, in <module>
    from rlberry.agents.experimental.torch import SACAgent
  File "/home/ub20/.local/lib/python3.8/site-packages/rlberry/__init__.py", line 12, in <module>
    configure_logging(level="INFO")
  File "/home/ub20/.local/lib/python3.8/site-packages/rlberry/utils/logging.py", line 112, in configure_logging
    gym.logger.set_level(
AttributeError: module 'gymnasium.logger' has no attribute 'set_level'

My environment:

  • Python 3.8
  • SOFA v23.06 (binary version with required plugins included)
  • Configured exactly as per the README (except SPLIB plugin, as I was informed by SOFA that SPLIB is now integrated into STLIB)
    I have spent significant time setting up SofaGym, but none of the examples work, which is highly frustrating :-(. I believe I need your assistance.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions