Page 1 of 1

Inconsistent Static Optimization Results: API vs GUI

Posted: Thu Feb 20, 2025 8:31 am
by leonlo
Description
When running static optimization through the Python API, the results differ from those obtained through the GUI interface, despite identical setup files. The GUI output appears to have smoothing applied, while the API output does not.

Additional Information
- Python version (via conda): opensim 4.5.1
- GUI version: OpenSim 4.5
- OS: Windows 11 & MacOs Sequoia
- Lowpass cutoff frequency is identical in the setup files

Questions
- Is there a hidden smoothing parameter in the GUI that's not exposed in the API?
- Is there something wrong with my code implementation or am I missing any required steps/parameters?

Code: Select all

(...)
 #Create the AnalyzeTool
    analyze_tool = osim.AnalyzeTool()
    analyze_tool.setModel(model)
    analyze_tool.setStatesFromMotion(state, coordinates_file_sto, True)
    analyze_tool.setStartTime(coordinates_file_sto.getFirstTime())
    analyze_tool.setFinalTime(coordinates_file_sto.getLastTime())
    analyze_tool.setReplaceForceSet(False)
    analyze_tool.setSolveForEquilibrium(False)
   
   # Initialize the StaticOptimization
    static_opt = osim.StaticOptimization()
    static_opt.setName("StaticOptimization")
    static_opt.setUseModelForceSet(True)
    static_opt.setStartTime(coordinates_file_sto.getFirstTime())
    static_opt.setEndTime(coordinates_file_sto.getLastTime())

    #analyze
    analysis_set = analyze_tool.getAnalysisSet()
    analysis_set.cloneAndAppend(static_opt)
    analyze_tool.addAnalysisSetToModel()
    analyze_tool.setCoordinatesFileName(coordinates_file)
    analyze_tool.setExternalLoadsFileName(external_loads_file)
    analyze_tool.setForceSetFiles(actuators)

    # Save setup and results
    analyze_tool.setResultsDir(results_directory)
    analyze_tool.printToXML(os.path.join(folder, "setup_so.xml"))

    analyze_tool.run()
output.png
output.png (46.1 KiB) Viewed 582 times

Re: Inconsistent Static Optimization Results: API vs GUI

Posted: Mon Feb 24, 2025 11:59 am
by nicos1993
Hello Leon!

Could you share your files etc? I will try to reproduce.

Thanks,

Nicos

Re: Inconsistent Static Optimization Results: API vs GUI

Posted: Tue Feb 25, 2025 2:49 am
by leonlo
Hello Nicos,

yes of course. I have attached all files I used in the analysis.

coordinate_file = IK.mot
coordinate_file_sto = osim.Storage(coordinate_file)
external_loads_file = externalloads.xml
actuators_file = actuators_so.xml

Additionally, I discovered when setting the lowpass cutoff frequency in python (*), the results do not change in comparison to omitting that line of code.

* analyze_tool.setLowpassCutoffFrequency(6)

Thank you in advance,

Leon