Skip to content

Conversation

@emolter
Copy link
Collaborator

@emolter emolter commented May 7, 2025

Resolves JP-3776

Closes #8860

This PR refactors the AmiAnalyze step to avoid creating a long list of 3-D arrays, reducing memory usage by a factor of ~13 for my test dataset (jw01349-c1007_20250319t131303_ami3_00002_asn.json). See ticket for memory usage flamegraphs - the one for this PR branch is named memray-flamegraph-output_refactor.html.

A beneficial side-effect of this refactor is that it removes a code pattern in which RawOifits objects required FringeFitter object as input, but some methods of FringeFitter required a RawOifits that was being initialized with that very same FringeFitter object, i.e. RawOifits(self). Now both classes require only an instrument data object, which I feel makes more logical sense and more cleanly splits up the roles of RawOifits and FringeFitter.

Memory usage tests to prevent a regression will be added by #9433

Tasks

  • If you have a specific reviewer in mind, tag them.
  • add a build milestone, i.e. Build 12.0 (use the latest build if not sure)
  • Does this PR change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see changelog readme for instructions)
    • update or add relevant tests
    • update relevant docstrings and / or docs/ page
    • start a regression test and include a link to the running job (click here for instructions)
      • Do truth files need to be updated ("okified")?
        • after the reviewer has approved these changes, run okify_regtests to update the truth files
  • if a JIRA ticket exists, make sure it is resolved properly

@github-actions github-actions bot added the ami label May 7, 2025
@emolter emolter added this to the Build 12.0 milestone May 7, 2025
@emolter emolter requested a review from rcooper295 May 7, 2025 21:25
@emolter emolter requested a review from drlaw1558 May 7, 2025 21:28
@emolter
Copy link
Collaborator Author

emolter commented May 7, 2025

regression tests started here https://github.com/spacetelescope/RegressionTests/actions/runs/14893626000

edit: Single failure was from JP-3941 and is not related

@codecov
Copy link

codecov bot commented May 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.85%. Comparing base (b4f10ec) to head (16abf3f).
⚠️ Report is 678 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9442   +/-   ##
=======================================
  Coverage   77.85%   77.85%           
=======================================
  Files         362      362           
  Lines       36287    36287           
=======================================
  Hits        28252    28252           
  Misses       8035     8035           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@emolter emolter marked this pull request as ready for review May 8, 2025 17:38
@emolter emolter requested review from a team as code owners May 8, 2025 17:38
Copy link
Contributor

@drlaw1558 drlaw1558 left a comment

Choose a reason for hiding this comment

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

LG2M; confirmed with some 1600-integration AMI data that the peak memory usage drops from 27 GB to < 1 GB. Output data look to be unchanged, as is the runtime.

@emolter emolter requested a review from tapastro May 9, 2025 17:06
Copy link
Collaborator

@melanieclarke melanieclarke left a comment

Choose a reason for hiding this comment

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

This looks sensible to me. It needs rebasing, and we should run the regtests again. They should now show the memory improvements, since #9433 was merged, right?

Do you want to wait for Rachel to review?

@emolter
Copy link
Collaborator Author

emolter commented May 9, 2025

Do you want to wait for Rachel to review?

I don't think it's necessary to do so. There are a few "API changes" if someone were using these classes outside the pipeline, but my understanding from my last conversations with Rachel is that, while the team wants to maintain the flexibility of these classes for testing (i.e., don't just remove everything not used by pipeline) they don't have any active/established workflows that require these. And the refactor doesn't remove any information that isn't accessible via a straightforward workaround.

If it turns out they're unhappy with the changes we'd hear about it in testing anyway.

@emolter
Copy link
Collaborator Author

emolter commented May 9, 2025

@emolter
Copy link
Collaborator Author

emolter commented May 9, 2025

regression tests are clean. The memory usage tracker shows

test case | previous status | current status | previous peakmem | current peakmem
jwst.regtest.test_niriss_ami3::test_log_tracked_resources_ami3 |   |   | 1259MB | 161MB

@emolter emolter requested a review from melanieclarke May 9, 2025 19:42
@melanieclarke melanieclarke merged commit 8ab59e7 into spacetelescope:main May 12, 2025
23 checks passed
@emolter emolter deleted the JP-3776 branch May 12, 2025 13:11
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.

Improve AmiAnalyze memory usage

4 participants