Model evaluation refactor#11931
Conversation
|
👋 Thank you for your draft pull request! Do you know that you can use |
|
Hello @WilliamJamieson 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-10-25 18:47:29 UTC |
10316de to
290fc4e
Compare
a46a3fd to
986445d
Compare
986445d to
38642ef
Compare
38642ef to
1c2dfd1
Compare
1c2dfd1 to
a44bea7
Compare
a44bea7 to
4a4fbc9
Compare
Integrated new bounding_box into automatic bounding_boxes Finished TODO to remove check on bounding box input processing. Updated _fix_input_bounding_box to be in line with PR astropy#11908. Made fix_inputs_with_bounding_box more robust Improved test_custom_model_bounding_box test to test with_bounding_box=True Removed debugging print from a test. Added changelog entry. Added `__all__` to bounding_box.py Fixed more docstrings Integrated new bounding_box into automatic bounding_boxes Finished TODO to remove check on bounding box input processing. Improved test_custom_model_bounding_box test to test with_bounding_box=True Removed debugging print from a test. Added `__all__` to bounding_box.py Fixed more docstrings Refactored generic_call Removed generic_call from core.py Refactored _generic_evaluate into Model class Moved get_bounding_box into model class Moved _prepare_inputs_* functions into model class Refactored _prepare_outputs_* into model. Refactored validate_input_shapes into model Refactored some helper functions into model. Fixed codestyle errors. Added changelog entry. Minor refactoring and additional documentation. More documentation added. Fixed get_bounding_box in asdf Moved changelog to correct folder Fixed rebase issue Refactored and added tests to increase test coverage.
4a4fbc9 to
3b6f4df
Compare
perrygreenfield
left a comment
There was a problem hiding this comment.
Just some minor comments; otherwise LGTM
|
|
||
| return output | ||
|
|
||
| def _prepare_outputs_single_model(self, outputs, format_info): |
There was a problem hiding this comment.
This might be a good opportunity to change the awful name format_info
There was a problem hiding this comment.
Though I wouldn't want to hold up getting this into the next astropy release. A new issue?
There was a problem hiding this comment.
Agreed, but I could not come up with a better name at the time. Maybe broadcast_shapes?
There was a problem hiding this comment.
Or broadcasted_shapes? Which implies an action taken upon them.
| else: | ||
| try: | ||
| return output.reshape(broadcast_shape) | ||
| except ValueError: |
There was a problem hiding this comment.
Some explanation of why this differs from the previous version would be helpful in the review. E.g., what previous problem is this fixing, or new capability it now handles. It otherwise seems more complex than the previous logic as well as relying on exception handling.
There was a problem hiding this comment.
This bit (of convoluted logic) is literally the old _prepare_outputs_single_model function. I just moved it from being a function to a bound static method, so that it was closer in the code to where it was actually being used.
There was a problem hiding this comment.
I got the heritage and the movement into methods, where the first arguments were essentially self (in some cases literally!); I was mainly asking about the new logic structure.
There was a problem hiding this comment.
This is somewhat explained in this comment. The major goal was to refactor the bounding box related parts of model evaluation so that they were performed by the bounding box itself. This paves the way for the CompoundBoundingBox in #11942, to add additional bounding box logic without lots of ugly hacks in core.py.
The rest of the logic structure was my attempt to move all the evaluation inside Model itself in such a way that CompoundModel could modify that logic as a sub class of Model instead of a lot of scattered external logic. Doing this made it easier to move the bounding box logic out in a consistent fashion.
|
@perrygreenfield. This PR is intended to streamline the model evaluation code (in my opinion). It moves the code from functions which "look-like" they should be bound methods but are not bound methods, to actual bound methods. So a lot of the changes are cut and pasting code around Moreover, since the bounding_box has become a more functional object. All of the bounding box enforcement logic has been moved into the The main goal of this refactor, in my mind, was to ready modeling for future refactoring of models so that |
|
|
||
| return output | ||
|
|
||
| def _prepare_outputs_single_model(self, outputs, format_info): |
There was a problem hiding this comment.
Or broadcasted_shapes? Which implies an action taken upon them.
| else: | ||
| try: | ||
| return output.reshape(broadcast_shape) | ||
| except ValueError: |
There was a problem hiding this comment.
I got the heritage and the movement into methods, where the first arguments were essentially self (in some cases literally!); I was mainly asking about the new logic structure.
|
@pllim Is there an issue with this going into 5.0? |
|
No. I wasn't expecting it to be merged so soon. This is not the astropy way. 😂 Will readjust milestone. |
|
My fault then. I was under the impression this was urgent to get in for the release (and there is another PR dependent on it) |
|
I did add a commit on |
No one's fault! |
|
Cool. Thanks for figuring this out! |
Description
This pull request extends the refactoring work in PR #11930 (indeed it depends on this PR so it should be rebased after this PR is merged) by further cleaning up model evaluation methods in
~astropy.modeling.core. This is an attempt to remove repeated code while moving methods closer to where they are used.Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CIlabel.no-changelog-entry-neededlabel.astropy-botcheck might be missing; do not let the green checkmark fool you.backport-X.Y.xlabel(s) before merge.