Modifying MuscleReflex Parameters with SconePy

SCONE is a software tool for predictive simulations of biomechanical movement. It uses OpenSim for modeling and simulation, and performs optimization using various control strategies, including feed-forward control, proprioceptic feedback control, and bal
POST REPLY
User avatar
Mustafa Kamal
Posts: 4
Joined: Tue Apr 30, 2024 3:51 am

Modifying MuscleReflex Parameters with SconePy

Post by Mustafa Kamal » Tue Dec 17, 2024 4:14 am

Hi Thomas,

I am currently using SconePy to run a large number of optimizations. For each optimization, I need to modify specific controller parameters within MuscleReflex (e.g., KL, L0, KF, C0) in the following hierarchy:

GaitStateController --> ConditionalControllers --> ConditionalController --> ReflexController --> MuscleReflex

My question is: is there a way to directly access and modify these parameters using SconePy?

I have tried using the scenario.set() function as demonstrated in the Batch Optimization Tutorial. However, instead of modifying the existing MuscleReflex parameters, it adds a new ConditionalController at the end of the script.

Is there a recommended way to achieve this?

Thank you in advance for your help!

Best regards,
Mustafa

User avatar
Thomas Geijtenbeek
Posts: 473
Joined: Wed Mar 12, 2014 8:08 am

Re: Modifying MuscleReflex Parameters with SconePy

Post by Thomas Geijtenbeek » Tue Dec 17, 2024 8:16 am

In cases where multiple child elements have the same name, you can use the "#n" notation to get the n-th child element.

For example, after loading the "Gait2D - GeyerHerr2010" example, you can use the following code to change the second ConditionalController:

Code: Select all

scenario.set("CmaOptimizer.SimulationObjective.GaitStateController.ConditionalControllers.#2.ReflexController.#1.KF", str(value))
This will set the KF of the first ReflexController in the second ConditionalController.

IMPORTANT: the element you are setting must already exist in the .scone file.

Let me know if this helps!

User avatar
Mustafa Kamal
Posts: 4
Joined: Tue Apr 30, 2024 3:51 am

Re: Modifying MuscleReflex Parameters with SconePy

Post by Mustafa Kamal » Tue Dec 17, 2024 9:47 am

Hi Thomas,

Yes, it worked perfectly, thank you for the clarification!

I was also wondering: is there a way to read or get the parameters using a function in SconePy, similar to how we use scenario.set() to modify them?

I also noticed this functionality is not mentioned in the SconePy documentation. Is there a reason for this, or is it planned to be included in future updates?

Thank you again for your help!

Best regards,
Mustafa

User avatar
Thomas Geijtenbeek
Posts: 473
Joined: Wed Mar 12, 2014 8:08 am

Re: Modifying MuscleReflex Parameters with SconePy

Post by Thomas Geijtenbeek » Fri Dec 20, 2024 9:08 am

The SconePy documentation indeed isn't up-to-date yet, unfortunately. Until then, the best way to see all functionality is via the Python "help" function.

It indeed makes sense to also have a scenario.get() function, so I added it :) Thanks for the suggestion!

It will be available in SCONE 2.4.1, but you can contact me via email if you would like a preview release with this functionality included.

If you have any other suggestions for the SconePy API, please let me know!

POST REPLY