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

Fix periodic kernel AD #531

Merged
merged 21 commits into from
Feb 7, 2024
Merged

Fix periodic kernel AD #531

merged 21 commits into from
Feb 7, 2024

Conversation

simsurace
Copy link
Member

This PR reactivates the AD tests for the periodic kernel and introduces rrules to make them pass.
Fixes #527

@simsurace simsurace requested a review from theogf October 16, 2023 09:48
@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (3b7a2df) 90.34% compared to head (774ac73) 67.81%.

Files Patch % Lines
src/chainrules.jl 80.95% 16 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #531       +/-   ##
===========================================
- Coverage   90.34%   67.81%   -22.54%     
===========================================
  Files          52       52               
  Lines        1378     1454       +76     
===========================================
- Hits         1245      986      -259     
- Misses        133      468      +335     

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

src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
test/basekernels/periodic.jl Outdated Show resolved Hide resolved
simsurace and others added 8 commits October 16, 2023 11:50
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
xi = view(x, i, :)
xj = view(x, j, :)
ds = twoπ .* Δ[i, j] .* sinpi.(xi .- xj) .* cospi.(xi .- xj) ./ d.r .^ 2
r̄ .-= 2 .* Δ[i, j] .* sinpi.(xi .- xj) .^ 2 ./ d.r .^ 3
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that rbar supports setindex! which is not true in general.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in this case, it is because the field of Sinus is a Vector.

test/chainrules.jl Outdated Show resolved Hide resolved
@simsurace
Copy link
Member Author

Ok, I added ChainRulesTestUtils tests for normal and static arrays. The static case is certainly not optimal, but I don't have the capacity to think of how to rewrite the rules to be non-mutating.

If anyone knows off-hand how to do this, feel free to make a suggestion.

test/chainrules.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
simsurace and others added 3 commits October 30, 2023 12:49
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/chainrules.jl Outdated Show resolved Hide resolved
simsurace and others added 2 commits February 6, 2024 19:42
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@simsurace
Copy link
Member Author

simsurace commented Feb 6, 2024

@willtebbutt Could we merge this? The comment regarding the generality of the rule does not I apply (I believe) because of the concrete type of the field of Sinus. The failures are unrelated, see #526.

@simsurace simsurace added the bug Something isn't working label Feb 6, 2024
@simsurace simsurace mentioned this pull request Feb 6, 2024
15 tasks
@willtebbutt
Copy link
Member

I have no objection to merging. @devmotion do you have thoughts?

@simsurace simsurace merged commit 49049b1 into master Feb 7, 2024
16 of 22 checks passed
@simsurace simsurace deleted the fix-periodic branch February 7, 2024 12:22
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

A few additional suggestions.

src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
src/chainrules.jl Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PeriodicKernel does not play with AD
3 participants