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

Cubeviz cube fitting: Fix fitted cube all zeroes, allow MP bypass #1333

Merged
merged 1 commit into from
May 25, 2022

Conversation

pllim
Copy link
Contributor

@pllim pllim commented May 20, 2022

Description

This pull request is to address reported bug where a failed cube fit would silently return a cube with all zeroes because multiprocessing swallowed all the exceptions. This PR intents to:

  • fix the bug that caused the exception in the first place
  • allow bypassing multiprocessing when n_cpu is set to 1 (this feature is for developers only)

Fix #1245

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)? 🐱

@pllim pllim added the bug Something isn't working label May 20, 2022
@pllim pllim added this to the 2.6 milestone May 20, 2022
@codecov
Copy link

codecov bot commented May 20, 2022

Codecov Report

Merging #1333 (16ca3d9) into main (2e1e505) will decrease coverage by 0.05%.
The diff coverage is 66.66%.

❗ Current head 16ca3d9 differs from pull request most recent head d55fb5e. Consider uploading reports for the commit d55fb5e to get more accurate results

@@            Coverage Diff             @@
##             main    #1333      +/-   ##
==========================================
- Coverage   84.64%   84.58%   -0.06%     
==========================================
  Files          91       91              
  Lines        7878     7839      -39     
==========================================
- Hits         6668     6631      -37     
+ Misses       1210     1208       -2     
Impacted Files Coverage Δ
jdaviz/utils.py 89.87% <60.00%> (-2.34%) ⬇️
...igs/default/plugins/model_fitting/model_fitting.py 78.79% <100.00%> (ø)
...default/plugins/metadata_viewer/metadata_viewer.py 93.40% <0.00%> (-1.10%) ⬇️
jdaviz/app.py 91.21% <0.00%> (-1.01%) ⬇️
...imviz/plugins/aper_phot_simple/aper_phot_simple.py 91.55% <0.00%> (-0.65%) ⬇️
...z/configs/default/plugins/line_lists/line_lists.py 68.87% <0.00%> (-0.48%) ⬇️
jdaviz/configs/mosviz/plugins/parsers.py 90.42% <0.00%> (-0.14%) ⬇️
jdaviz/configs/mosviz/helper.py 86.74% <0.00%> (-0.04%) ⬇️
jdaviz/core/template_mixin.py 93.06% <0.00%> (+0.17%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84ddff9...d55fb5e. Read the comment docs.

jdaviz/utils.py Outdated Show resolved Hide resolved
@pllim

This comment was marked as resolved.

@pllim

This comment was marked as resolved.

@pllim pllim changed the title Hotfixes for Ori and Cami demo Cubeviz cube fitting: Fix fitted cube all zeroes, allow MP bypass May 24, 2022
@pllim pllim added the cubeviz label May 24, 2022
DEV: Allow multiprocessing bypass when n_cpu is 1
@pllim pllim force-pushed the cubeviz-hotfixes branch from 3637fbc to d55fb5e Compare May 24, 2022 16:49
Copy link
Contributor Author

@pllim pllim left a comment

Choose a reason for hiding this comment

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

@rosteen , please double check the X and Y order. That part always confuses me because of specutils reordering things and such.

@@ -119,14 +113,16 @@ def test_cube_fitting_backend():

SIGMA = 0.1 # noise in data
TOL = 0.4 # test tolerance
IMAGE_SIZE_X = 15
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I purposely made this asymmetric so it is easier to tell if we get the spatial dimension wrong.

assert fitted_spectrum.flux.unit == u.Jy
assert not np.all(fitted_spectrum.flux.value == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there is a better way to test the contents of fitted_spectrum but maybe we can defer that for the "science verification" campaign.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it would be too hard to generate a known shape with some noise on top and check that the result is within tolerance of the expected fit, but I agree that I think we can defer that for now.

Copy link
Member

Choose a reason for hiding this comment

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

Should we add a comment above this to the effect of "if this ever fails, set n_cpu=1 to access the tracebacks from fitting"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a comment to that effect on line 149 # n_cpu = 1 # NOTE: UNCOMMENT TO DEBUG LOCALLY, AS NEEDED, think there needs to be another one here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of copy pasting that sentence everywhere in the test, should I just write it up in dev docs? Any suggestion on where?

Copy link
Member

Choose a reason for hiding this comment

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

this is currently the one place that will catch these failures, right? But I guess we may have more in the future - I'm just trying to save us time in the future if/when this returns zeros and trips this test again. I'm not sure I would remember and see the other comment to even know that a debug mode is an option. But I suppose we always have the blame history back to this PR 🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it help if I expose this in API doc over at RTD as a follow-up PR?

n_cpu : `None` or int
**This is only used for spectral cube fitting.**
Number of cores to use for multiprocessing.
Using all the cores at once is not recommended.
If `None`, it will use max cores minus one.
Set this to 1 for debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will ping you to review #1346 when it is ready. Thanks!

@pllim pllim marked this pull request as ready for review May 24, 2022 17:03
@pllim pllim requested a review from orifox May 24, 2022 17:04
Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Works for me, thanks.

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Science verification and regression tests still need to be added (as future efforts) to ensure this bug doesn't resurface for various scenarios, but this at least enables us to write those tests and debug when they fail.

@rosteen
Copy link
Collaborator

rosteen commented May 25, 2022

This closes #1245

@rosteen rosteen merged commit cf1caa0 into spacetelescope:main May 25, 2022
@pllim pllim deleted the cubeviz-hotfixes branch May 25, 2022 14:13
@pllim pllim mentioned this pull request May 25, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Cubeviz: model fitting over the cube fails with spectral subset
3 participants