QuantumBFS / Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.
https://yaoquantum.org
Other
918 stars 119 forks source link

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

Closed jlbosse closed 1 year ago

jlbosse commented 1 year ago

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:

codecov[bot] commented 1 year ago

Codecov Report

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

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

Additional details and impacted files ```diff @@ 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](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS) | Coverage Δ | | |---|---|---| | [lib/YaoBlocks/src/autodiff/chainrules\_patch.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvYXV0b2RpZmYvY2hhaW5ydWxlc19wYXRjaC5qbA==) | | | | [lib/YaoBlocks/src/autodiff/specializes.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvYXV0b2RpZmYvc3BlY2lhbGl6ZXMuamw=) | | | | [lib/YaoBlocks/src/measure\_ops.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvbWVhc3VyZV9vcHMuamw=) | | | | [src/EasyBuild/hamiltonians.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL0Vhc3lCdWlsZC9oYW1pbHRvbmlhbnMuamw=) | | | | [lib/YaoBlocks/src/utils.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvdXRpbHMuamw=) | | | | [lib/YaoBlocks/src/abstract\_block.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvYWJzdHJhY3RfYmxvY2suamw=) | | | | [lib/YaoBlocks/src/treeutils/treeutils.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvdHJlZXV0aWxzL3RyZWV1dGlscy5qbA==) | | | | [src/EasyBuild/qft\_circuit.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL0Vhc3lCdWlsZC9xZnRfY2lyY3VpdC5qbA==) | | | | [lib/YaoBlocks/src/treeutils/dump.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvdHJlZXV0aWxzL2R1bXAuamw=) | | | | [lib/YaoBlocks/src/treeutils/load.jl](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-bGliL1lhb0Jsb2Nrcy9zcmMvdHJlZXV0aWxzL2xvYWQuamw=) | | | | ... and [50 more](https://codecov.io/gh/QuantumBFS/Yao.jl/pull/446/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS)

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

Roger-luo commented 1 year ago

need tests pass before a review

jlbosse commented 1 year ago

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.