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

[WIP][Bug Fix] Fixing the pow method on qml.TShift #6356

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

willjmax
Copy link
Contributor

@willjmax willjmax commented Oct 7, 2024

This PR fixes issue #6355 by providing proper pow implementations for qml.TShift, qml.TAdd, and qml.TClock. Each of these operators implement pow in the following way.

def pow(self, z):
    return super().pow(z % 3)

This is calling the pow method on Operator which handles the cases for z==0 and z==1 but returns a PowUndefinedError for any other value of z. This leads to an error for TShift, TAdd, and TClock when raising to the second power. This PR implements the case when z is a non-negative integer by returning a list containing z copies of the operator.

Copy link
Contributor

github-actions bot commented Oct 7, 2024

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.

pennylane/operation.py Outdated Show resolved Hide resolved
@@ -168,7 +173,7 @@ def test_no_pow_ops(self, op):
assert len(op_pow) == 1
assert op_pow[0].__class__ == op.__class__

pows = [0.1, 2, -2, -2.5]
pows = [0.1, -2.5]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pows = [0.1, -2.5]
pows = [0.1, -2, -2.5]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-2 should not raise PowUndefinedError since -2 % 4 = 2 is what gets passed into pow which is now defined. Maybe this test is not necessary since THadamard is tested in test_period_two_three_noninteger_power 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the %4?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I just realized that this is a test for qutrit ops

pennylane/operation.py Outdated Show resolved Hide resolved
@willjmax willjmax changed the title [Bug Fix] Fixing the pow method on qml.TShift [WIP][Bug Fix] Fixing the pow method on qml.TShift Oct 8, 2024
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