opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
801 stars 324 forks source link

OpenSim 4.5.1 - error when running consecutive Analyze #3904

Closed katya-stanzy closed 1 month ago

katya-stanzy commented 2 months ago

This question is related to this post on the OpenSim forum.


Hello,

I am using OpenSim with Python. Previousely, I was able to run several Static Optimization analyses using the Analyze tool consecutively. It is no longer possible in the new OpenSim 4.5 Python package. When moving on to the next trial, the Kernel crashes with the following error:

"SWIG director method error. Error detected when calling 'LogSink.sinkImpl''

Is it a known problem? Does a fix exist?

Repeat_SO_Failure_Python.zip

mrrezaie commented 2 months ago

Hi @katya-stanzy, I just tested your files in IPython console (.py rather than .ipynb) and it worked. Perhaps something is wrong with the way you use opensim Logger and Jupyter Notebook. These two lines would be sufficient if you want to keep the logs in separate files. Could you try commenting out the other lines related to the Logger?

osim.Logger.removeFileSink()
osim.Logger.addFileSink(PATH_TO_LOG_FILE)

Also, just a couple of points:

  1. I noticed that the Performance and Constraint violation values are huge. So, I checked your external force files and found that the bodies the forces are applied to are not defined correctly. You need to swap the calcn_r and calcn_l bodies.
  2. You may also need to adjust your actuator file. Since you are using IK output, you need strong residual actuators, strong reserve actuators for free coordinates without muscles, and weak reserve actuators for free coordinates spanned by muscles.

Hope this helps.

katya-stanzy commented 2 months ago

Hi, mrrezaie - yes, you are absolutely right. The log script was the issue -- sorry for ever doubting OpenSim! Also thank you for pointing out the large errors in SO solutions for that data, I found a silly bug in my script for feet determination almost immediately.

aymanhab commented 2 months ago

Outstanding work @mrrezaie 👏 I will leave this issue open until we can scope the logger issue, and if it is specific to the fileSink calls in ipynb

aymanhab commented 1 month ago

There's no need to subclass across the interface between c++ and python when we provide methods specifically to add/remove FileSink that work as demonstrated by @mrrezaie