Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown error running SOFAgym TrunkEnv #24

Open
tdillonmit opened this issue Apr 14, 2023 · 19 comments
Open

Unknown error running SOFAgym TrunkEnv #24

tdillonmit opened this issue Apr 14, 2023 · 19 comments

Comments

@tdillonmit
Copy link

Hi

I'm trying to compile the example TrunkEnv, using a simple python function:

import gym
import sofagym.envs
import time

import sofagym

env = gym.make('trunk-v0')
observation, info = 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()

    done = terminated or truncated
   
env.close()

The terminal output errors are below. The line "observation, info = env.reset()" seems to be causing this. I'm using the SOFA binaries on Windows 10 with Python 3.7.

[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/Sofa.GL.Component.Shader.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/Sofa.Component.LinearSolver.Preconditioner.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/SofaComponentAll.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/STLIB.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/SoftRobots.dll

########## SIG 11 - SIGSEGV: segfault ##########
  sofa::helper::BackTrace::dump
  sofa::helper::BackTrace::sig
  seh_filter_exe
  seh_filter_exe
  _C_specific_handler
  _chkstk
  RtlRaiseException
  KiUserExceptionDispatcher
  PyObject_GetAttrString
  sofapython3::PythonEnvironment::getStaticData
  initExternalModule
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  PyMethodDef_RawFastCallKeywords
  PyCFunction_FastCallKeywords
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyEval_EvalCodeEx
  PyEval_EvalCode
  PyArena_Free
  PyRun_FileExFlags
  PyRun_SimpleFileExFlags
  PyRun_AnyFileExFlags
  Py_UnixMain
  Py_UnixMain
  PyErr_NoMemory
  Py_Main
  Py_Main
  Py_Main
  BaseThreadInitThunk
  RtlUserThreadStart
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\tom\documents\sofagym-main\sofagym\rpc_server.py", line 528, in deferredStart
    check=True)
  File "C:\Program Files\Python37\lib\subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['C:\\Program Files\\Python37\\python.exe', 'c:\\users\\tom\\documents\\sofagym-main/sofagym/rpc_client.py', "{'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': 'c:\\\\users\\\\tom\\\\documents\\\\sofagym-main\\\\sofagym\\\\envs\\\\Trunk/Results/Trunk', 'planning': False, 'discrete': True, 'seed': None, 'start_from_history': None, 'python_version': 'python3', 'dt': 0.01, 'save_path_image': None, 'save_path_results': None, 'goal_node': 1, 'goalPos': [-10, 20, 80]}", '16', '62505']' returned non-zero exit status 3.
@EtienneMenager
Copy link
Collaborator

Hi,

It seems that you are using both gym and gymnasium syntax. Can you try to change the allocation of the reset and done by doing "observation = env.reset()" and removing "done = terminated or truncate". Let me know.

Etienne

@tdillonmit
Copy link
Author

tdillonmit commented Apr 16, 2023

Hi Etienne,
I changed those two lines as you suggested, and I'm still getting a similar output as below. Any further suggestions you have would be greatly appreciated. Also should I be using "import gym", "import gymnasium" or "import gynasium as gym". In the below I am using import gym.
Thanks
Tom

