csu-hmc / opty

A library for using direct collocation in the optimization of dynamic systems.
http://opty.readthedocs.io
Other
86 stars 20 forks source link

Use pycompilation if installed. #109

Open moorepants opened 10 months ago

moorepants commented 10 months ago

The pycompilation caching seems to work. On the problem in https://github.com/brocksam/muscle-driven-bicycle-paper if I run the optimal control script twice in a row, the second run takes no time for the compilation step taking total time to instantiate the problem from 180 seconds to 54 seconds (approximately).

I did notice that if I open IPython and run the script twice in a row that the cached compilation did not seem to load (always took 180 seconds to complete). Not sure why.

moorepants commented 10 months ago

To clarify:

python ocp.py
python ocp.py

shows the speed up on the second run but:

$ ipython
run ocp.py
run ocp.py

didn't.

moorepants commented 9 months ago

Bjorn pointed out to me that a version of pycompilation is in sympy/utilities/_compilation.

I have it working but I don't know if it caches the compiled code.

moorepants commented 9 months ago

In the sympy version the import_module_from_file has a kwarg only_if_newer_than. It may be a way to import an old complied version if some dependent files haven't changed.

moorepants commented 1 month ago

SymPy includes pycompilation (private modules), so we could just use it from SymPy instead of the standalone package.