Page 1 of 1
Access Simbody functions like Optimizer through MATLAB API
Posted: Tue Apr 10, 2018 1:02 pm
by adrianlai88
Hi all,
I was wondering if it's possible to access Simbody functions like the Optimizer using the MATLAB API?
I'm trying to run my CMC entirely through MATLAB but I can't seem to find the option where I can alter the optimizer options such as algorithm, max iteration, etc. Yet, these options appear after I print the setup XML file.
Any help will be much appreciated.
Adrian
Re: Access Simbody functions like Optimizer through MATLAB API
Posted: Wed Apr 11, 2018 12:50 pm
by chrisdembia
Unfortunately, the optimizer settings are not exposed in the Matlab API (except for setUseFastTarget()); you would have to do XML editing.
Why do you find it necessary to alter these settings? The defaults have always worked for me.
Re: Access Simbody functions like Optimizer through MATLAB API
Posted: Thu Apr 12, 2018 10:08 am
by adrianlai88
Hi Chris,
Thanks for the reply. I thought it may it the cause of my error when running CMC exclusively in MATLAB.
See the code below. When I run my first instance "Tool2Use.run()", the CMC simulation fails, but if I print the setup file and then reopen it, and then run it, the simulation succeeds. The setup files that were created for both simulations were identical.
Am I missing something in my CMC tools?
Code: Select all
% CMC tools settings
Tool2Use = CMCTool();
Tool2Use.setModel(osimModel);
Tool2Use.setDesiredKinematicsFileName(kin_file);
Tool2Use.setTaskSetFileName(taskset_file);
Tool2Use.setExternalLoadsFileName(external_loads_file);
Tool2Use.setConstraintsFileName(constraints_file);
Tool2Use.setResultsDir(result_folder);
Tool2Use.setReplaceForceSet(0);
force_set = ForceSet(osimModel,actuator_file);
Tool2Use.setForceSetFiles(forceset_file);
Tool2Use.setLowpassCutoffFrequency(low_pass_cutoff);
Tool2Use.setModelFilename(model_file);
% Abstract tools settings
Tool2Use.setOutputPrecision(output_precision);
Tool2Use.setTimeWindow(time_window);
Tool2Use.setUseFastTarget(1);
Tool2Use.setDebugLevel(0);
Tool2Use.setInitialTime(initial_time);
Tool2Use.setFinalTime(final_time);
Tool2Use.setMaximumNumberOfSteps(max_no_steps);
Tool2Use.setMaxDT(max_steps);
Tool2Use.setMinDT(min_steps);
Tool2Use.setErrorTolerance(err_tol);
Tool2Use.addAnalysisSetToModel();
% add analyses to CMC analysis set
abs_tool = AbstractTool.safeDownCast(Tool2Use);
analyses = AnalysisSet.safeDownCast(abs_tool.getAnalysisSet());
analyses.set(0,AnalysisTool);
% Opt_settings = Optimizer();
Tool2Use.print('CMCtool.xml');
% Tool2Use.run()
% Tool2Use.printResults('old','CMC_Results_v2');
% need to print and then reopen setup file
newTool2Use = CMCTool('CMCtool.xml');
% run CMC simulations
newTool2Use.run()
newTool2Use.print('CMCtool_v2.xml');
newTool2Use.printResults('new','CMC_Results_v2');
Re: Access Simbody functions like Optimizer through MATLAB API
Posted: Thu Apr 12, 2018 11:24 am
by chrisdembia
I would continue to use the "print, load, run" workaround. The issue is not likely to be the optimizer settings. The interface for the tools has not been well-tested for programmatically adjusting the tool settings.
Re: Access Simbody functions like Optimizer through MATLAB API
Posted: Thu Apr 12, 2018 5:28 pm
by adrianlai88
Cool thanks Chris!