Vectorise matrix extraction in MetisLMSSpectralTrace.get_matrices - #988
Open
astronomyk wants to merge 1 commit into
Open
Vectorise matrix extraction in MetisLMSSpectralTrace.get_matrices#988astronomyk wants to merge 1 commit into
astronomyk wants to merge 1 commit into
Conversation
The 4x4 matrix elements were selected with one boolean mask over the full polynomial table per matrix (4 scans of ~38k rows) plus one mask per element on the sub-table (64 more), for every one of the 28 slices. Select the (order, slice) block once, evaluate the angle polynomial on whole columns, and scatter the values into the matrices via their Row/Col indices. Results are exactly identical; the KeyError for an unknown order/slice combination is kept. Adds an element-by-element equivalence test against the previous per-element evaluation, and a KeyError test.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #988 +/- ##
==========================================
+ Coverage 76.46% 76.82% +0.36%
==========================================
Files 69 69
Lines 9025 9024 -1
==========================================
+ Hits 6901 6933 +32
+ Misses 2124 2091 -33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding both @oczoske and @teutoburg as it's more a mechanics issue, than an instrument specific one.
Local tests produce identical results.
TL;DR - A speed boost for SpectralTraceList
From the testing notebook, removing these nested loops results in a 10x speed boost for extracting the polynomial coefficients
Not that impressive on a single run, but when we have to run this hundreds of times for METIS_Simulations, it all adds up.
Resulting in
Toaster description below:
What
The A/B/AI/BI matrices are polynomial evaluations at the echelle angle, with coefficients selected from the
Polynomial coefficientstable (37,632 rows inTRACE_LMS.fits). The old loop ran one boolean mask over the full table per matrix, plus one mask per matrix element on the sub-table — (4 + 64) table scans for each of the 28 slices, on every trace-list construction.The new code selects the (order, slice) block once, evaluates the angle polynomial on whole columns, and scatters the values into the 4x4 matrices via their Row/Col index columns. The resulting matrices are exactly identical (same additions in the same order — unit-tested element-by-element with zero tolerance); the KeyError for an unknown order/slice combination is kept.
Testing
TestGetMatrices::test_matches_elementwise_reference— exact equality against the previous per-element evaluation for slices 1, 14 and 28 of the real coefficient table.TestGetMatrices::test_raises_for_unknown_order— KeyError behaviour preserved.