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] Fix qml.lie_closure by using SVD based linear independence check #6232

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

Conversation

Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Sep 6, 2024

fixes #6065

Additionally introduces normalization of vectors to avoid exploding coefficients
Could alternatively also introduce orthonormalization with orthonormal_basis = U[:, :rank] in the SVD step, but I dont think this is necessary.

@Qottmann Qottmann marked this pull request as ready for review September 6, 2024 12:36
@Qottmann
Copy link
Contributor Author

Qottmann commented Sep 6, 2024

@dwierichs @vincentmr tagged you for review, but no rush on this. I did this change on my local research branch and found it to work quite well.

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.70%. Comparing base (de54c54) to head (7529e1b).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6232   +/-   ##
=======================================
  Coverage   99.70%   99.70%           
=======================================
  Files         444      444           
  Lines       42133    42134    +1     
=======================================
+ Hits        42008    42009    +1     
  Misses        125      125           

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

Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

We now have

eps = 1e-3
g = qml.lie_closure([X(0), X(0) + eps * Y(0)])
>> [X(0), X(0) + 1e-03 * Y(0), 1e-03 * Z(0)]

but

eps = 1e-9
g = qml.lie_closure([X(0), X(0) + eps * Y(0)])
>> [X(0), X(0) + 1e-09 * Y(0)]

This is because the commutator is nullified by com.simplify() in lie_closure. Should we pass tol along to obtain a more consistent or predictable behaviour?
Similarly,

eps = 1e-5
g = qml.lie_closure([X(0), X(0) + eps * Y(0)], tol=1e-2)
>> [X(0)]

but

eps = 1e-5
g = qml.lie_closure([X(0), X(0) + eps * Y(0)], tol=1e-3)
>> [X(0), X(0) + 1e-05 * Y(0), 1e-05 * Z(0)]

which looks unintuitive to me.

pennylane/pauli/dla/lie_closure.py Outdated Show resolved Hide resolved
@dwierichs
Copy link
Contributor

Should we pass tol along to obtain a more consistent or predictable behaviour?

I agree that we should do this: If a user wants to take care of tolerances themselves, they should be able to do so consistently

which looks unintuitive to me.

For default tolerances, I think we can give our best to create a consistent default, but if there are hickups in edge cases, I'd personally say that's fine :)
Regarding your last code snippet, @vincentmr , I can't seem to reproduce it (the result is just [X(0)] for both tol values passed to lie_closure.

@vincentmr
Copy link
Contributor

Regarding your last code snippet, @vincentmr , I can't seem to reproduce it (the result is just [X(0)] for both tol values passed to lie_closure.

You're right, I reinstalled PennyLane in a fresh venv and the effect went away. Never mind that.

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Nice upgrade @Qottmann!
I had a few small comments to be addressed :)

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/pauli/dla/lie_closure.py Outdated Show resolved Hide resolved
tests/pauli/dla/test_lie_closure.py Show resolved Hide resolved
@Qottmann
Copy link
Contributor Author

Thanks for the great feedback @vincentmr and @dwierichs !

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

LGTM! Nice upgrade @Qottmann 💯

@dwierichs
Copy link
Contributor

This fix was unblocking some research I was doing today, might be nice to get in soon :)

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.

LGTM! Just a small suggestion for the changelog : )

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@Qottmann Qottmann enabled auto-merge (squash) September 20, 2024 13:30
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.

qml.lie_closure often raises LinAlgError: Singular matrix
4 participants