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

fft notebook #409

Merged
merged 33 commits into from
Aug 22, 2023
Merged

fft notebook #409

merged 33 commits into from
Aug 22, 2023

Conversation

samjrholt
Copy link
Member

@samjrholt samjrholt commented Aug 3, 2023

Dependent on:

Summary by CodeRabbit

  • New Feature: Improved performance of the Fast Fourier Transform (FFT) functionality by utilizing the faster scipy library and optimizing computation.
  • Documentation: Added a comment to explain the purpose of a code block in discretisedfield/mesh.py.
  • Test: Enhanced test coverage for FFT calculations in discretisedfield/tests/test_field.py, ensuring correctness in various scenarios.
  • Refactor: Adjusted the axes parameter in certain functions of discretisedfield/field.py to exclude the last axis, improving computation efficiency.
  • Chore: Imported scipy.fft module as spfft in discretisedfield/tests/test_field.py.

These changes collectively improve the performance and reliability of the code while maintaining compatibility with the external interface.

@samjrholt samjrholt linked an issue Aug 3, 2023 that may be closed by this pull request
3 tasks
@samjrholt
Copy link
Member Author

@lang-m When you get a chance could you please look through this. There may be a bug in rfft as the peak in the spectrum is not in the same place.

So the current example is probably more useful for people doing micromagnetics but I also considered changing the example to 2 spatial dimensions and a scalar field as this simplifies the code/plots a little.

@samjrholt
Copy link
Member Author

I have fixed the bug in #410. Please review that first and then merge into this one then please review this.

@samjrholt samjrholt mentioned this pull request Aug 4, 2023
3 tasks
@samjrholt samjrholt removed a link to an issue Aug 4, 2023
3 tasks
Copy link
Member

@lang-m lang-m left a comment

Choose a reason for hiding this comment

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

The notebook looks really good. Here is some preliminary feedback from a first review. I'll go over it again more thoroughly after reviewing and merging the bug fix.

docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Show resolved Hide resolved
samjrholt and others added 6 commits August 7, 2023 08:30
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 94.62% and project coverage change: -3.53% ⚠️

Comparison is base (dfbfdb5) 96.87% compared to head (9f1c19a) 93.35%.
Report is 1163 commits behind head on master.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #409      +/-   ##
==========================================
- Coverage   96.87%   93.35%   -3.53%     
==========================================
  Files          28       28              
  Lines        2498     2933     +435     
==========================================
+ Hits         2420     2738     +318     
- Misses         78      195     +117     
Files Changed Coverage Δ
discretisedfield/field.py 87.01% <ø> (-9.94%) ⬇️
discretisedfield/interact.py 100.00% <ø> (ø)
discretisedfield/plotting/util.py 92.94% <66.66%> (-4.32%) ⬇️
discretisedfield/plotting/k3d_mesh.py 95.00% <75.00%> (-5.00%) ⬇️
discretisedfield/plotting/mpl_field.py 85.85% <83.13%> (-3.27%) ⬇️
discretisedfield/plotting/k3d_region.py 96.00% <83.33%> (-4.00%) ⬇️
discretisedfield/io/hdf5.py 85.33% <88.23%> (-14.67%) ⬇️
discretisedfield/plotting/mpl_region.py 96.77% <88.88%> (-3.23%) ⬇️
discretisedfield/io/__init__.py 89.28% <89.28%> (-10.72%) ⬇️
discretisedfield/plotting/k3d_field.py 95.03% <94.44%> (-0.07%) ⬇️
... and 14 more

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

docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
@samjrholt samjrholt requested a review from lang-m August 9, 2023 06:41
@samjrholt samjrholt self-assigned this Aug 10, 2023
Copy link
Member

@lang-m lang-m left a comment

Choose a reason for hiding this comment

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

Final review for the first part of the notebook (anything before "Visualising and analysing FFTs"). I have added some more suggestions and minor corretions.

I'll try to also review the second half of the notebooks soon.

docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Show resolved Hide resolved
docs/field-fft.ipynb Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2023

Image description CodeRabbit

Walkthrough

The changes made to the codebase focus on improving the Fast Fourier Transform (FFT) functionality in the discretisedfield module. The modifications include utilizing the faster scipy library for computation, optimizing the computation by excluding unnecessary axes, adding comments for code clarity, and enhancing the test coverage for FFT calculations. These changes collectively improve the performance, maintainability, and correctness of the code.

Changes

File Summary
discretisedfield/field.py - Use scipy library for faster computation.
- Adjust axes parameter to exclude the last axis in certain functions.
discretisedfield/mesh.py Add a comment to explain the purpose of a code block.
discretisedfield/tests/test_field.py - Import scipy.fft module as spfft.
- Modify or remove assertions related to FFT calculations.
- Add additional tests for FFT calculations, including testing 1D rfft and rfftn with no shift in the last dimension.
- Create a new field a with specific values and compare its FFT with the expected result using scipy.fft.rfftn.

"With scipy we dance,

Faster FFT, a chance.

Axes trimmed, code refined,

Comments clear, peace of mind.

Tests expanded, correctness assured,

Rabbit's joy, code's allure." 🐇✨


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version.

samjrholt and others added 9 commits August 17, 2023 10:29
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
Copy link
Member

@lang-m lang-m left a comment

Choose a reason for hiding this comment

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

Some additional minor comments for the second half of the notebook.

Feel free to merge once all open comments are addressed.

Edit: several of the comments seem to be off by one line (not sure how that has happened). I hope they all make sense. Directly applying the suggestions of course doesn't work for these.

docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
docs/field-fft.ipynb Outdated Show resolved Hide resolved
samjrholt and others added 3 commits August 22, 2023 15:16
Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com>
@samjrholt samjrholt merged commit 86b4390 into master Aug 22, 2023
1 of 4 checks passed
@samjrholt samjrholt deleted the fft_notebook branch August 22, 2023 13:40
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.

3 participants