SofaDefrost / SofaGym

Machine Learning framework for Sofa
69 stars 10 forks source link

Make SOFA Binary #2

Open p-shg opened 2 years ago

p-shg commented 2 years ago

Make SOFA binary and test code with binary

Need to add a SOFA Binary with compiled plugins to allow to test the code and free users from compiling SOFA from scratch Needed plugins: SP3 STLIB SoftRobots SoftRobots.Inverse BeamAdapter Cosserat
MOR

SantiDiazC commented 1 year ago

Hi, I was wondering if you have the binary with the required plugins so it can be added to this repo. I succeded compiling SOFA but still struggling compiling the plugins, so a binary with all the dependencies will be awesome. Thanks for your work! I was looking around for something like this for my research.

EtienneMenager commented 1 year ago

Hi,

There is a binary for SOFA in the official website here. The binary include all the plugins you need.

Cheers,

Etienne

SantiDiazC commented 1 year ago

Thanks for your fast reply Etienne!

I just downloaded the binary from the website you said, and as said in the quickstart section I put:

export SOFA_ROOT=/sofa/build_dir/ To the directory I uncompressed the zip file. However, I don't know how to set the: export PYTHONPATH=/sofa/build_dir/lib/python3/site-packages:$PYTHONPATH since there is no ../python3/lib/site-packages on that build.

I don't know if there is an additional step to make things work, I just create my own python environment (Python 3.8) with the libraries listed as requirements in the documentation pip install gym==0.21 psutil pygame glfw pyopengl imageio inside pycharm. and when running the example code:

import gym import sofagym.envs

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 got the following error: ModuleNotFoundError: No module named 'splib3' I would appreciate a lot if you can tell me how to make it run with the binary. Thank you in advanced!

Santiago

EtienneMenager commented 1 year ago

It seems that it is a problem with STLIB. Could you indicate in your pythonpath the path to stlib3 and splib3?

SantiDiazC commented 1 year ago

Thanks for your answer I set the pythonpath where it looks the stlib3 and splib3 are located in the folder of sofa binary after unzip it: ../SOFA/v22.12.00/plugins/STLIB/lib/python3/site-packages/

now when I run the example:

python test_env.py -e trunk-v0 -ep 100 -s 100

there is the following error:

Traceback (most recent call last): File "test_env.py", line 23, in from sofagym.envs import File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/envs/init.py", line 1, in from sofagym.envs.BubbleMotion.BubbleMotionEnv import File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/envs/BubbleMotion/BubbleMotionEnv.py", line 11, in from sofagym.AbstractEnv import AbstractEnv File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/AbstractEnv.py", line 18, in import splib3 File "/home/hri/SOFA/v22.12.00/plugins/STLIB/lib/python3/site-packages/splib3/init.py", line 19, in import splib3.utils File "/home/hri/SOFA/v22.12.00/plugins/STLIB/lib/python3/site-packages/splib3/utils.py", line 12, in import Sofa ModuleNotFoundError: No module named 'Sofa'

And also when I tried to run the scene as recommended #24 with the runSofa the scene is not loaded:

Checking SOFA_ROOT and SOFAPYTHON3_ROOT Using environment variable SOFA_ROOT: /home/hri/SOFA/v22.12.00/

[INFO] [PluginManager] Loaded plugin: /home/hri/SOFA/v22.12.00/plugins/SofaPython3/lib/libSofaPython3.so [INFO] [PluginManager] Loaded plugin: /home/hri/SOFA/v22.12.00/plugins/SoftRobots/lib/libSoftRobots.so [INFO] [SofaPython3] Added '/home/hri/SOFA/v22.12.00/plugins/SoftRobots/lib/python3/site-packages' to sys.path [INFO] [PluginManager] 5 plugins have been loaded from /home/hri/SOFA/v22.12.00//config/loadedPlugins.ini

pygame 2.4.0 (SDL 2.26.4, Python 3.8.10) Hello from the pygame community. https://www.pygame.org/contribute.html [ERROR] [SofaPython3::SceneLoader] Missing createScene function [INFO] [SceneCheckerVisitor] Validating node "root" with checks: [SceneCheckDuplicatedName, >SceneCheckMissingRequiredPlugin, SceneCheckUsingAlias, SceneCheckDeprecatedComponents, >SceneCheckCollisionResponse] [INFO] [SceneCheckerVisitor] Finished validating node "root".

Is there something I still need to configure to make it work? thank you in advanced!

EtienneMenager commented 1 year ago

Are you both SPLIB and SofaPyhton in your PythonPath? Look like your SofaPython3 is not in your python path ... (error: ModuleNotFoundError: No module named 'Sofa')

