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

Add generator checks and differentiability checks to assert_valid #6282

Merged
merged 47 commits into from
Oct 8, 2024

Conversation

astralcai
Copy link
Contributor

@astralcai astralcai commented Sep 19, 2024

The purpose of this story is to check if every operator can be differentiated properly with the parameter shift method. The gradient calculated using parameter shift is compared with backprop to verify that they are equal.

There are some cases where this does not apply:

  1. Backprop does not produce the correct gradient in some cases such as for StatePrep and for QubitUnitary, as it does not take into account the constraint that the matrix must remain unitary, making this test invalid.
  2. Some operator takes integers as parameters, such as BasisState. In this case, it does not make sense to take the gradient of integer parameters.

For these cases, a skip_differentiation toggle is added to assert_valid such that the differentiation check is skipped for these operators.

Three bugs are found as a result of adding this check. The relevant tests are xfailed:
#6331
#6333
#6340

Some other minor bug fixes are also included in this PR.

[sc-65197]
Fixes #6311

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@astralcai astralcai changed the title Add generator checks and differentiability checks to assert_valid [WIP] Add generator checks and differentiability checks to assert_valid Sep 19, 2024
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.40%. Comparing base (6c6b80f) to head (5ff3b1e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6282   +/-   ##
=======================================
  Coverage   99.39%   99.40%           
=======================================
  Files         446      446           
  Lines       42328    42358   +30     
=======================================
+ Hits        42073    42104   +31     
+ Misses        255      254    -1     

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

@astralcai astralcai changed the title [WIP] Add generator checks and differentiability checks to assert_valid Add generator checks and differentiability checks to assert_valid Oct 3, 2024
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Other than a changelog entry , everything looks good to me 👍

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

This looks great to me. Just a couple of questions

pennylane/ops/functions/assert_valid.py Outdated Show resolved Hide resolved
pennylane/ops/functions/assert_valid.py Outdated Show resolved Hide resolved
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni 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!

@astralcai astralcai enabled auto-merge (squash) October 8, 2024 13:42
@astralcai astralcai merged commit c6476bb into master Oct 8, 2024
36 checks passed
@astralcai astralcai deleted the assert-valid branch October 8, 2024 20:40
austingmhuang pushed a commit that referenced this pull request Oct 23, 2024
)

The purpose of this story is to check if every operator can be
differentiated properly with the parameter shift method. The gradient
calculated using parameter shift is compared with backprop to verify
that they are equal.

There are some cases where this does not apply:
1. Backprop does not produce the correct gradient in some cases such as
for `StatePrep` and for `QubitUnitary`, as it does not take into account
the constraint that the matrix must remain unitary, making this test
invalid.
2. Some operator takes integers as parameters, such as `BasisState`. In
this case, it does not make sense to take the gradient of integer
parameters.

For these cases, a `skip_differentiation` toggle is added to
`assert_valid` such that the differentiation check is skipped for these
operators.

Three bugs are found as a result of adding this check. The relevant
tests are xfailed:
#6331
#6333
#6340

Some other minor bug fixes are also included in this PR.

[sc-65197]
Fixes #6311
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.

[BUG] Definition of generator for Evolution inconsistent with the convention
3 participants