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

Change for loop calculating OPD from Zernikes to an Einstein sum. #400

Merged
merged 1 commit into from Feb 26, 2021

Conversation

grbrady
Copy link

@grbrady grbrady commented Feb 25, 2021

I change a for loop in the opd_from_zernikes function in Zernikes.py to an Einstein sum. This produced a significant speedup in code that I wrote (JWST field dependence model in WebbPSF) that uses the function heavily. This employs the Numpy einsum function, which is a highly optimized, multithreaded implementation. Possibly downside is that the Einstein sum notation is a little less readable to most people.

…code that uses opd_from_zernikes heavily this can produce a significant speedup since einsum is a highly optimized, multithreaded function.
@grbrady grbrady marked this pull request as draft February 25, 2021 06:39
@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #400 (2632004) into develop (bf0531d) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #400      +/-   ##
===========================================
- Coverage    74.21%   74.20%   -0.01%     
===========================================
  Files           17       17              
  Lines         5829     5827       -2     
===========================================
- Hits          4326     4324       -2     
  Misses        1503     1503              
Impacted Files Coverage Δ
poppy/zernike.py 82.65% <100.00%> (-0.09%) ⬇️

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 bf0531d...2632004. Read the comment docs.

@grbrady grbrady marked this pull request as ready for review February 25, 2021 06:39
@grbrady
Copy link
Author

grbrady commented Feb 25, 2021

I can't seem to explicitly add a reviewer to this pull request. Will follow-up with Marshall or Shannon as to whether this is a problem.

Copy link
Collaborator

@mperrin mperrin left a comment

Choose a reason for hiding this comment

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

👍 A nice optimization, thanks @grbrady

Some benchmarks from calls to opd_from_zernikes show 2x or better speedup:

# zernikes Npix using for loop using einsum
36 512 21.7 ms 10.8 ms
36 1024 116 ms 49.1 ms
78 1024 235 ms 87.4 ms

@mperrin mperrin merged commit e0793cc into spacetelescope:develop Feb 26, 2021
@robelgeda robelgeda mentioned this pull request Feb 27, 2021
@mperrin mperrin added this to the 1.0.0 milestone Mar 26, 2021
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.

None yet

2 participants