Multiprocessing for cube_rescaling and import VIP in ~1 millisecond#702
Merged
VChristiaens merged 6 commits intovortex-exoplanet:masterfrom Mar 25, 2026
Merged
Multiprocessing for cube_rescaling and import VIP in ~1 millisecond#702VChristiaens merged 6 commits intovortex-exoplanet:masterfrom
VChristiaens merged 6 commits intovortex-exoplanet:masterfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #702 +/- ##
==========================================
+ Coverage 23.55% 32.51% +8.96%
==========================================
Files 88 88
Lines 17010 17048 +38
==========================================
+ Hits 4006 5543 +1537
+ Misses 13004 11505 -1499 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Thanks a lot @IainHammond ! These changes look great! Also these are significant speed gains - well done 👍 |
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.
As title!
This request adds

nproctocube_rescaling. What's the motivation: rescaling takes quite a long time since it's done in serial (frame-by-frame) by looping overframe_rescaling. This is normally not too much of a problem because a typical cube isn't all that large (e.g. 39 channels for IFS). The problem arises when we have a 4D cube of say 80 temporal frames. Or in a non-coronagraphic dataset when this could be several hundred. For SDI, the cube is scaled not once but twice, so this can lead to several thousand calls tocube_rescalingwith no multiprocessing. Now, whennproc> 1, frames are rescaled in parallel viapool_mapusing a new helper function_frame_rescaling_mp.nproc=1 is still the default and the function behaves as it always has. There are no changes to return values or other parameters. I also usereuse_pool=Trueso the pool remains open and is not continually closed and re-opened, since we are normally looping over a 4D cube. Pools are cleaned up at the end byatexitwhich was added recently by Gilles. The function is significantly faster now and mostly limited by read/write. There are still performance gains on 1 CPU (e.g. a laptop) because the jobs are spread across the CPU cores and not run in serial so there are always gains by increasing nproc. Here are the results on a cluster (yes I had a lot of spare time while waiting for a PDS 70 dataset!):Second part: addressing the impressively slow importing of the VIP package. The current version of VIP will load absolutely everything when any function is imported and all dependencies in the entire package. This can get particularly annoying when just opening a fits file for a quick check or running something simple, and was really noticable on a cluster that was made for storage capacity and not speed. Other packages like numpy and scipy comply with PEP 562, which only import exactly what is needed for a function to run and became standard in python 3.7. So this pull request makes VIP PEP 562 compliant by yoinking what other packages do. Submodules only load when you actually use them and when they do load, they take the same time they always did. The slow loading of preproc (mostly due to torch) only occurs if you actually import vip_hci.preproc. The result is the following:
import vip_hci: ~2.8s -> 0.001sfrom vip_hci.fits import open_fits: ~2.8s -> 0.01sIt also saves about 200MB of RAM from not loading every dependency while being crazy fast. In the future we should probably move the torch import to be a lazy load in
cube_derotateif the user specifically asks for torchEnjoy!