-
Notifications
You must be signed in to change notification settings - Fork 23
Enables caching of the compiled code if tmp_dir is set. #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes csu-hmc#107 A hash of the unique evaluation code is stored in its C file and the files present in the tmp_dir are checked to see if they contain the hash. If one does, then that compiled module is loaded if possible. This saves having to recompile the C code if the differential algebraic equations passed to Problem or ConstraintCollocator have not changed.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I manually tested some with the gait2d model and the Jacobian function which has about 4000 subexpressions seems to generate different hash sometimes, i.e. it doesn't seem deterministic. |
|
Maybe our _forward_jacobian function is not deterministic. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Maybe it would be deterministic if I hash the SymPy equations of motion: EDIT: hash() is probably not repeatable across new interpreters. |
|
The generated code for the Jacobian has slight differences, maybe in the ordering of the subexpressions: $ diff --color codegen/ufuncify_matrix_1_c.c codegen/ufuncify_matrix_3_c.c
1c1
< // opty_code_hash=3fc4ac84638576bd605a5b8df0c14c2caf3301beb7b6bdd514f5301dfcdfc966
---
> // opty_code_hash=0144e43378d3a13238d5bfacb371d6d8a917688d8992924fbcd900ddb150f83f
4c4
< #include "ufuncify_matrix_1_h.h"
---
> #include "ufuncify_matrix_3_h.h"
554,556c554,556
< double z1171_ = mc_ + md_;
< double z1176_ = mb_*xb_*z802_ - mb_*yb_*z824_ + mc_*z1111_ + md_*z1124_ + z1169_*z1171_;
< double z1177_ = mb_*xb_*z803_ - mb_*yb_*z825_ + mc_*z1112_ + md_*z1125_ + z1170_*z1171_;
---
> double z1172_ = mc_ + md_;
> double z1176_ = mb_*xb_*z802_ - mb_*yb_*z824_ + mc_*z1111_ + md_*z1124_ + z1169_*z1172_;
> double z1177_ = mb_*xb_*z803_ - mb_*yb_*z825_ + mc_*z1112_ + md_*z1125_ + z1170_*z1172_;
561,563c561,563
< double z1201_ = mf_ + mg_;
< double z1205_ = me_*xe_*z818_ - me_*ye_*z830_ + mf_*z1141_ + mg_*z1154_ + z1198_*z1201_;
< double z1206_ = me_*xe_*z819_ - me_*ye_*z831_ + mf_*z1142_ + mg_*z1155_ + z1199_*z1201_;
---
> double z1200_ = mf_ + mg_;
> double z1205_ = me_*xe_*z818_ - me_*ye_*z830_ + mf_*z1141_ + mg_*z1154_ + z1198_*z1200_;
> double z1206_ = me_*xe_*z819_ - me_*ye_*z831_ + mf_*z1142_ + mg_*z1155_ + z1199_*z1200_; |
|
cse has this kwarg but we are just using the default: |
|
I think the only unit test I can write for this is to run Problem twice with tmp_dir and make sure only two sets of Cython files are ecreated. It is difficult to test anything else given that it falls back to compiling. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I get this error on the path test: I'm confused why it says False = <function... |
|
The issue is that in the pytest runs the module counter has already been advanced: |
|
Over in gait-closed-loop-id I'm getting a failed to import even though it finds a match: |
|
Interesting if I open IPython and |
|
I also tried |
|
|
|
Maybe ipython does something different with the working directory: https://stackoverflow.com/questions/77767321/importing-module-works-with-ipython-but-it-doesnt-if-im-not-using-ipython |
|
Interesting I have the opposite result here: #109 (comment) |
Fixes #107
A hash of the unique evaluation code is stored in its C file and the files present in the tmp_dir are checked to see if they contain the hash. If one does, then that compiled module is loaded if possible. This saves having to recompile the C code if the differential algebraic equations passed to Problem or ConstraintCollocator have not changed.
TODO:
Include it in an example that has more than one execution of Problem.can add later with human gait update