Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add tensor unwrapping in BaseQNode for keyword arguments #903
Add tensor unwrapping in BaseQNode for keyword arguments #903
Changes from 9 commits
eff75df
16d7379
dba1b7f
41b799c
515ffef
64f7b89
98b14d5
315917a
f0e513b
d95ed03
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This had to be changed because
pennylane.numpy.tensor
objects are accepted types here (no check for the type of the elements contained):pennylane/pennylane/templates/subroutines/uccsd.py
Line 176 in cf8fe64
With the unwrapping this changed as we'd have a real
ndarray
instead of apennylane.numpy.tensor
object: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.
@antalszava I have to admit, I don't follow the above comment 🤔
How come the first check pass, but the second one fails, in the example?
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.
This test case tests that the UCCSD template will raise an error when supplied
np.array([1.2, 1, 0, 0])
as the initial state.Previously:
This test case passed because the expected error was raised by the call on line 206 due to the call to
qml.BasisState
.pennylane/pennylane/templates/subroutines/uccsd.py
Line 206 in cf8fe64
However, conceptually speaking the check on line 176 using
check_type
(linked in the previous comment) should have actually already raised an error. It is meant to check that elements ofinit_state
are integer types. However, since it also allowsnp.ndarray
as an accepted type, it passes for single element PennyLane tensor objects because if we received anp.ndarray
we don't further check the type of the element contained. Therefore, when we passednp.array([1.2, 1, 0, 0])
as a PennyLane tensor and indexed into it using thefor
loop, this check passes.The snippet in the previous comment proves that this check indeed passes for a PennyLane tensor, but fails for an original
ndarray
. The following is the output of the snippet by addingprint('Type of element: ', type(i))
right before thecheck_type
call:It might be worth revisiting the edge cases for the check using
check_type
, although I would argue that that is out of scope for this PR.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.
Got it! thanks Antal
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.
💯