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

Refactor ChainRulesCoreExt into separate files #133

Merged
merged 13 commits into from
Jul 2, 2024
Merged

Conversation

lkdvos
Copy link
Collaborator

@lkdvos lkdvos commented Jun 27, 2024

This refactors the chainrules extension into separate files.
In the meantime, I improved the test coverage a bit, and ironed out some type instabilities.

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 90.95023% with 20 lines in your changes missing coverage. Please review.

Project coverage is 82.57%. Comparing base (8b41fe3) to head (99f71c0).

Files Patch % Lines
ext/TensorKitChainRulesCoreExt/constructors.jl 53.84% 12 Missing ⚠️
ext/TensorKitChainRulesCoreExt/utility.jl 72.22% 5 Missing ⚠️
src/tensors/tensor.jl 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
+ Coverage   82.19%   82.57%   +0.37%     
==========================================
  Files          43       48       +5     
  Lines        5713     5710       -3     
==========================================
+ Hits         4696     4715      +19     
+ Misses       1017      995      -22     

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

return NoTangent(), NoTangent(), ∂t
end
return A, convert_pullback
end

function ChainRulesCore.rrule(::typeof(Base.convert), ::Type{Dict}, t::AbstractTensorMap)
out = convert(Dict, t)
function convert_pullback(c)
function convert_pullback(c′)
c = unthunk(c′)
if haskey(c, :data) # :data is the only thing for which this dual makes sense
Copy link
Owner

Choose a reason for hiding this comment

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

How about dual = typeof(out)(:data => c[:data]) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think that works, because then the spaces are missing in the dictionary-to-tensormap converter. Maybe the comment is a bit misleading -- all fields in the dictionary are required, but Zygote tends to drop fields that do not contribute (i.e. codomain and domain). Thus, this uses the dictionary from the forwards pass with the data from the backwards pass.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok. I wanted to avoid copying the data from out, but probably copy(out) is a shallow copy that does not duplicate out[:data]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it should really only duplicate the pointer, which I think is acceptable. On top of that, I am not sure this rule is ever used/useful anyways. I think I copied this at some point from maarten, but presumably that was also only introduced for testing purposes, as it also suffers from the weird interplay of "inner product on the parameters" for non-abelian symmetries.

src/tensors/tensor.jl Outdated Show resolved Hide resolved
src/tensors/tensor.jl Outdated Show resolved Hide resolved
@lkdvos lkdvos force-pushed the refactor-chainrules branch from b0e8230 to 99f71c0 Compare July 2, 2024 06:31
@Jutho Jutho merged commit 1331067 into master Jul 2, 2024
14 checks passed
@lkdvos lkdvos deleted the refactor-chainrules branch July 2, 2024 16:17
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.

2 participants