Unable to erase _states.sto file - causes Matlab crash

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Lucas Moreno Carbonell
Posts: 2
Joined: Tue Mar 07, 2023 2:18 am

Unable to erase _states.sto file - causes Matlab crash

Post by Lucas Moreno Carbonell » Wed May 17, 2023 2:13 am

Hello,

I am trying to run mutliple successive CMC computations on the Matlab2019b API of OpenSim 4.4.
I have noticed that once a _ state.sto file has been created, it is impossible to overwrite it or delete it as long as Matlab is still open (allthough the shell is done running the script). Additionally, trying to remove this file by any mean causes Matlab to crash.
My teammate's guess is that something is still running in the background, with a file id pointing towards the _ state.sto file. I have been looking for a way to terminate this process by calling methods such as cmc.delete() or model.disownAllComponents() at the end of my script, none of which seem to be working.

Here is a script I wrote to adresse this specific issue.

Code: Select all

import org.opensim.modeling.*;

resultsDir = 'SetupMoka/CMC_res';

% Model
disp('    Model: Setup ........ START');
model = Model('SetupMoka/subject01_simbody_adjusted.osim');
force_set = ForceSet('SetupMoka/gait2354_CMC_Actuators.xml',true);
for i = 0:1:force_set.getSize()-1 
    model.updForceSet().append(force_set.get(i));
end
state = model.initSystem();
disp('    Model: Setup .......... DONE');

% CMCTool
cmc = CMCTool();
cmc.setName(num2str(1));
cmc.setModel(model);
mkdir(['SetupMoka/CMC_res/' num2str(1)]);
iterResultsDir = [resultsDir '/' num2str(1)];
cmc.setResultsDir(iterResultsDir);
cmc.setInitialTime(0.6-0.03);
cmc.setFinalTime(0.6+0.01);
cmc.setExternalLoadsFileName('SetupMoka/subject01_walk1_grf.xml');
cmc.setDesiredKinematicsFileName('SetupMoka/IK_res/subject01_walk1_ik.mot');
cmc.setTaskSetFileName('SetupMoka/gait2354_CMC_Tasks.xml');
cmc.setConstraintsFileName('SetupMoka/gait2354_CMC_ControlConstraints.xml');
cmc.setUseVerbosePrinting(true);
disp(['CMC ' num2str(1) ': Setting up the tool........ DONE']);

% Computing CMC Solution
disp(['CMC ' num2str(1) ': Computing solution........ START']);
res = cmc.run();
if ~res
    warning(['CMC ' num2str(1) ' Error(s) occured while computing a solution. Check opensim.log']);
else
    disp(['CMC ' num2str(1) ': Computing solution........ DONE']);
end

% Delete tools
model.disownAllComponents()
disp model.disownAllComponents

model.delete
cmc.delete
force_set.delete

% Remove folder
rmdir('SetupMoka/CMC_res','s');
Running this returns the following error and causes Matlab to crash without sending a report a few minutes later :

Code: Select all

Error using rmdir
H:\CL_orthosis_simulation\tests_succ_cmc\SetupMoka\CMC_res\1\1_states.sto could not be removed.
H:\CL_orthosis_simulation\tests_succ_cmc\SetupMoka\CMC_res\1 could not be removed.
H:\CL_orthosis_simulation\tests_succ_cmc\SetupMoka\CMC_res could not be removed.


Error in test (line 49)
rmdir('SetupMoka/CMC_res','s');
The initial and final time of the simulation are very close on purpose, I don't believe this is the problem anyway.


Perhaps someone else has had a similar problem ?

Thank you in advance for your help,

Lucas

Tags:

POST REPLY