Opensim memory leak during for loop

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mohsen Sharifi Renani
Posts: 7
Joined: Thu Apr 12, 2018 1:00 pm

Opensim memory leak during for loop

Post by Mohsen Sharifi Renani » Thu Dec 03, 2020 9:05 pm

Hi,
I'm trying to run a for loop over a OpenSim analyze tool in python. I have to run over 100000 kinematic instances with the analyzing tool, but after 1000 instances the memory will be filled and my script is crashed. Is there any way we to resolve the issue? I tried to del the create osim.AnlayzeTool after each instance but it did not work!

The memory keep increasing linearly after each iteration.
[/code]
def run_analyze(self, ik_file, analyze_result_folder):
self.analyzeTool = osim.AnalyzeTool(self.analyze_setup_file)
motCoordsData = osim.Storage(ik_file)
initial_time = motCoordsData.getFirstTime()
final_time = motCoordsData.getLastTime()
start = [i for i, c in enumerate(ik_file) if c=='/'][-1]+1
name = ik_file[start:][:-4]
self.analyzeTool.setName(name)
self.analyzeTool.setModelFilename(self.model)
self.analyzeTool.setResultsDir(analyze_result_folder)
self.analyzeTool.setCoordinatesFileName(ik_file)
self.analyzeTool.setInitialTime(initial_time)
self.analyzeTool.setFinalTime(final_time)
self.analyzeTool.setLowpassCutoffFrequency(6)
analysis_set = self.analyzeTool.getAnalysisSet()
nAnalysis = analysis_set.getSize()
for k in range(nAnalysis - 1):
analysis = analysis_set.get(k)
analysis.setStartTime(initial_time)
analysis.setEndTime(final_time)
self.analyzeTool.run()
del self.analyzeTool
For i in range(100000):
...
...
do run_analyze()

Code: Select all


Thanks for your help in advance.
Mohsen

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Opensim memory leak during for loop

Post by Dimitar Stanev » Sat Dec 05, 2020 11:45 am

Hi Mohsen,

Maybe if you build the new version of OpenSim, where we fixed a memory leak ([1] and [2]) in the integrator, this might be resolved.

[1] https://github.com/opensim-org/opensim-core/issues/2865
[2] https://github.com/opensim-org/opensim-core/issues/2865

But this is not a guarantee. Maybe there is another memory leak in the analysis tool. I had similar issues in the past. What I did was to kill the Python process and start over from where the analysis stoped. It is not ideal.

POST REPLY