Lower memory in photon to geometry calculation#515
Draft
Conversation
…ctures in geometry rather than vectorising across large arrays.
…. Not as clean or Pythonic, but it saves a *lot* of memory.
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.
With Jim's investigation this may no longer be necessary, but in case it's useful here are the changes I made to
diffraction.pythat reduce memory usage indirected_dist(). The code as it is now inmainis nicely vectorised, but relies heavily on intermediate arrays which can really eat into memory if bright objects are being processed. This line alone allocates very nearly 1 GB when I run the realistic test Jim gave me with photon pooling enabled and photon processing of bright objects.(That's why it may not be needed - if it's only ever going to be FFTs.)
I've split the calculation apart so it no longer calculates and stores the vectors between all points (photons) and structures, but it now stores only the vector to the nearest object.
I also investigated changing the call to
apply_diffraction_delta()in e.g.RubinDiffractionby havingimSim/imsim/photon_ops.py
Lines 294 to 301 in 6dda08b
not call it all in one go, but looping through the full array of
vand filling it in chunks of say 100. I'm not sure it actually helped much at all in contrast with this change and the one in #513, so I haven't included it here, but wanted to mention it in case.