simplified MultisliceCalculator no longer uses _process_frame_worker_torch#39
Merged
simplified MultisliceCalculator no longer uses _process_frame_worker_torch#39
Conversation
…compatible, ensuring 18_caching test still passes
Collaborator
Author
|
testing status test consists of:
watch out:, main currently will NOT run on gpu. just copy this branch's multislice/potentials.py in. the only difference should be the loading of the potential slices appropriately (looks like this was never tested on gpu before, somehow) life pro tip: |
This was referenced Jan 2, 2026
Merged
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.
Why?
_process_frame_worker_torch does some pretty incredible pack/unpack to get all the args passed in. this was necessary when trying to implement multiprocessing, but i don't think it helped, nor is necessary, given the various improvements and speed gains from torch.
all these pack/unpack shenanigans also make maintenance difficult. adding new features (e.g., i would like to add vectorized processing of multiple different probes, to implement spatial/temporal decoherence), but this is tough in it's current state.
it's also a challenge for code readability (imo). one must keep track of what variable was what between MultisliceCalculator.run and _process_frame_worker_torch.
plus, this is an opportunity to clean up a lot of the "if torch" and "if slices" stuff, and varying shapes of the propagated array (whether or not there is in index for probes or layers).
also, half the code inside _process_frame_worker_torch was just torch device and dtype checking, and we really don't expect the worker to have different dtypes/devices from what MultisliceCalculator has.
Changes
first, i moved all the logic from _process_frame_worker_torch into the frame loop of MultisliceCalculator.run.
then, I greatly cleaned up the logic. I have made use of the backend in some places, with backend.zeros and the new backend.expand_dims, to account for the varying shapes of things.
exit_waves_batch is always l,p,x,y (since i expand_dims if l or p are missing), meaning we can always loop through layers (get rid of an if/else), to do the FFT and load into frame_data (which is always p,x,y,l,1, as before).
testing
earlier this evening I wrote up tests/18_caching.py, which runs a series of generic calculations (e.g., with and without multiple probe positions, with and without multiple timesteps, with and without layer-by-layer results cached). results are also saved for future comparison via differ.
I then ran the same test in this branch 1) with no psi_data folder (new caches) 2) with a self-generated psi_data folder (demonstrating that this branch creates and reloads its own caches as expected) and 3) with a psi_data generated from main, pre-merge (demonstrating that this branch can reload previously-generated caches, and that these changes are backwards compatible).