Refactor model.update#710
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #710 +/- ##
=======================================
Coverage 90.32% 90.33%
=======================================
Files 99 99
Lines 4641 4563 -78
=======================================
- Hits 4192 4122 -70
+ Misses 449 441 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This sounds reasonable to me in principle although I haven't reviewed the code changes in detail. Does the change to the validation process make a difference in performance? I know validation can be expensive sometimes, I'm wondering how many separate validation calls compares to one big one. |
|
Thanks for suggesting looking at runtime @melanieclarke , as you maybe suspected yes this new method is slower. To update a blank You are right that in certain circumstances validation can be a substantial fraction of model overhead, e.g. if data arrays are very small, so this slowdown is definitely worth considering. I may have found a way to make validation a bit faster - I'll see if that's worth pursuing and then push up a separate PR. I do think something should be done here though. I think I've convinced myself that allowing |
|
@melanieclarke had asked whether the @tapastro had asked if the |
|
Thanks for checking @emolter - that all makes sense to me. |
|
I thought it might be good to address the schema update in a separate PR: #712 That way we can more easily ensure this PR doesn't have other unanticipated impacts. But let me know if you think this is not necessary. |
|
instead of updating multislit schema, now pointing to a jwst branch where we attempt never to set multislit wcsinfo: https://github.com/spacetelescope/RegressionTests/actions/runs/24575930853 |
braingram
left a comment
There was a problem hiding this comment.
Overall code changes look good to me. One request for updating the update docstring. Also how does the performance look now?
Finally, are the regtest failures all expected with this PR (and the linked jwst one)?
|
The JWST PR shows the same failures when pointed to stdatamodels main. My expectation is that once that's merged, a regtest rerun of jwst main against this branch will be clean. The speed numbers from #710 (comment) are still accurate: before this PR, update was taking 15ms to populate a blank RampModel with real regtest RampModel metadata. After, along with #714, it takes 26ms. Nearly all of the difference is still in validation. |
braingram
left a comment
There was a problem hiding this comment.
Thanks! This greatly simplifies update. I may poke at the update performance to see if there are any easy wins there but those don't need to hold up this PR.
|
companion jwst PR is merged now. https://github.com/spacetelescope/RegressionTests/actions/runs/24787022754 should check for any unexpected differences before merging this. |
Closes #690
This PR modifies
model.updateto set attributes on the datamodel object nodes directly instead of into its instance dictionary, except in the case ofextra_fitswhen requested, which exist outside the schema.There are two major effects of the change.
First, validation now occurs attribute-by-attribute on assignment, replacing a call to
model.validate()at the end. This is beneficial because it avoids triggering validation warnings/errors that were not introduced by the update call itself. See #690 for a concrete example. This also makesmodel.updaterespect thevalidate_on_assignmentflag.Second,
update()will no longer add non-schema-defined attributes to the target model. For example,on main the last line returns
100.0, i.e., propagates the value from source to target. On the PR branch, the last line will raise anAttributeError- that attribute was not updated since it wasn't in the schema.My opinion is that the new behavior is better; however, it seems the old behavior was leveraged in the pipeline to give
wcsinfotoMultiSlitModelin the extract2d step. That was the cause of these errors: https://github.com/spacetelescope/RegressionTests/actions/runs/24104400120/attempts/2An AI tool was used to help prepare this PR.
Tasks
docs/pageno-changelog-entry-needed)changes/:echo "changed something" > changes/<PR#>.<changetype>.rst(see below for change types)jwstregression tests with this branch installed ("git+https://github.com/<fork>/stdatamodels@<branch>")news fragment change types...
changes/<PR#>.feature.rst: new featurechanges/<PR#>.bugfix.rst: fixes an issuechanges/<PR#>.doc.rst: documentation changechanges/<PR#>.removal.rst: deprecation or removal of public APIchanges/<PR#>.misc.rst: infrastructure or miscellaneous change