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
Help device plugin developers deal with the Operation refactor #2210
Comments
Thanks @cvjjm for reporting this! Just double checking, but is From having a look at your code, def decomposition(self, *params, wires=None):
if wires is None:
wires = self.wires
if not params:
params = self.parameters
qml.RY(params[0], wires=wires[0])
qml.PauliZ(wires=wires[0])
qml.RX(params[1], wires=wires[0]) is a nice (and relatively simply to read) workaround, I'll see if there is a nice way to catch this (might mean tracking down everywhere that |
I've created a PR (#2214) to fix this :) |
I think the similar problems will occur with other refactored method. I also have a few other issues that I will report once I understand them better. |
Here is another facet of this problem: When using the current mater with an old style Operation that defines its matrix via the old style In particular the user is not even told which operation caused this error. As this error is raised in Side remark: It strikes me as slightly odd that |
And another issue is that |
@cvjjm yep, the only reason for this is the need to take into account for the inverse in the middle of the logic, making it difficult to use pennylane/pennylane/operation.py Lines 1302 to 1303 in fc96309
Having said that, we are still in the process of the operator refactor, unfortunately! There are a couple more changes likely coming down the line in v0.23 (since we are unable to finish them all in time for one release):
Regarding this last point, what this means is that One option will be a function along the lines of One benefit of a function is that (as you've noticed!) it is a lot easier to evolve and deprecate functions that it is with class methods 😆 Another benefit is that the function would be able to act on various inputs, including QNodes, tapes, etc., not just operations.
Let me explore this in a PR.
This is another case where |
Thanks for the explanations. This sounds all great! One remark on the scalar multiplication: I may be misunderstanding this, but |
This is the plan yes, but with a caveat: it is likely the So The reason for this is that we ran into too many issues where A deeper problem was that the fact that |
Yes, that sounds perfect. Looking forward to that new functionality! |
The one last idea: You are currently using a tuple of two lists to represent the terms, which I subjectively find a but "cumbersome". I.e. to determine the number of terms one has to first take, e.g., the first element of that tuple and then call |
And here is another problem I encountered with the refactor: As with the |
We haven't, but good to get this feedback since this is all still TBD! Would it fit your workflow if this was a simple class containing two lists? We then have the flexibility to add convenience methods such as e.g., to return the nth term (operator + coeff) as well as mappings |
A simple class would certainly also do the job, but why re-invent the wheel? A |
@cvjjm thanks for your valuable feedback! Just coming in real quick here to clarify something general. As discussed before, unfortunately we cannot consider developers' aim to support multiple versions of PennyLane. This has never been a goal of PennyLane dev, and it is not an industry standard - it was mere chance that this was possible before. It would also require an disproportional amount of resources, especially for refactors, and may often just mean that PennyLane cannot develop as a library, which no one would benefit from in the long run. But, of course, we will try our very best to allow for at least one deprecation cycle, so there is time to adapt. I hope there was no misunderstanding there. I think some issues you raise here are still valid (since a deprecation cycle is a kind of "two-version-support"). But just to get the shared goal clear, and to avoid disappointment! |
Yes, agree. There is no need to make extra efforts to support a broad range of versions, but some sort of deprecation cycle of one or two releases, depending on the magnitude of changes, would be healthy (imho) and much appreciated. |
Summing up the thread above and the things I have learned while trying to make my
|
I plan to have a PR merged before 0.22 that:
I'll have to think if there are any implications here - one reason for preferring
I'm not 100% I follow here - are you wishing to call a class method from inside @staticmethod
def compute_matrix(*params, wires, **hyperparameters):
return SomeOperatorClass.a_class_method() |
Yes.
Yes, but repeating the class name in the function is not nice and does not play well with inheritance. But, yes this is a workaround in case caching does clash with |
Thanks for clarifying! I suppose one other option is to override |
The top level There remains the problem that You invested quite a lot of effort renaming other functions such as |
Hey @cvjjm! Apologies, I think I misunderstood previous discussion. I thought you had code that worked with both styles, it was just ugly? #2210 (comment) |
Ah, I missed a later comment: #2210 (comment) |
Actually my comment #2210 (comment) was written before I talked to @dwierichs . He mentioned that he thinks that if the code using PL consistently only uses the new top level |
@cvjjm nice, let me know how the testing goes |
I can confirm that this works! Awesome! So me and other plugin developers actually have a good update path! Thanks for making this possible! |
Nice to hear @cvjjm! |
Feature details
As was discussed in #2023 with @josh146 and @mariaschuld in the light of the
Operation
refactor a smooth transition with useful deprecation warnings should be ensured so that device developers have time to update their devices and customOperation
s and support at least a few versions of PennyLane.Currently this has not been fully achieved.
Assume that some third party code (e.g a device plugin) defines a "old style" custom
Operation
as follows:This works until v0.21.0 but with master the user gets the unspecific error message:
Converting the implementation to "new style" will break the code with all PL versions prior to and including v0.21.0.
This is not nice.
Due to the smart re-naming of functions in #2023 it is indeed possible to define the above operation in a way that is compatible with both the old and the new style:
Alternatively one can also directly implement the new
compute_decomposition()
and patch in a suitablepreparation()
if one is running on an old PL version. The following also works with both 0.21 and the current master:There are of course a few further variants...
It would be nice to replace the above unspecific error message with a useful error that gives a hint for how the implementations can be made compatible across the 0.21/0.22 cut so that plugin developers can at all times support at least some range of PennyLane versions.
Implementation
No response
How important would you say this feature is?
3: Very important! Blocking work.
Additional information
No response
The text was updated successfully, but these errors were encountered: