-
Notifications
You must be signed in to change notification settings - Fork 306
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
Python/Matlab examples for using the tools #2076
Comments
Such examples would be great. @jimmyDunne worked on a utility script for appending reserve actuators. #2060 is related. |
@chrisdembia it seems that a lot of documentation is located in the .cpp files, it would be nice if these can be accessed in the doxygen. |
Yes we've discussed that a lot. Over time a lot of the documentation in the cpp files has become less than correct, and we think that incorrect documentation is worse than no documentation. We definitely want to move the comments from the cpp files to the headers, but they documentation should be corrected in the process. |
Continuing our discussion, here are some comments for using the AnalyzeTool. This is how I managed to initiate the SO (v3.3) after a lot of effort:
From a user perspective the https://github.com/opensim-org/opensim-core/blob/master/OpenSim/Tools/AnalyzeTool.cpp#L531 so the user can't pass the https://github.com/opensim-org/opensim-core/blob/master/OpenSim/Tools/AnalyzeTool.cpp#L91 Another problem is the motion vs state input. If the coordinates are specified from a .mot file (e.g. IK) then the https://github.com/opensim-org/opensim-core/blob/master/OpenSim/Tools/AnalyzeTool.cpp#L540 The tools are an important part of the API, especially with the python and java wrappings. I suggest that the API is refined based on use cases so as to permit easy initialization and invocation, without restricting to the xml approach alone. |
Thanks @mitkof6; those are all good points. The documentation for |
Hi, Two more comments.
Windows: access violation - no rtti data Archlinux: Python segmentation fault (core dumped)
When I comment Furthermore, PS: you can use the file from the gait model to try and reproduce this error. |
@romainmartinez yes it seems so. You can try to verify this if you have time so we can be 100% sure. |
When I perform batch joint reaction analysis the RAM is constantly increasing so I have to close python and re-run the batch from where it stopped. Is this a python side effect or some memory leak? This is my code:
and the batch loop
|
@mitkof6 did you find a solution to this? Im finding the same problem. I'm even running my batch processing using python subprocess so that I am calling a script that does my JR analysis (and all steps leading up to it) and once it's done that entire script should be closed, running the next batch in a separate python subprocess. I would think that ending the script should release that memory, but it doesnt seem to be the case. A related quirk I've noticed is that killing a python script that is running an opensim analysis doesnt kill the opensim analysis - it keeps running in the background (shown as a python process), even though the python script is closed on the command line. In System Monitor, there is still a python process that is running and taking up memory. For the killed python script, it seems to take up memory and CPU resources until the opensim analysis is done (I cant know this for sure, but the time it takes to release makes this seem plausible), and then it gets released. Im wondering if part of the batch processing problem is that there are still some latent C++ processes being run by opensim that if given some more time before starting the next loop might release that memory. But when not given the time, they just keep piling on. I say this because of the fact that killing a python script running an opensim analysis eventually does release the memory, it just doesnt do so until everything from the underlying C++ code that had been initiated is done. Sorry, that's a lot of info/ideas. Im not a computer scientist, so these ideas could be out to left field. Hopefully this is helpful in some way. sudo code example of the python script running subprocesses:
|
Just to clarify, I was talking about the memory issue mentioned for batch processing... sorry, I didn't say that explicitly :). |
Hi @gattia, Unfortunately, I haven't resolved this issue. It might be a memory leak in the joint reaction tool or anywhere else. I have to close the python process each time to free the memory. |
@mitkof6 thanks for the response. I've done some more playing and realized that what I mentioned in my post (using subprocess to call a second python script that performs the analysis) actually does work. It's a bit of a hack, and doesnt solve the underlying problem, but if you are running into memory issues, it might be of interest. In the event that you are interested in this solution, I've tried to briefly describe what I've done, and the advantages to it below. I am performing batch processing for participants as well as trials within participants. In the code block I had in my previous comment, the opensim_batch.py batch processes trials for an individual participant and this slowly accumulates memory. However, because each participant is called independently using the subprocess module from another python script it releases memory after completing every participant. Using subprocess in this way is nice because depending on how much RAM and CPU compute you have, you can actually run multiple instances of this at the base script at the same time, effectively getting parallel computation of many analyses - I'm finding that opensim essentially maxes out one thread, so I could in theory run in parallel 2x the number of cores on my machine, or 2xnumber of cores-1 if you want to leave something available for other processes. In addition, you could also extend what I've mentioned so each individual trial, as well as participant, is processed in a subprocess, and this should completely eliminate the memory accumulation. |
Could you guys provide a minimal C++ example to reproduce the issue so we can find out if this is Bindings (python, Matlab) specific or if it can be fixed for all use cases? Thanks |
@mitkof6 ExternalLoads had undergone refactoring before 4.0 release so your comment above may or maynot apply now. Just a headsup. |
Sorry, I have zero experience with C++, otherwise I'd be happy to help out. In case it helps, my current version of opensim was built using this commit The for loop I run is very similar to that described by @mitkof6, except I include IK in my loop as well. I essentially run from line 35 this script and onwards in a loop |
I could try creating a self-contained minimal example in python using some of the opensim example data if that will help someone else re-create in C++. |
Thanks @gattia yes, that would be awesome, a minimal example in any language would be a great first step 👍 |
@aymanhab I've uploaded a repository that includes some of the example gait data and tests accumulation of memory for batch processing. It records the memory accumulated after every loop for each of IK, ID, SO, and JR. I've included in the README examples of the resulsts printed from the script - these results are the average memory accumulated per loop (20 loops). For the example data I have, it seems that SO is the biggest culprit (40MB/loop), but all of them seem to accumulate at least a little memory. |
@aymanhab I have prepared a project that reproduces this behavior as part of a demo for TGCS. Currently, only Linux is supported because I have problems porting gmp library for Windows (not tested on Mac). I am working on a Windows version. You will have to build the C++ source code and run CalculateFeasibleMuscleForces first. Then to reproduce this behavior run the
If you open a task manager or system monitor, you will observe that the RAM constantly increases with each iteration. |
@mitkof6 I have a similar problem in running CMC in Matlab did you found a solution? Here is my code.
@chrisdembia I can not change the "force data file" directory by using |
If the set external force does not work, then you should write the external loads setup file and use the
Please note that if you use OpenSim v3.3 you should use ForceSet instead of SetForce. Keep in mind that the setForceSetFile might be ignored if called in wrong order. |
Thank you so much for sharing that, @mitkof6 ! |
@mitkof6 Thank you. It solved based on your idea, except I changed
|
I find it a little bit difficult to setup the AnalyzeTool without the .xml file (through the API). It would be great if examples are provided (especially for Python and Matlab users) that demonstrate the simulation pipelines (e.g. gait2354, SO, IK, ID, JRA, etc.). Something like this: IK.
For example, it isn't very intuitive how to append reserve actuators and how to add different analysis. The doxygen is a little bit vague and does not explain the meaning of some functions and how to use them.
The text was updated successfully, but these errors were encountered: