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

Fix qml.GellMann observable data #4366

Merged
merged 4 commits into from Jul 18, 2023
Merged

Fix qml.GellMann observable data #4366

merged 4 commits into from Jul 18, 2023

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Jul 18, 2023

Context:
Fixes #4341 .

Description of the Change:

  • Update Observable._obs_data() to include the index of qml.GellMann in the parameter list.
  • Update Hamiltonian._obs_data() to include the index of qml.GellMann in the parameter list.

Note:
I would still recommend using the new operator arithmetic with qutrits. The generators of parametric qutrit gates are instances of Prod and Sum, not qml.Hamiltonian. So, try using qml.dot instead of qml.Hamiltonian with qutrit observables.

Benefits:
Comparison of instances of qml.GellMann, Hamiltonians and Tensors containing qml.GellMann is correct.

Possible Drawbacks:

Related GitHub Issues:
#4341

@mudit2812 mudit2812 requested a review from a team July 18, 2023 14:49
@mudit2812
Copy link
Contributor Author

[sc-41597]

@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Merging #4366 (55cf2b7) into master (fa58441) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4366   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         351      351           
  Lines       32407    32411    +4     
=======================================
+ Hits        32334    32338    +4     
  Misses         73       73           
Impacted Files Coverage Δ
pennylane/pulse/parametrized_evolution.py 96.55% <ø> (ø)
pennylane/pulse/transmon.py 100.00% <ø> (ø)
pennylane/operation.py 96.81% <100.00%> (+<0.01%) ⬆️
pennylane/ops/qubit/hamiltonian.py 100.00% <100.00%> (ø)

@timmysilv
Copy link
Contributor

being honest, I don't love seeing qml.GellMan in such base/unrelated files as operation.py and hamiltonian.py. Did you consider any other ways of getting this done? I do appreciate how concise the change is, but it seems like a circular dependency that we kinda just get away with today.

@mudit2812
Copy link
Contributor Author

mudit2812 commented Jul 18, 2023

it seems like a circular dependency that we kinda just get away with today.

I agree, and I wasn't particularly happy with the change. I tried just overloading GellMann._obs_data() but both Hamiltonian and Observable _obs_data supersede it. The alternate solution is to always use new op math, which I've recommended in the PR description as well.

If we want to correctly support it in Hamiltonian, adding a special case for it would be required as there are no other observables which justify having hyperparameters stored in _obs_data. That being said, I think that saying "Don't use Hamiltonian; use qml.dot" is also a valid solution.

@timmysilv
Copy link
Contributor

do we need to plan anything to have this removed in the future? I suspect it will happen naturally once we switch to arithmetic ops everywhere since that seems to be the only place this is used (Sum/Prod aren't even Observable objects!)

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.

given the circumstances, adding 2 lines in each file ain't too bad. thanks for 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.

Simple enough fix.

Would this actually work in a measurement?

@mudit2812
Copy link
Contributor Author

Would this actually work in a measurement?

It should. The issue was that calling Hamiltonian.simplify relied on Hamiltonian.compare, which was not taking the index of GellMann into account. Since this change is contained to one exception in terms of comparison for GellMann, measurements shouldn't be affected. Moreover, support for Hamiltonian measurements is basically non-existent in default.qutrit, so it doesn't really matter that much.

@mudit2812 mudit2812 enabled auto-merge (squash) July 18, 2023 21:18
@mudit2812 mudit2812 merged commit d28df54 into master Jul 18, 2023
43 checks passed
@mudit2812 mudit2812 deleted the gm-hamiltonian branch July 18, 2023 21:50
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] op_math adding two GellMann observables doesn't treat them as different Hermitians
3 participants