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-3678: Ensure C extension works with multiprocessing #268

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ Changes to API
Bug Fixes
---------

-

ramp_fitting
~~~~~~~~~~~~

- When OLS_C was selected as the ramp fitting algorithm with multiprocessing, the C
extension was not called. The old python code was called. This bug has been fixed,
so the C extension is properly run when selecting multiprocessing. [#268]

1.7.2 (2024-06-12)
==================
Expand Down
12 changes: 9 additions & 3 deletions src/stcal/ramp_fitting/ols_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
nrows = ramp_data.data.shape[2]
num_available_cores = cpu_count()
number_slices = utils.compute_num_slices(max_cores, nrows, num_available_cores)
log.info(f"Number of multiprocessing slices: {number_slices}")

# For MIRI datasets having >1 group, if all pixels in the final group are
# flagged as DO_NOT_USE, resize the input model arrays to exclude the
Expand Down Expand Up @@ -574,6 +575,8 @@
ramp_data_slice.start_row = start_row
ramp_data_slice.num_rows = nrows

ramp_data_slice.run_c_code = ramp_data.run_c_code

Check warning on line 578 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L578

Added line #L578 was not covered by tests

return ramp_data_slice


Expand Down Expand Up @@ -661,19 +664,20 @@
opt_info : tuple
The tuple of computed optional results arrays for fitting.
"""
# use_c = False
# use_c = True # XXX Change to default as False
use_c = ramp_data.dbg_run_c_code
use_c = ramp_data.run_c_code
if use_c:
c_start = time.time()

ramp_data, gain_2d, readnoise_2d, bswap = endianness_handler(ramp_data, gain_2d, readnoise_2d)

if ramp_data.drop_frames1 is None:
ramp_data.drop_frames1 = 0
log.debug("Entering C extension")

Check warning on line 675 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L675

Added line #L675 was not covered by tests
image_info, integ_info, opt_info = ols_slope_fitter(
ramp_data, gain_2d, readnoise_2d, weighting, save_opt)

log.debug("Returning from C extension")

Check warning on line 679 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L679

Added line #L679 was not covered by tests

c_end = time.time()

# Read noise is used after STCAL ramp fitting for the CHARGELOSS
Expand All @@ -694,8 +698,10 @@

p_start = time.time()

log.debug("Entering python code")
image_info, integ_info, opt_info = ols_ramp_fit_single_python(
ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, weighting)
log.debug("Returning from python ")

p_end = time.time()
p_diff = p_end - p_start
Expand Down
2 changes: 1 addition & 1 deletion src/stcal/ramp_fitting/ramp_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
ramp_data = create_ramp_fit_class(model, dqflags, suppress_one_group)

if algorithm.upper() == "OLS_C":
ramp_data.dbg_run_c_code = True
ramp_data.run_c_code = True

Check warning on line 176 in src/stcal/ramp_fitting/ramp_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ramp_fit.py#L176

Added line #L176 was not covered by tests

return ramp_fit_data(
ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, algorithm, weighting, max_cores, dqflags
Expand Down
2 changes: 1 addition & 1 deletion src/stcal/ramp_fitting/ramp_fit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self):
self.suppress_one_group_ramps = False

# C code debugging switch.
self.dbg_run_c_code = False
self.run_c_code = False

self.one_groups_locs = None # One good group locations.
self.one_groups_time = None # Time to use for one good group ramps.
Expand Down
Loading