-
Notifications
You must be signed in to change notification settings - Fork 517
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
Add utility methods to HierarchicalTimer #2651
Conversation
Codecov ReportBase: 87.03% // Head: 87.03% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2651 +/- ##
=======================================
Coverage 87.03% 87.03%
=======================================
Files 754 754
Lines 84051 84087 +36
=======================================
+ Hits 73151 73185 +34
- Misses 10900 10902 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
This is a neat addition to the timing utility.
If we had a # Clear __init__
timer.get_timer_from_string("root.__init__").clear_except()
# Clear solve_nlp
timer.get_timer_from_string("root.set_inputs.set_parameters.solve.solve_nlp").clear_except()
# Flatten
timer.get_timer_from_string("root.set_inputs").flatten()
# Clear set_inputs except for solve_nlp
timer.get_timer_from_string("root.set_inputs").clear_except("solve_nlp") This would require some naming convention where the "base name" of a timer is required not to have a period in it, however. |
Fixes most of #2503
Summary/Motivation:
I am using
HierarchicalTimer
to collect fairly detailed timing information inExternalPyomoModel
, and when comparing different configurations, I sometimes want to highlight different timing categories. I want to do this by (a) removing redundant information from the timer and (b) flattening the timer so that categories I care about are easy to compare.For example, I would like to convert the first timer shown into the second timer shown for the purpose of comparing the amount of time spent in NLP Newton solvers.
With the changes proposed in this PR, I can do this with the following few lines:
Changes proposed in this PR:
flatten
method toHierarchicalTimer
. This recursively flattens the "child timers" into a single layer. If any timers in this layer have the same identifier, theirtotal_time
andn_calls
fields are combined.clear_except
method toHierarchicalTimer
. This pops timers from the dict of "child timers" except those whose identifier match one of the identifiers provided as argumentsHierarchicalTimer
documentationLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: