@rwightman Thanks for your reply.
When you mention to “implement that loop in C or C++”, do you mean purely C++ running on CPU or using the torch C++ frontend on GPU? If the answer is the latter,  I totally agree a C++ will be faster than python running on the CPU, but since I have not tried the torch C++ frontend, I am not sure whether an implementation of the controller using it will have a significant impact on execution speed on the GPU.
About Python,  I simply wanted to try. I am used to it for machine learning and also have seen some use cases for pytorch+python on optimal control (and general optimization) with interesting results. Nonetheless, optimization sees benefits on Pytorch thanks to automatic differentiation. Also, coming from a C background, coding in Python is much easier.