Inconsistent Static Optimization Results: API vs GUI

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Leon Lo
Posts: 2
Joined: Sun Sep 03, 2023 5:53 am

Inconsistent Static Optimization Results: API vs GUI

Post by Leon Lo » Thu Feb 20, 2025 8:31 am

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 583 times

Tags:

User avatar
Nicos Haralabidis
Posts: 210
Joined: Tue Aug 16, 2016 1:46 am

Re: Inconsistent Static Optimization Results: API vs GUI

Post by Nicos Haralabidis » Mon Feb 24, 2025 11:59 am

Hello Leon!

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

Thanks,

Nicos

User avatar
Leon Lo
Posts: 2
Joined: Sun Sep 03, 2023 5:53 am

Re: Inconsistent Static Optimization Results: API vs GUI

Post by Leon Lo » Tue Feb 25, 2025 2:49 am

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
Attachments
setup_so_py.xml
(5.19 KiB) Downloaded 10 times
IK.mot
(67.16 KiB) Downloaded 9 times
externalloads.xml
(1.76 KiB) Downloaded 9 times
externalloads.mot
(740.63 KiB) Downloaded 9 times
setup_so_gui.xml
(5.16 KiB) Downloaded 9 times

POST REPLY