Skip to content

Write measurement data to temporary files - #15

Open
josephburkhart wants to merge 15 commits into
mainfrom
better-data-transfer
Open

josephburkhart wants to merge 15 commits into
mainfrom
better-data-transfer

Conversation

@josephburkhart

@josephburkhart josephburkhart commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR resolves memory issues caused when measuring fields with high position and orientation resolution by streaming measurement data to files on disk, rather than keeping it all in memory.

Currently, util.simulation.measure() streams data as comma-separated strings into a StringIO object, and then passes that object back up to System.measure() to be processed further. This causes problems when the number of measured positions and orientations is quite large, eventually resulting in out-of-memory issues.

This PR resolves that problem by using StringIO only as a buffer, and periodically dumping that buffer into a temporary file, <destination>/measure_part<i>.csv, where <destination> is the parent folder of the requested output file and <i> is the process number.

Note the following changes:

  • util.simulation.measure() no longer returns anything, it just writes measure_part<i>.csv to disk.
  • System.measure() merges the part files and cleans their headers, so merge_tables() and clean_header() have been removed from util/data.py. This merging and cleaning is now memory-friendly, meaning that the part files are never loaded fully into memory. If support is added for new table file formats in the future, this functionality may be moved back into util/data.py.
  • Before executing the measurement loop, System.measure() now checks if files can be read/written/removed from the destination, and it raises an error if they cannot.
  • Users can now specify if they want System.measure() to return a field instance or not. If this were not the case, the whole table file would be loaded into memory and that could cause the same out-of-memory issue. In the future, functionality may be added to allow users to do aggregation over orientations on the file on disk.

The new approach is covered by new and existing tests in test/test_measure.py.

The "breaking changes" listed above only impact functions in the util module, so this PR is not itself considered a breaking change.

Motivation and Context

Users often want to measure fields with high resolution on HPC resources. They should not need to request additional compute nodes just to increase the amount of available memory. Additionally, users should be able to measure high resolution fields on their local computers without worrying about running out of memory.

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant