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

Fixing missing hyperparameters of GlobalPhase #6940

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

Conversation

JerryChen97
Copy link
Contributor

Context:
qml.GlobalPhase does not set its hyperparameters during initialization. This caused certain bugs, e.g.

>>> np.allclose(qml.GlobalPhase(0.123).matrix(), qml.GlobalPhase(0.123).sparse_matrix().toarray())
False
>>> qml.GlobalPhase(0.123).matrix().shape
(1, 1)
>>> qml.GlobalPhase(0.123).sparse_matrix().shape
(2, 2)
>>> qml.GlobalPhase(0.123).matrix()
array([[0.99244503-0.12269009j]])
>>> qml.GlobalPhase(0.123).sparse_matrix().toarray()
array([[0.99244503-0.12269009j, 0.        +0.j        ],
       [0.        +0.j        , 0.99244503-0.12269009j]])

where GlobalPhase.sparse_matrix() did the calculation wrongly because it never received correct n_wires from hyperparameters, which is required by the base class Operator

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@JerryChen97 JerryChen97 marked this pull request as ready for review February 7, 2025 21:15
@JerryChen97 JerryChen97 self-assigned this Feb 7, 2025
Copy link
Contributor

github-actions bot commented Feb 7, 2025

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/ops/identity.py Outdated Show resolved Hide resolved
pennylane/ops/identity.py Outdated Show resolved Hide resolved
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.

1 participant