PennyLaneAI / comments

0 stars 0 forks source link

blog/2021/05/how-to-add-custom-gates-and-templates-to-pennylane/ #17

Open utterances-bot opened 8 months ago

utterances-bot commented 8 months ago

How to add custom gates and templates to PennyLane | PennyLane Blog

Implementing your own gates in PennyLane does not require deep manipulation of the code base but is as easy as listing some core properties of the operation to be added. Even easier, you can construct your own templates to create structured special purpose circuits and simplify your workflow.

https://pennylane.ai/blog/2021/05/how-to-add-custom-gates-and-templates-to-pennylane/

kyujin2228 commented 8 months ago

Hello, I'd like to ask about the error I got. I followed the first 3 code blocks on my local laptop. (m1 scilicon, python=3.9, pennylane=0.32.0) But I got this error message as follows. TypeError: decomposition() missing 2 required positional arguments: 'theta' and 'wires'

I wonder if this error comes from the version of pennylane. If it's right, how can I fix those codes?

trbromley commented 8 months ago

Hi @kyujin2228! Thanks for pointing this issue out. This blog post was written for quite an old version of PennyLane (version 0.15). To get things working with the newest version of PennyLane - 0.33 was just released this week :tada: - you can follow the instructions here.

For the example in this post, you could do the following:

class RXX(Operation):
    num_params = 1
    num_wires = 2
    par_domain = "R"

    @staticmethod
    def compute_decomposition(theta, wires):
        return [qml.PauliRot(theta, 'XX', wires=wires)]