Read calfits files without memory-mapping - #1724
Conversation
Clarify the description of the memmap option in the docstring.
for more information, see https://pre-commit.ci
Updated docstring to clarify memory-mapping behavior.
for more information, see https://pre-commit.ci
Added a 'memmap' keyword option to UVCal.read_calfits and UVCal.read for optimized file reading.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1724 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 23912 23912
=========================================
Hits 23912 23912 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@tyler-a-cox thank you for this! My reading of the astropy docs is that setting memmap=True is what lets you read in part of the data. So I think we should only use memmap=True when we're only reading in a portion of the data. I thought that's what we did on uvfits, but looking at it now it seems like memmap is always False, so there may be a bug there. I'm not sure we need a read parameter for this if we set it sensibly based on whether or not there's a select, but I could be convinced otherwise with a good use case. |
|
@bhazelton thanks for giving this a look over! I'm definitely open to removing |
|
@bhazelton after reviewing the code, I realized that calfits never actually does partial reads. I can either implement select on read for calfits, which feels like a pretty large structural change, or just always open calfits files with |
|
Ah, I had forgotten that we hadn't implemented partial read on cal fits. Let's just set to always be False. |
|
Okay, looks like that simplified things a little. Should be ready to look at now! |
bhazelton
left a comment
There was a problem hiding this comment.
Looks great, thank you @tyler-a-cox !
Description
UVCal.read_calfitsnow opens calfits files withmemmap=False. The calfits reader always reads the data in full (select happens after the read) or, withread_data=False, doesn't read it at all, so memory-mapping doesn't buy anything here. Metadata-only reads still only read the headers and the antenna table.The gain-type
quality_arrayis copied out of the FITS data array so the rest of that array can be freed once the gains and flags are built.I added a test (
test_read_not_memmappedintests/uvcal/test_calfits.py) that checks the arrays aren't memory-mapped after a read and that the gain quality array doesn't hold onto the FITS data. I also added a CHANGELOG entry.Motivation and Context
For HERA phase II we read about 1850 calfits files per night off of NRAO's Lustre file system during calibration smoothing, and a lot of that time is spent in memory-mapped reads. On a network file system, memory-mapping pulls in the file a piece at a time as the arrays are accessed, and each of those pieces has to wait on the network. Reading without memory-mapping grabs the data in one big read.
I timed
read_calfitson some of our calfits files on Lustre, clearing the page cache first. The median read took 2.1 s per file with memory-mapping and 0.23 s per file without it, so about 9x faster. Peak memory was the same either way (about 60 MB per read), and the arrays were identical. On local disk the two were about the same.This follows #1651, which stopped
read_uvfitsfrom memory-mapping full reads.Types of changes
Checklist:
Other: