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

Avoid repeated outer products in free-bound emission calculation #319

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

wtbarnes
Copy link
Owner

@wtbarnes wtbarnes commented Sep 27, 2024

Fixes #318

This refactors the Ion.free_bound calculation a bit to avoid repeated np.outer calls that produce arrays of size n_temperature by n_wavelength.

Doing some informal benchmarking, without this PR, for a temperature array of length 5000 and a wavelength array of 1000,

============================================================================ test session starts ============================================================================
platform darwin -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0
rootdir: /Users/wtbarnes/Documents/codes/fiasco
configfile: pyproject.toml
plugins: astropy-0.11.0, cov-5.0.0, remotedata-0.4.1, anyio-4.3.0, filter-subpackage-0.2.0, doctestplus-1.2.1, astropy-header-0.2.2, hypothesis-6.102.6, asdf-3.2.0, arraydiff-0.6.1, mock-3.14.0
collected 1 item

fiasco/tests/test_performance.py .                                                                                                                                    [100%]

============================================================================= slowest durations =============================================================================
36.18s call     fiasco/tests/test_performance.py::test_fb_speeds
1.05s setup    fiasco/tests/test_performance.py::test_fb_speeds

(1 durations < 0.005s hidden.  Use -vv to show these durations.)

and with this PR,

============================================================================ test session starts ============================================================================
platform darwin -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0
rootdir: /Users/wtbarnes/Documents/codes/fiasco
configfile: pyproject.toml
plugins: astropy-0.11.0, cov-5.0.0, remotedata-0.4.1, anyio-4.3.0, filter-subpackage-0.2.0, doctestplus-1.2.1, astropy-header-0.2.2, hypothesis-6.102.6, asdf-3.2.0, arraydiff-0.6.1, mock-3.14.0
collected 1 item

fiasco/tests/test_performance.py .                                                                                                                                    [100%]

============================================================================= slowest durations =============================================================================
20.20s call     fiasco/tests/test_performance.py::test_fb_speeds
1.08s setup    fiasco/tests/test_performance.py::test_fb_speeds

(1 durations < 0.005s hidden.  Use -vv to show these durations.)
============================================================================ 1 passed in 21.36s =============================================================================

For smaller arrays, $O(10^2)$ entries, the gains are more modest, closer to a 1 s difference.

@wtbarnes wtbarnes marked this pull request as ready for review September 27, 2024 01:37
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.47%. Comparing base (a896483) to head (2caf81f).
Report is 17 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #319   +/-   ##
=======================================
  Coverage   90.46%   90.47%           
=======================================
  Files          40       40           
  Lines        3367     3369    +2     
=======================================
+ Hits         3046     3048    +2     
  Misses        321      321           

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

@wtbarnes wtbarnes merged commit 545da0a into main Sep 27, 2024
14 checks passed
@wtbarnes wtbarnes deleted the fb-performance branch September 27, 2024 13:33
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.

Repeated outer products in free-bound emission calculation affect performance
1 participant