Error when running AnalyzeTool using Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Riza Bayoglu
Posts: 26
Joined: Wed Aug 02, 2023 8:54 am

Error when running AnalyzeTool using Python

Post by Riza Bayoglu » Thu Sep 19, 2024 6:05 am

I was able to run static optimization using the AnalyzeTool with Python up until two weeks ago. But now the kernel crashes when I start my simulations. I did not change anything in my scripts and could not find why it does not work anymore. Below is the output I am seeing:

Code: Select all

[info] Loaded model MaleFullBodyModel_v2.0_OS4 from file Model.osim
[info] AbstractTool NMB loading model Model.osim
[info] Loaded model MaleFullBodyModel_v2.0_OS4 from file Model.osim
[info] Adding force object set from Model_Actuators.xml
[info] ExternalLoads 'HandForces' was renamed and is being reset to 'externalloads'.
[info] Storage: read data file = NMB_ExternalForce1.mot (nr=11 nc=25)
[info] ExternalForce::HandForce_R Data source being set to NMB_ExternalForce1
[info] ExternalForce::HandForce_L Data source being set to NMB_ExternalForce1
[info] Loading coordinates from file 'motion_file.mot'.
[info] Storage: read data file = motion_file.mot (nr=11 nc=151)
[warning] Model::formCompleteStorages():  Did not find column /jointset/ground_pelvis/pelvis_rotation/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ground_pelvis/pelvis_list/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ground_pelvis/pelvis_tx/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ground_pelvis/pelvis_ty/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ground_pelvis/pelvis_tz/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_r/hip_flexion_r/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_r/hip_adduction_r/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_r/hip_rotation_r/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/knee_r/knee_angle_r/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ankle_r/ankle_angle_r/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_l/hip_flexion_l/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_l/hip_adduction_l/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/hip_l/hip_rotation_l/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/knee_l/knee_angle_l/value in storage object.
[warning] Model::formCompleteStorages():  Did not find column /jointset/ankle_l/ankle_angle_l/value in storage object.
[info] Found 11 state vectors with time stamps ranging from 0.0 to 1.0.
[info] Executing the analyses from 0.0 to 0.0...
[info] Storage: read data file = NMB_ExternalForce1.mot (nr=11 nc=25)
[info] ExternalForce::HandForce_R Data source being set to NMB_ExternalForce1
[info] ExternalForce::HandForce_L Data source being set to NMB_ExternalForce1
[info] Storage: read data file = NMB_ExternalForce1.mot (nr=11 nc=25)
[info] ExternalForce::HandForce_R Data source being set to NMB_ExternalForce1
[info] ExternalForce::HandForce_L Data source being set to NMB_ExternalForce1

The kernel died, restarting...
----
I am using OpenSim (version 4.4 with Python 3.10, np121) with Spyder running on conda 24.5.0 on Windows OS. Things I tried to find the issue:

1. Tested PyCharm and Jupyter Notebook as the IDE. Same error.
2. Tested with the latest version of conda and OpenSim 4.5.1. Same error.
3. Tested directly in OpenSim software, and it is working there.
4. Created a minimal working example, attached here. Main.py file is the main file.

My colleague is running into the same issue. Could someone help me please?

This is my main file:

Code: Select all

#%%

def static_optimization(input_model, mot):

  import opensim as osim

  model     = osim.Model(input_model)                
  actuators = osim.ForceSet('Model_Actuators.xml')
  forceset  = model.updForceSet()
  
  for i in range(0, actuators.getSize() -1):
              
      forceset.cloneAndAppend(actuators.get(i))
      
      analyze_tool = osim.AnalyzeTool('staticOpt_Setup_Minimum.xml')
      analyze_tool.setModel(model)
      analyze_tool.setStartTime(0)
      analyze_tool.setFinalTime(0)  
      analyze_tool.setCoordinatesFileName(mot)      
      state  = model.initSystem()
      analyze_tool.run()            
    
#%%    
    
static_optimization('Model.osim', 'motion_file.mot')	

Here is the download link to the minimal working example: https://www.dropbox.com/s/0hdmo5ym9brap ... e.zip?dl=0

Tags:

User avatar
Mohammadreza Rezaie
Posts: 407
Joined: Fri Nov 24, 2017 12:48 am

Re: Error when running AnalyzeTool using Python

Post by Mohammadreza Rezaie » Fri Sep 20, 2024 12:31 am

Hi, I just tested your minimum working example in IPython console (py10, osim4.5.1), and it works. Your motion seems to be a static pose, and I think that's why you set the final time to zero as well. The warnings suggest that the motion file doesn't contain all coordinates. Some people have reported similar issue when running AnalyzeTool in API on the forum, and they found this workaround:

Code: Select all

analyze_tool.printToXML('test.xml')
analyze_tool = osim.AnalyzeTool('test.xml')
analyze_tool.run()
Hope this helps.

User avatar
Riza Bayoglu
Posts: 26
Joined: Wed Aug 02, 2023 8:54 am

Re: Error when running AnalyzeTool using Python

Post by Riza Bayoglu » Mon Sep 23, 2024 4:34 am

Thank you Mohammedreza! I previously tried that piece of code, but it did not fix the issue. However, I am now able to run my simulations after I installed the same conda package configuration as another colleague of mine. At least it works when running with Jupyter Notebook. I don't know what exactly caused the problem, but it seemed like a package issue.

POST REPLY