Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP-3706: Set outlier detection buffer size based on total available memory #8756

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
5a82f06
add ModelLibrary
braingram Jun 18, 2024
98fb07f
update tweakreg to use ModelLibrary
braingram Jun 20, 2024
395298d
remove minimize_memory option for skymatch
braingram Jun 20, 2024
4b2ce13
update skymatch to use ModelLibrary
braingram Jun 20, 2024
018e3ce
temporary ModelContainer to and from ModelLibrary converter, assign_m…
emolter Jul 18, 2024
74b6607
replaced container with library in resample
emolter Jul 22, 2024
9233dd2
Revert "temporary ModelContainer to and from ModelLibrary converter, …
emolter Jul 29, 2024
bd6207b
put in nogroupid try except statements
emolter Jul 29, 2024
5c3cfc3
ModelLibrary for resample imaging, ModelContainer for resample spec
emolter Jul 29, 2024
c1615dd
Merge remote-tracking branch 'braingram/outlier_detection_steps' into…
emolter Jul 30, 2024
b4a7ce1
fixing problems from merge of outlier detection changes
emolter Jul 30, 2024
36c2b40
outlier detection to ModelLibrary for imaging modes
emolter Jul 30, 2024
c78841a
small fix to resample_spec
emolter Jul 30, 2024
9cdf2b7
Merge remote-tracking branch 'upstream/master' into JP-3690
emolter Jul 30, 2024
3103f82
convert to ModelLibrary and back again in resample_spec_step to avoid…
emolter Jul 30, 2024
2f85218
bugfixes for outlier detection unit tests
emolter Jul 31, 2024
570dc26
expose on_disk for all steps, some cleanup to passing libraries betwe…
emolter Jul 31, 2024
ad9902d
using map_function where applicable, more unit test bug fixes
emolter Jul 31, 2024
3d4fa0d
fix typo in pyproject.toml
emolter Jul 31, 2024
3db69d3
bump version of stpipe
emolter Jul 31, 2024
5ca774e
mark ModelLibrary as not part of stdatamodels
emolter Jul 31, 2024
d694178
added changelog entry
emolter Jul 31, 2024
6066f2b
first draft of docs changes
emolter Jul 31, 2024
48b1050
fixing regtest failures for spec3 pipeline, adding library to mtwcs
emolter Aug 1, 2024
99ef2f6
integrate assign_mtwcs changes with spec3 pipeline
emolter Aug 1, 2024
55262c0
debug coron3 pipeline
emolter Aug 2, 2024
f3ae92e
emptying data arrays in input to model_blender inside resample
emolter Aug 2, 2024
e27acc2
decreasing memory usage of outlier step using profiler
emolter Aug 2, 2024
d6c1642
revert refactor that introduced a bug in resample
emolter Aug 2, 2024
189b375
update skymatch input spec
emolter Aug 12, 2024
a2dd947
bugfix for failed asdf load of recursive wcs transform
emolter Aug 12, 2024
4307f22
Merge branch 'master' into JP-3690
emolter Aug 13, 2024
1ca5c9b
small changes from memory profiling and review
emolter Aug 13, 2024
6f08b61
bugfix for failed to load area extension and other metadata
emolter Aug 14, 2024
b124a8b
handle asn_table and asn_pool metadata properly
emolter Aug 14, 2024
62bacbd
make ind_asn_type case-insensitive
emolter Aug 14, 2024
30dcb3f
fix output filenames from outlier_detection
emolter Aug 14, 2024
5e9e672
bugfix for HDRTAB association info in i2d files
emolter Aug 15, 2024
f87809e
re-add python 3.13 pin that was accidentally clobbered
emolter Aug 15, 2024
ca62baf
reverting accidental clobber of stcal pin dependency
emolter Aug 15, 2024
d47ef4b
updates after reviews by myself and by @braingram
emolter Aug 16, 2024
26e5436
ruff style check
emolter Aug 16, 2024
8f902b7
call img.area
emolter Aug 19, 2024
33d66c9
bugfixes for remove s2d files and for mtimage regtest
emolter Aug 19, 2024
b357edc
Merge branch 'master' into JP-3690
emolter Aug 20, 2024
f35725a
attempted fix for resample and source_catalog result filenames
emolter Aug 20, 2024
4ed0892
remove setting of asn pool and table name in resample
emolter Aug 20, 2024
79f91c6
pushing bad things to remote to diagnose regtest
emolter Aug 20, 2024
3fd25fc
yet another attempt to fix filename issue
emolter Aug 20, 2024
28fa217
attempt to propagate fix also into source_catalog
emolter Aug 20, 2024
1863ef1
bugfix for updating table and pool name in library._assign_member_to_…
emolter Aug 21, 2024
cb5594e
fixes based on @braingram review
emolter Aug 21, 2024
099580c
fix ruff style check and remove unnecessary comment
emolter Aug 21, 2024
6ff67d3
fix unit test and revert changes to file naming
emolter Aug 22, 2024
6cad768
new attempted fix of output filenames
emolter Aug 23, 2024
91b1b19
removed one more manual change to output file naming
emolter Aug 23, 2024
bf069ed
changed has_groups conditional to reflect master branch
emolter Aug 23, 2024
5a44905
attempted fix single regtest failure for miri image3 crf files
emolter Aug 23, 2024
8d9f7c7
compute chunk size based on allowed memory
emolter Aug 26, 2024
5b9ecd8
using number of groups for buffer size
emolter Aug 26, 2024
e828ebc
Merge branch master into JP-3690
emolter Aug 27, 2024
5272ac9
fixes per @melanieclarke comments
emolter Aug 27, 2024
2afe670
merge master into JP-3690
emolter Aug 30, 2024
04e2fa5
fixed failure to raise NoGroupID for in-memory models with None for o…
emolter Aug 30, 2024
36ab34d
Merge branch 'master' into JP-3690
emolter Sep 5, 2024
41ddd29
Merge branch 'JP-3690' into JP-3706
emolter Sep 5, 2024
f8d1dc8
Merge branch 'master' into JP-3706
emolter Sep 5, 2024
6919a3a
added changelog entry
emolter Sep 5, 2024
eae6972
Merge branch 'master' into JP-3706
emolter Sep 5, 2024
f3f6d83
Merge branch 'master' into JP-3706
emolter Sep 9, 2024
2504d0f
Merge branch 'master' into JP-3706
emolter Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ outlier_detection