[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/SofaComponentAll.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/STLIB.dll
[INFO]    [PluginManager] Loaded plugin: C:/Users/Tom/Documents/sofa_build/sofa_build/bin/SoftRobots.dll

########## SIG 11 - SIGSEGV: segfault ##########
  sofa::helper::BackTrace::dump
  sofa::helper::BackTrace::sig
  seh_filter_exe
  seh_filter_exe
  _C_specific_handler
  _chkstk
  RtlRaiseException
  KiUserExceptionDispatcher
  PyObject_GetAttrString
  sofapython3::PythonEnvironment::getStaticData
  initExternalModule
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo
  PyMethodDef_RawFastCallKeywords
  PyCFunction_FastCallKeywords
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyMethodDef_RawFastCallKeywords
  PyEval_EvalFrameDefault
  PyEval_EvalCodeWithName
  PyEval_EvalCodeEx
  PyEval_EvalCode
  PyArena_Free
  PyRun_FileExFlags
  PyRun_SimpleFileExFlags
  PyRun_AnyFileExFlags
  Py_UnixMain
  Py_UnixMain
  PyErr_NoMemory
  Py_Main
  Py_Main
  Py_Main
  BaseThreadInitThunk
  RtlUserThreadStart
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\tom\documents\sofagym-main\sofagym\rpc_server.py", line 528, in deferredStart
    check=True)
  File "C:\Program Files\Python37\lib\subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['C:\\Program Files\\Python37\\python.exe', 'c:\\users\\tom\\documents\\sofagym-main/sofagym/rpc_client.py', "{'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': 'c:\\\\users\\\\tom\\\\documents\\\\sofagym-main\\\\sofagym\\\\envs\\\\Trunk/Results/Trunk', 'planning': False, 'discrete': True, 'seed': None, 'start_from_history': None, 'python_version': 'python3', 'dt': 0.01, 'save_path_image': None, 'save_path_results': None, 'goal_node': 1, 'goalPos': [-10, 20, 80]}", '16', '52844']' returned non-zero exit status 3.

@EtienneMenager
Copy link
Collaborator

Hi,

We fix some error in the last pr. Can you try it?

Cheers,

Etienne

@tdillonmit
Copy link
Author

Hi, I tried reinstalling but still get the same error. Any other potential reasons for this issue?

@alxbilger
Copy link
Member

Please make sure you are able to run the SOFA scene https://github.com/SofaDefrost/SofaGym/blob/main/sofagym/envs/Trunk/TrunkScene.py

@tdillonmit
Copy link
Author

Hi @alxbilger yes the TrunkScene and TrunkEnv run fine
image

@EtienneMenager
Copy link
Collaborator

Hi, the error is not expressive and we can't reproduce it on our computer. Could you remove the try at the time of the creation of the scene to check if the problem does not come from here (file simulate.py). Also can you tell me at which precise moment of your test code there is the problem (render, step, reset, ...).

Cheers,

Etienne

@tdillonmit
Copy link
Author

Hi Etienne, the problem is coming when I run "observation = env.reset()". The creation of the scene "env = gym.make('trunk-v0')" runs fine. Let me know if theres some other way of providing additional information on the error
Thanks for your help so far
Tom

@EtienneMenager
Copy link
Collaborator

Sorry I can't give you an answer directly, as we can't reproduce the error we are doing by trial and error. Can you tell me which line of the reset produces the error? To do this, you can put prints in the AbstractEnv or use a debugger. The ideal would be to have a log a little more precise than the one you sent in your first message (which just tells me that a client is down). Let me know !

Etienne

@tdillonmit
Copy link
Author

I'm having trouble identifying the line in reset of abstractenv that produces the error. I put prints in the "initialization" and "reset" functions of abstractenv which seem to be ok and are present midway through the log below.

full log.txt

I can also look into TrunkEnv to see if placing print statements there makes the problem clear

@EtienneMenager
Copy link
Collaborator

Right, seems that everything is good during the make env. But I don’t see the message during the second initialisation … Can you check your test with another scene please.

Etienne

@tdillonmit
Copy link
Author

Hi Etienne, I tried with the cartstem scene and env instead. The error seems to be slightly more informative than last time, but its still complaining about subprocess.py. See the new log attached

new log.txt

Does my gym environment registration seem ok?
Thanks

@samuelmyoussef
Copy link
Member

Could you please try to run some of the scenes like trunk and cartstem using runSofa not python.
For example: runSofa TrunkScene.py

@EtienneMenager
Copy link
Collaborator

Hi Tom,

Yes, Samuel is right. In the new_log.txt we can see this error:

Traceback (most recent call last):
File "c:\users\tom\documents\sofagym-main/sofagym/rpc_client.py", line 174, in
root = init_simulation(config, _startCmd, mode='simu')
File "c:\users\tom\documents\sofagym-main\sofagym\simulate.py", line 44, in init_simulation
raise NotImplementedError("Importing your SOFA Scene Failed")

There is a problem in the construction of the scene. Perhaps this error is cause by the scene (and so you can see it with runSofa) or with some parameters you use during the simulation. Try to replace in simulate.py the lines (l.40-44)

