-
Notifications
You must be signed in to change notification settings - Fork 117
[feat] Make hook-related machinery available as class directives #1969
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
|
Hello @jjotero, Thank you for updating! Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide Comment last updated at 2021-06-07 08:19:44 UTC |
Codecov Report
@@ Coverage Diff @@
## master #1969 +/- ##
==========================================
- Coverage 87.61% 87.46% -0.16%
==========================================
Files 50 50
Lines 8788 8850 +62
==========================================
+ Hits 7700 7741 +41
- Misses 1088 1109 +21
Continue to review full report at Codecov.
|
|
@jjotero, I am not sure how this feature will evolve or be utilized... So, what's the other benefit of this feature? Furthermore, I agree that the syntactic-sugar syntax is required. And I wonder if, in the simplified form, there could be an implicit from handy_hooks import ext_fn
class MyTest(rfm.RegressionTest):
pre_compile(bind(ext_fn))
post_run(bind(ext_fn, name='new_name'))one could write from handy_hooks import ext_fn
class MyTest(rfm.RegressionTest):
pre_compile(ext_fn)
post_run(ext_fn, name='new_name') |
In the gpu microbenchmarks, the There is quite a lot of room at the Regarding the syntax, I agree that binding an external hook doing class MyTest(rfm.RegressionTest):
run_before('compile')(bind(ext_fn, name='local_fn'))is perhaps worse than a manual bind such as class MyTest(rfm.RegressionTest):
@run_before('compile')
def local_fn(self):
ext_fn(self)So that's why I think that the least we should do here is expose the from handy_hooks import ext_fn
class MyTest(rfm.RegressionTest):
pre_compile(bind(ext_fn))
post_run(bind(ext_fn, name='new_name'))If you want to go further and make the from handy_hooks import ext_fn
class MyTest(rfm.RegressionTest):
inject_before_compile(ext_fn)
inject_after_run(ext_fn, name='new_name'))or instead from handy_hooks import ext_fn
class MyTest(rfm.RegressionTest):
inject_before('compile', ext_fn)
inject_after('run', ext_fn, name='new_name')) |
|
Here's another and perhaps a bit of a different use-case. Look at the from hpctestlib.utils.topo import get_sibling_cpus
@rfm.simple_test
class MyTest(rfm.RegressionTest):
...
bind(get_sibling_cpus)
@run_before('run')
def get_logical_cpus_per_core(self):
self.num_cpus_per_core = len(self.get_sibling_cpus(0, by='core')) |
|
I personally see the value of this proposal in this PR. Here are my general comments:
|
|
That's why there is the more verbose option to define a function and decorate it. I don't see the point in exposing the hooks as |
Meanwhile, we need to deprecate it since 3.7.0, I guess. |
Done I've also intercepted all these directives to not make their way into the class and the instance, since something like |
|
I think there is sth wrong with this PR git-wise. I see 67 files changed 🤔 |
|
@vkarak I've updated all the |
|
Oh, I see! No, keep it, because we don't want tons of deprecation warnings. We already have enough with the |
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm in general, but I don't see unit tests for the new functionality introduced:
- The
bind()function - Removal of the blacklisted directives after the class is created.
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a couple of minor comments.
|
Implementation-wise, I'm still not 100% happy that the file |
|
I feel this now looks a lot better. The backend |
vkarak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, except the documentation needs a little bit of fine-tuning. Also the fact that the run_before etc. docs are in three places. I am working on that.
- Remove duplicate documentation; use pointers in the code to the actual user documentation. - Move pipeline hooks section under the builtins. - Add a warning box for the deprecation of former syntax.
|
@jjotero I've fine tuned the documentation as follows:
If you agree with the changes, I am ready to merge it. |
Yeah, docs look far cleaner now. I've also made the parameters and variables to show as |
This PR builds on #1929 to simplify and improve the syntax when writing test libraries. The
run_before,run_afterandrequire_depsdecorators are now available as class directives, so there is no need for the precedingrfm.anymore:This PR also introduces the
binddirective, which binds an external function with the regression test class. This allows to write pipeline hooks as standalone unary functions, which can then be safely "imported" by several other classes.Not using the bind directive here might lead to problems because the function object
ext_fnwould be shared by multiple classes.Issues with the current implementation
By moving these directives into the
reframe/core/hooks.pyI feel that the mapping of the argument to therun_beforeandrun_aftershould be done in the metaclass and not by any of the functions in thehooks.pyfile. It's a bit strange to me that these hook functions are aware of the pipeline stages. It would feel a lot more natural if the directives exposed by the metaclass would preprocess this argument and do the mapping before calling any of the functions inhooks.py.Alternatively, we could add some syntactic sugar into this and get rid of the mapping problem altogether by exposing directives to the
pre_andpost_steps of each individual pipeline stage. IMO, this would vastly improve the syntax above: