Biomechanical Optimization with SymPy 1.13 and Opty 1.3


SymPy 1.13 was released on July 8, 2024. This release includes all of the work we did under the CZI Open Source Software for Science Cycle 4 grant. For example, SymPy now includes new features for modeling biomechanical multibody systems. The new features include model construction from joints via a system manager and force actuator classes including a musculo-tendon model. At the close of the grant period, we demonstrated how these features can be used in the solution of biomechanical trajectory optimization and parameter estimation optimal control problems, but only from development branches of the various intertwined software packages. Today, we released Opty 1.3 which can now be used alongside SymPy 1.13 to solve biomechanical optimal control problems. Opty can now handle symbolic equations of motion that have many millions of mathematical operations and tens of thousands of constraints and optimization variables. To help grow adoption, we've built out a new example gallery that demonstrates how Opty can be used to solve a variety of problems:

Opty 1.3's new example gallery.

One example in the gallery, the "One-Legged Cycling Time Trial", shows how to find an optimal control solution of a musculo-tendon driven model that makes use of SymPy 1.13's new biomechanics features. We developed this example for an activity in TU Delft's 2024 Sports Engineering course to show the students how models can be used to study how muscles play a role in optimal performance. The example solves a minimum time cycling race using a model of a single leg and simplified muscles that drive the leg motion to propel the bicycle. The example in the gallery is set up with a short race distance but if you bump the distance up to 80 meters the cyclist starts approaching terminal velocity. Opty can find an optimal solution for the 17,000 variables in this problem in about 10 minutes on an AMD Ryzen 5 2600X 12 core machine.

This produces a reasonably realistic overall motion which can be seen in the cadence, resulting speed, and the power to accelerate and overcome rolling and air resistance:

There is no limit on the fatigue of the muscles so the optimizer finds a bang-bang style coordination of the muscle excitations to power the leg and push the muscles to their maximum force production:

The four muscle forces, muscle lengths, and muscle excitations versus time during the 80 meter time trial with the minimum race time shown at the top.

This solution results in this overall pedaling motion:

Our next step is to incorporate muscles in our 3D nonlinear bicycle-rider models to enable deeper understanding of how bicycles are balanced and controlled. Opty can quickly find optimal trajectories of the joint torque driven model, as shown in our BRiM paper:

Torque driven Opty optimal control solution for the non-linear Carvallo-Whipple bicycle model.

Thanks to Timo, Sam, Peter, and all the SymPy developers for the contributions that helped pull all this together! We hope that others can make use of these models and tools for their own work.