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

BugFix: Controlled.generator correctly projects with control values #5068

Merged
merged 17 commits into from
Jan 16, 2024

Conversation

astralcai
Copy link
Contributor

@astralcai astralcai commented Jan 15, 2024

Context:

Controlled.generator always projects onto the $\ket{1}$ space of the control wire without considering control values.

Description of the Change:

Now Controlled.generator correctly projects the operator based on the control value specified

Benefits:

Fixes a bug

@astralcai astralcai requested a review from a team January 15, 2024 20:55
@astralcai astralcai marked this pull request as ready for review January 15, 2024 20:56
Copy link

codecov bot commented Jan 15, 2024

Codecov Report

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

Comparison is base (c01cb4b) 99.67% compared to head (116ef54) 99.66%.
Report is 19 commits behind head on master.

Files Patch % Lines
pennylane/workflow/jacobian_products.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5068      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         394      394              
  Lines       35670    35461     -209     
==========================================
- Hits        35554    35343     -211     
- Misses        116      118       +2     

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

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.

We should also add some tests to ensure this definition of the generator agrees with the qml.exp(op.generator(), 1j*op.data[0]) convention for a generator. op and that exponential operator should have the same form.

We could potentially even add this check to assert_valid:

https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/ops/functions/assert_valid.py

to test generators more generally, but for now we should just check those two forms have the same matrix.

@astralcai
Copy link
Contributor Author

We should also add some tests to ensure this definition of the generator agrees with the qml.exp(op.generator(), 1j*op.data[0]) convention for a generator. op and that exponential operator should have the same form.

We could potentially even add this check to assert_valid:

https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/ops/functions/assert_valid.py

to test generators more generally, but for now we should just check those two forms have the same matrix.

I added a quick check for this in the test case, is checking matrix equivalence the proper way of doing this?

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.

Thanks for finding this and making a fix 🎉

Copy link
Contributor

@timmysilv timmysilv 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) January 16, 2024 22:28
@astralcai astralcai merged commit e264f4f into master Jan 16, 2024
34 of 35 checks passed
@astralcai astralcai deleted the ctrl-generator branch January 16, 2024 22:46
mudit2812 pushed a commit that referenced this pull request Jan 19, 2024
…5068)

**Context:**

`Controlled.generator` always projects onto the $\ket{1}$ space of the
control wire without considering control values.

**Description of the Change:**

Now `Controlled.generator` correctly projects the operator based on the
control value specified

**Benefits:**

Fixes a bug

---------

Co-authored-by: Christina Lee <christina@xanadu.ai>
@Alex-Preciado
Copy link
Contributor

Alex-Preciado commented Jan 19, 2024

Awesome!! Just Linking to Shortcut story: [sc-55065]

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.

4 participants