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
Access Simbody functions like Optimizer through MATLAB API
- Adrian Lai
- Posts: 46
- Joined: Tue Mar 13, 2012 11:33 am
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Access Simbody functions like Optimizer through MATLAB API
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.
Why do you find it necessary to alter these settings? The defaults have always worked for me.
- Adrian Lai
- Posts: 46
- Joined: Tue Mar 13, 2012 11:33 am
Re: Access Simbody functions like Optimizer through MATLAB API
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?
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');
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Access Simbody functions like Optimizer through MATLAB API
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.
- Adrian Lai
- Posts: 46
- Joined: Tue Mar 13, 2012 11:33 am
Re: Access Simbody functions like Optimizer through MATLAB API
Cool thanks Chris!