SantiDiazC commented 1 year ago

I added the SofaPython3 as well as indicated in the

cd ~/SOFABUNDLE* export PYTHONPATH="plugins/SofaPython3/lib/python3/site-packages" export PYTHONPATH=$PYTHONPATH:"plugins/STLIB/lib/python3/site-packages"

and then it didn't recognize sofagym:

python test.py

Checking SOFA_ROOT and SOFAPYTHON3_ROOT Using environment variable SOFA_ROOT: /home/hri/SOFA/v22.12.00/

pygame 2.4.0 (SDL 2.26.4, Python 3.8.16) Hello from the pygame community. https://www.pygame.org/contribute.html [INFO] [PluginManager] Loaded plugin: /home/hri/SOFA/v22.12.00/lib/libSofa.Component.so 56519 /home/hri/anaconda3/envs/sofa_gym/lib/python3.8/site-packages/gym/spaces/box.py:73: UserWarning: WARN: Box bound >precision lowered by casting to float32 logger.warn( All clients are closed. Bye Bye. Traceback (most recent call last): File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/rpc_client.py", line 24, in from sofagym.simulate import init_simulation, step_simulation ModuleNotFoundError: No module named 'sofagym' Exception in thread Thread-2: Traceback (most recent call last): File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/rpc_server.py", line 527, in deferredStart subprocess.run([sys.executable, path+"sofagym/rpc_client.py", sdict, str(nb_actions), str(port_rpc)], File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/subprocess.py", line 516, in run raise CalledProcessError(retcode, process.args,

so I added to the path as well by: export PYTHONPATH=$PYTHONPATH:"/home/hri/PycharmProjects/sofa_gym/SofaGym/" Where I cloned the sofagym repository, and now I am getting the following error:

Checking SOFA_ROOT and SOFAPYTHON3_ROOT Using environment variable SOFA_ROOT: /home/hri/SOFA/v22.12.00/

pygame 2.4.0 (SDL 2.26.4, Python 3.8.16) Hello from the pygame community. https://www.pygame.org/contribute.html [INFO] [PluginManager] Loaded plugin: /home/hri/SOFA/v22.12.00/lib/libSofa.Component.so [ERROR] [SofaRuntime] Exception: SPLIB is now relocated at: https://github.com/SofaDefrost/STLIB, please clone and >install the plugin to use it Traceback (most recent call last): File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/rpc_client.py", line 169, in _getState = importlib.import_module("sofagym.envs."+scene+"."+scene+"Toolbox").getState File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 843, in exec_module File "", line 219, in _call_with_frames_removed File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/envs/Trunk/TrunkToolbox.py", line 17, in from splib.animation.animate import Animation File "/home/hri/SOFA/v22.12.00/plugins/SofaPython3/lib/python3/site-packages/splib/init.py", line 2, in raise Exception("SPLIB is now relocated at: https://github.com/SofaDefrost/STLIB, please clone and install the plugin to use >it")

Exception in thread Thread-2: Traceback (most recent call last): File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/home/hri/PycharmProjects/sofa_gym/SofaGym/sofagym/rpc_server.py", line 527, in deferredStart subprocess.run([sys.executable, path+"sofagym/rpc_client.py", sdict, str(nb_actions), str(port_rpc)], File "/home/hri/anaconda3/envs/sofa_gym/lib/python3.8/subprocess.py", line 516, in run raise CalledProcessError(retcode, process.args,

I don't know if it is a problem adding the Python path, should I add it differently or is it located in a different folder in the zip file of the binary? thank you in advanced!

EtienneMenager commented 1 year ago

Two thing to test:

  1. Replace the l.17 of the trunk toolbox with: from splib3.animation.animate import Animation
  2. If it doesn't work, clone the branch v22.12 https://github.com/SofaDefrost/STLIB, and replace your python path of stlib in the bundle by this one (find where are splib3 and stlib3).

@samuelmyoussef do you know why there is a splib and not splib3 in the toolbox?

samuelmyoussef commented 1 year ago

Not sure why, but if you try to replace splib with splib3 in trunk toolbox it causes an error. You also need to modify these lines:

SantiDiazC commented 1 year ago

Thank you for your replies! I did change the lines on TrunkToolbox and TrunkScene and removing the realTimeClock as well and the error disappear. However, there is a new problem and the scene is not loaded, this is what it shows:

pygame 2.4.0 (SDL 2.26.4, Python 3.8.16) Hello from the pygame community. https://www.pygame.org/contribute.html [INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/lib/libSofa.Component.so [INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/plugins/BeamAdapter/lib/libBeamAdapter.so