try:
create_scene = importlib.import_module("sofagym.envs."+scene+"." + scene + "Scene").createScene
except:
print("sofagym.envs."+scene+"." + scene + "Scene")
raise NotImplementedError("Importing your SOFA Scene Failed")

with just

create_scene = importlib.import_module("sofagym.envs."+scene+"." + scene + "Scene").createScene

to see what is the problem with this import.

Let me know

Etienne

@tdillonmit
Copy link
Author

Thanks both for your continued help. Please find attached the updated log when I use runSofa TrunkScene.py instead of python. It looks like its missing the "linear solver" component.
updated_log.txt

Are there additional plugins I need to download? I cloned sofagym and downloaded the following binaries:
https://github.com/SofaDefrost/DefrostSofaBundle

@alxbilger
Copy link
Member

DefrostSofaBundle is outdated. Is is based on Sofa v22.06. You should use the latest binaries of Sofa.
If you cloned SofaGym, you should use the master branch of Sofa, otherwise try to clone the v22.12 branch.

@tdillonmit
Copy link
Author

Thanks @alxbilger
I installed the latest binaries and cloned SofaGym to the sofa root directory. When I run I'm now getting a new error:

C:\Users\Tom\SOFA\v22.12.00>python dummy_test.py
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: C:/Users/Tom/Documents/sofa_build/sofa_build
Using environment variable SOFAPYTHON3_ROOT: C:/Users/Tom/Documents/sofa_build/sofa_build/plugins/SofaPython3
---------------------------------------
Traceback (most recent call last):
  File "dummy_test.py", line 3, in <module>
    import sofagym.envs
  File "c:\users\tom\sofa\v22.12.00\sofagym\sofagym\envs\__init__.py", line 1, in <module>
    from sofagym.envs.BubbleMotion.BubbleMotionEnv import *
  File "c:\users\tom\sofa\v22.12.00\sofagym\sofagym\envs\BubbleMotion\BubbleMotionEnv.py", line 11, in <module>
    from sofagym.AbstractEnv import AbstractEnv
  File "c:\users\tom\sofa\v22.12.00\sofagym\sofagym\AbstractEnv.py", line 18, in <module>
    import splib3
  File "C:\Users\Tom\SOFA\v22.12.00\plugins\STLIB\lib\python3\site-packages\splib3\__init__.py", line 19, in <module>
    import splib3.utils
  File "C:\Users\Tom\SOFA\v22.12.00\plugins\STLIB\lib\python3\site-packages\splib3\utils.py", line 12, in <module>
    import Sofa
  File "C:\Users\Tom\SOFA\v22.12.00\plugins\SofaPython3\lib\python3\site-packages\Sofa\__init__.py", line 107, in <module>
    import Sofa.Helper
ModuleNotFoundError: No module named 'Sofa.Helper'

C:\Users\Tom\SOFA\v22.12.00>echo %PYTHONPATH%
plugins\SofaPython3\lib\python3\site-packages;plugins\STLIB\lib\python3\site-packages

This forum has a similar problem, but I'm not sure how to resolve the issue:
https://www.sofa-framework.org/community/forum/topic/modulenotfounderror-sofa-helper-with-binary-install-v21-06-02/

@EtienneMenager
Copy link
Collaborator

Do you set your pythonpath to the sofapython3 plugin ?

@tdillonmit
Copy link
Author

tdillonmit commented Apr 24, 2023

Yes, and I'm still getting the same error (whether I use a relative or absolute path for the Sofapython3 library)

C:\Users\Tom\SOFA\v22.12.00>echo %PYTHONPATH%
plugins/SofaPython3;plugins/SofaPython3/lib/python3/site-packages;plugins/STLIB/lib/python3/site-packages

C:\Users\Tom\SOFA\v22.12.00>echo %SOFAPYTHON3_ROOT%
C:/Users/Tom/Documents/sofa_build/sofa_build/plugins/SofaPython3

C:\Users\Tom\SOFA\v22.12.00>echo %SOFA_ROOT%
C:/Users/Tom/Documents/sofa_build/sofa_build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants