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

fallback to scipy when linalg.matrix_power isn't available #4827

Merged
merged 6 commits into from Nov 16, 2023

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Nov 10, 2023

Context:
Tensorflow does not have a matrix_power function. For non-int powers, we always fall back to scipy, and we noticed that this works with Tensorflow as well! We can use this...

Description of the Change:

  • Whenever trying to raise TF matrices to an integer matrix-power, use scipy.linalg.fractional_matrix_power. Until today, we just raised an error. Pow is not trainable regardless, so there's no harm in adding this.
  • This also indirectly allowed for raising any QubitUnitary to a non-int power (eg: qml.QubitUnitary(np.eye(2), wires=[0]).pow(3.5))

Benefits:
Less errors! more features!

Possible Drawbacks:

  • Still not differentiable
  • QubitUnitary.pow looks more complex to support more stuff

Related GitHub Issues:
Fixes #4825 [sc-49952]

@timmysilv timmysilv requested review from a team and KetpuntoG November 10, 2023 22:05
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (456d98e) 99.66% compared to head (47c33d6) 99.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4827      +/-   ##
==========================================
- Coverage   99.66%   99.65%   -0.01%     
==========================================
  Files         382      382              
  Lines       34468    34213     -255     
==========================================
- Hits        34351    34095     -256     
- Misses        117      118       +1     

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

@timmysilv timmysilv requested a review from a team November 14, 2023 14:53
Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

🚀

@timmysilv timmysilv enabled auto-merge (squash) November 16, 2023 19:12
@timmysilv timmysilv merged commit 8edac6f into master Nov 16, 2023
33 checks passed
@timmysilv timmysilv deleted the tf-matrix-power branch November 16, 2023 19:25
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] qml.pow() is not working properly with the interfaces
3 participants