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

Changed expect_g and fidelity_g to return the "correctly" scaled gradient w.r.t to the register #446

Merged
merged 2 commits into from
Dec 8, 2022

Conversation

jlbosse
Copy link
Contributor

@jlbosse jlbosse commented Dec 7, 2022

Up until now expect_g and fidelity_g were off by a factor of one half, in the sense that
∂_reg expect(ham, reg) = 2 * expect_g(ham, reg) instead ∂_reg expect(ham, reg) = expect_g(ham, reg) and analogous for the other methods of expect_g and fidelity_g. This was counter acted by multiplying a factor of 2 to the final paramsδ at the end of expect_g(ham, reg => circuit) and fidelity_g(reg1 => circuit1, reg2 => circuit2).

This is changed here to backpropagate the "correctly" scaled gradient w.r.t registers.

I am not sure if this would be considered a breaking change, because it also means that the output of expect'(ham, reg => circuit)[1] is changed by a factor of 2 now.

Changes:

  • Changed expect_g and fidelity_g
  • Updated the rrules in chainrules_patch.jl
  • Updated the corresponding tests

@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 88.28% // Head: 86.93% // Decreases project coverage by -1.35% ⚠️

Coverage data is based on head (30c388a) compared to base (9d7ab2e).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #446      +/-   ##
==========================================
- Coverage   88.28%   86.93%   -1.36%     
==========================================
  Files          76       16      -60     
  Lines        4765     1408    -3357     
==========================================
- Hits         4207     1224    -2983     
+ Misses        558      184     -374     
Impacted Files Coverage Δ
lib/YaoBlocks/src/autodiff/chainrules_patch.jl
lib/YaoBlocks/src/autodiff/specializes.jl
lib/YaoBlocks/src/measure_ops.jl
src/EasyBuild/hamiltonians.jl
lib/YaoBlocks/src/utils.jl
lib/YaoBlocks/src/abstract_block.jl
lib/YaoBlocks/src/treeutils/treeutils.jl
src/EasyBuild/qft_circuit.jl
lib/YaoBlocks/src/treeutils/dump.jl
lib/YaoBlocks/src/treeutils/load.jl
... and 50 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Roger-luo
Copy link
Member

need tests pass before a review

Copy link
Member

@GiggleLiu GiggleLiu left a comment

Choose a reason for hiding this comment

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

Looks good to me. The failure in the nightly test seems unrelated.

@jlbosse
Copy link
Contributor Author

jlbosse commented Dec 8, 2022

The tests fun on my local machines on julia 1.8.3 and 1.8.2 and are in parts of the tests that shouldn't be affected by my changes at all. So I also think that the failures on nightly are unrelated.

@GiggleLiu GiggleLiu merged commit 5dcbf74 into QuantumBFS:master Dec 8, 2022
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