-
Notifications
You must be signed in to change notification settings - Fork 627
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 devices.qubit.apply_operation
with large tf states
#3884
Conversation
apply_times.txt n_dim = qml.math.ndim(state)
if n_dim >= 9 and qml.math.get_interface(state) == "tensorflow":
return apply_operation_tensordot(op, state) I think this is better for a few reasons:
|
@timmysilv Thanks for running those benchmarks. I've updated the code to to check first. |
Codecov Report
@@ Coverage Diff @@
## master #3884 +/- ##
=======================================
Coverage 99.71% 99.71%
=======================================
Files 341 341
Lines 29810 29814 +4
=======================================
+ Hits 29724 29728 +4
Misses 86 86
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Christina! Are there any other interfaces such as torch that might also share the slicing trouble?
[sc-34873] |
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
This problem was found when writing tests for #3862 . All other interfaces passed those tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Christina!
@@ -111,7 +111,10 @@ | |||
|
|||
* Made `qml.OrbitalRotation` and consequently `qml.GateFabric` consistent with the interleaved Jordan-Wigner ordering. | |||
[(#3861)](https://github.com/PennyLaneAI/pennylane/pull/3861) | |||
|
|||
|
|||
* `qml.devices.qubit.apply_operation` catches the `tf.errors.UnimplementedError` that occurs when `PauliZ` or `CNOT` gates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i realize this isn't the most fitting changelog entry anymore... maybe let's sneak a touch-up into another PR?
* fix apply operation with large tf states * black and changelog * change back order in multiply function * check first instead of catching error * Update pennylane/devices/qubit/apply_operation.py Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> * Update pennylane/devices/qubit/apply_operation.py Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> --------- Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Tensorflow doesn't support slicing on states with more than 8 dimensions. So if we try and run the code:
We get:
Since this case is exceptional, and we do not want to slow down the standard logical slow, I implemented fallback logic using try-except blocks.
If the error is a
tf.errors.UnimplementedError
, we fall back toapply_operation_tensordot
.This will probably have performance implications for applying PauliZ and CNOT on large states, but at least it won't affect the performance in cases where the error does not occur.
Blocks testing for #3862