- Fix errors in documentation describing arguments. [#8603]

- Set buffer size for ``create_median`` based on the amount of available memory
instead of hard-coding a value, and make it respect ``allowed_memory`` parameter. [#8756]

pathloss
--------

Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def detect_outliers(
input_models.shelve(model, modify=True)

# Perform median combination on set of drizzled mosaics
median_data = create_median(drizzled_models, maskpt, on_disk=not in_memory)
median_data = create_median(drizzled_models, maskpt, on_disk=not in_memory, allowed_memory=allowed_memory)

if save_intermediate_results:
# make a median model
Expand Down
23 changes: 20 additions & 3 deletions jwst/outlier_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The ever-present utils sub-module. A home for all...
"""
import warnings
import psutil

import numpy as np

Expand Down Expand Up @@ -32,7 +33,7 @@
return median


def create_median(resampled_models, maskpt, on_disk=True, buffer_size=10.0):
def create_median(resampled_models, maskpt, on_disk=True, allowed_memory=None):
"""Create a median image from the singly resampled images.

Parameters
Expand All @@ -46,8 +47,9 @@
on_disk : bool
If True, the input models are on disk and will be read in chunks.

buffer_size : float
The size of chunk in MB, per input model, that will be read into memory.
allowed_memory : float
The fraction of available memory to be used by create_median.
If None, use 50% of the machine's available memory.
This parameter has no effect if on_disk is False.

Returns
Expand Down Expand Up @@ -75,6 +77,16 @@
return np.nanmedian(np.array(model_list), axis=0)
else:
# set up buffered access to all input models
log.info("Computing median in chunks to save memory")
if allowed_memory is None:
allowed_memory = 0.5
machine_available_memory = psutil.virtual_memory().available + psutil.swap_memory().total
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why swap memory is included. Unless I misunderstand what this refers to (and I may very well misunderstand), I don't think the size of the swap area should be included. We are most interested in how much real memory is available so no paging or swapping is necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing this. Brett pointed out the same thing, and it's buried somewhere in our long back-and-forth (understandable that you did not read it all lol). If the swap memory were removed, what is your take on whether it's better to use the total amount of available memory or a per-model section size?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just noticed the long discussion "below the fold". I had some general concerns as well along Brett's lines.

available_memory = machine_available_memory * allowed_memory

# buffer_size sets size of chunk in MB that will be read into memory per model
buffer_size = available_memory / len(resampled_models.group_names) / _ONE_MB
log.info(f"Chunk size {buffer_size} MB per model for {len(resampled_models)} models (totaling {allowed_memory * 100}% of available memory)")

with resampled_models:
example_model = resampled_models.borrow(0)
shp = example_model.data.shape
Expand All @@ -83,6 +95,11 @@
resampled_models.shelve(example_model, modify=False)
del example_model

if nsections == 1:
emolter marked this conversation as resolved.
Show resolved Hide resolved
log.info("Chunk size is large enough to read entire model at once")
else:
log.info(f"Data will be read in {nsections} sections of {section_nrows} rows each")

Check warning on line 101 in jwst/outlier_detection/utils.py

View check run for this annotation

Codecov / codecov/patch

jwst/outlier_detection/utils.py#L101

Added line #L101 was not covered by tests

# get spatial sections of library and compute timewise median, one by one
resampled_sections = _get_sections(resampled_models, nsections, section_nrows, shp[0])
median_image_empty = np.empty(shp, dtype) * np.nan
Expand Down
Loading