########## SIG 11 - SIGSEGV: segfault ########## sofa::helper::BackTrace::sig(int) PyObject_GetAttrString sofapython3::PythonEnvironment::getPythonCallingPointAsFileInfo() PyCFunction_Call _PyObject_MakeTpCall _PyEval_EvalFrameDefault _PyFunction_Vectorcall _PyEval_EvalFrameDefault _PyEval_EvalCodeWithName _PyFunction_Vectorcall _PyEval_EvalFrameDefault _PyEval_EvalCodeWithName _PyFunction_Vectorcall _PyEval_EvalFrameDefault _PyEval_EvalCodeWithName _PyFunction_Vectorcall _PyEval_EvalFrameDefault _PyEval_EvalCodeWithName PyEval_EvalCodeEx PyEval_EvalCode PyRun_SimpleFileExFlags Py_BytesMain __libc_start_main Exception in thread Thread-2: Traceback (most recent call last): File "/home/hri/anaconda3/envs/SOFA/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/hri/anaconda3/envs/SOFA/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/SofaGym/sofagym/rpc_server.py", >line 527, in deferredStart subprocess.run([sys.executable, path+"sofagym/rpc_client.py", sdict, str(nb_actions), str(port_rpc)], File "/home/hri/anaconda3/envs/SOFA/lib/python3.8/subprocess.py", line 516, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/home/hri/anaconda3/envs/SOFA/bin/python', >'/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/SofaGym/sofagym/rpc_client.py', "{'scene': >'Gripper', 'deterministic': True, 'source': [0, -80, 350], 'target': [0, -80, 0], 'goalList': [[0, 10, 0], [0, 20, 0], [0, 30, 0]], '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': >'/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/SofaGym/sofagym/envs/Gripper/Results/G>ripper', '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': 2, 'goalPos': [0, 30, 0]}", '8', '33225']' died with ><Signals.SIGSEGV: 11>.

I tried to test on other environments to see if it has the same problem and it happens the same to the gripper-v0. In the case of the bubblemotion-v0 there is no error after fixing the same lines to the splib3 in similar files, but the terminal shows this (No rendering):

[INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/lib/libSofa.Component.IO.Mesh.so [INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/plugins/SofaLoader/lib/libSofaLoader.so [INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/lib/libSofa.Component.Playback.so [INFO] [PluginManager] Loaded plugin: >/home/hri/PycharmProjects/SOFA/DefrostSofaBundle_linux_python3.8_v22.06.01/plugins/SofaGeneralLoader/lib/libSofaGene>ralLoader.so >> Init bubblemotion_config... >> Init bubblemotion... >> Init bubblemotion... >> Init done. [WARNING] [CGLinearSolver(CGLinearSolver)] Required data "threshold" has not been set. Falling back to default value: 1e-> 05 >> Time before start: 0 steps. Initialization ... >> ... Done. >> No rendering >> No rendering >> No rendering >> No rendering

But when I run the python test_env.py -e bubblemotion-v0 -ep 100 -s 100 it runs correctly and the window with the rendering is shown. but that's not the case using other environments (trunk-v0 or gripper-v0), the terminal shows the same segfault error.

samuelmyoussef commented 1 year ago

Can you try to change render to 0 in test_env.py l.71 and run the trunk env again using the script to see if it's working or not? If it's working correctly, it will be giving the 'no rendering' message similar to the bubblemotion env.

SantiDiazC commented 1 year ago

Thanks for your answer! I changed render on test_env.py to 0 and gives the same error:

########## SIG 11 - SIGSEGV: segfault ########## sofa::helper::BackTrace::sig(int) as before.

The bubblemotion gives no rendering when I run the test code:

import gym import sofagym.envs

env = gym.make('bubblemotion-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() When I run python test_env.py -e bubblemotion-v0 -ep 100 -s 100 it works fine and the rendering is shown:

Selection_004

I think the splib3 problem is solved since BubbleMotionToolbox.py imports it. Do I need to modify something else on the other environments?

maddy-weaver commented 1 year ago

Hi, I am having the same issue, could someone please consolidate these instructions so I could have an easier time getting this running? My issue is when I try to run the example scene it can't find the necessary plugins. I am working in a virtual machine with Ubuntu 20.04 LTS but can set up the machine in any way that is easiest. My goal is to use the SOFA binary and not have to build the SOFA installation, as this also causes errors.

Thanks!

alxbilger commented 11 months ago

@maddy-weaver it should be possible. The instructions in the readme file have been updated recently. Could you read them carefully? Note that a work is in progress to create a conda environment with SOFA and some plugins. It will ease the usage of SOFA. Stay tuned