# Create an Operation with several registers as inputs/outputs

**URL:** <https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926>\
**Category:** PennyLane Help\
**Created:** [May 30, 2022, 3:11pm UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926 "2022-05-30T15:11:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asimonu](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Asimonu](https://discuss.pennylane.ai/u/Asimonu)\
**Post date:** [May 30, 2022, 3:11pm UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/1 "2022-05-30T15:11:29Z")

</div>

In Pennylane, we can create a custom operation by creating a class inheriting _pennylane.operation.Operation_.  
One point is that it is then possible to draw this operation as a block in a given circuit.

However, the operation I am working on is a modular multiplication that takes as input one register for an operand, another for the other operand, a third one for the result, a fourth one for a modulo and a fifth one for the auxiliary qubits. I could also add a control qubit…

I want to implement this operation but the way to specify these registers is problematic.  
I already saw 2 possibilities to do that, however they are not satisfying:

- Put everything in the **wires** but as each register can have a varying size it may not work (we don’t know which wire does what)
- Add the registers sizes as parameters, but the problem is that when I draw my operation, all these sizes will appear and if there is a real parameter (e.g. an angle) to display it will be lost in the crowd

How could I do ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [May 31, 2022, 6:24pm UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/2 "2022-05-31T18:24:46Z")

</div>

Hi @Asimonu, could you please share your code for option 2? I think we may find how to fix your problem from there but it’s hard to troubleshoot without seeing your code.

Also, if possible, please share the output you’re getting!

---

<div class="post-metadata">

**Author:** ![Asimonu](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Asimonu](https://discuss.pennylane.ai/u/Asimonu)\
**Post date:** [June 1, 2022, 7:36am UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/3 "2022-06-01T07:36:13Z")

</div>

Thanks for your answer!  
Sure, here is the whole class:

```
class modularMultiply(qml.operation.Operation):
    num_params = 6
    par_domain = "R"
    num_wires = AnyWires

    @staticmethod
    def compute_decomposition(a, m, b, aux, res, ctrl, wires):
        wires = list(wires)
        return [modular_multiply(a,m,wires[:b],wires[b:b+aux],wires[b+aux:b+aux+res],
                             wires[b+aux+res:b+aux+res+ctrl])]

```

modular\_multiply is a circuit defined as a simple function, a and m are 2 external parameters (“true parameters”), aux, res and ctrl are used to tell how many of which kind of wires there are.  
I find the overall way I did it quite dirty, because if I want to display the drawing of the circuit with parameters, I get something like that:

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/c/c3316c0339db907efd8595d7144069a337852350.png)  
which is confusing because the only parameters I am interested in viewing are a and m.

---

<div class="post-metadata">

**Author:** ![Guillermo\_Alonso](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/guillermo_alonso/32/816_2.png) [@Guillermo\_Alonso](https://discuss.pennylane.ai/u/Guillermo_Alonso)\
**Post date:** [June 1, 2022, 7:29pm UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/4 "2022-06-01T19:29:15Z")

</div>

Hi @Asimonu! I don’t know the logic of the function but you are probably calculating the values of `b`, `aux` and `res` a priori from `a` and `m`, right? In that case, you could do those calculations inside `def compute_decomposition` so you don’t need to pass them as an attribute. The only thing you would have to do is the estimation of the wires you are going to need to tell the operator.  
I hope this helps!

---

<div class="post-metadata">

**Author:** ![Asimonu](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Asimonu](https://discuss.pennylane.ai/u/Asimonu)\
**Post date:** [June 2, 2022, 7:25am UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/5 "2022-06-02T07:25:47Z")

</div>

Hi !  
Okay, right, I didn’t think at it but it’s a good idea. I would say however that computing the order of the wires at two different points in the code (call of the class and method `compute_decomposition`) can be dangerous (or require another function), but it’s indeed better for the drawing.  
Thanks !

---

<div class="post-metadata">

**Author:** ![Guillermo\_Alonso](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/guillermo_alonso/32/816_2.png) [@Guillermo\_Alonso](https://discuss.pennylane.ai/u/Guillermo_Alonso)\
**Post date:** [June 2, 2022, 1:32pm UTC](https://discuss.pennylane.ai/t/create-an-operation-with-several-registers-as-inputs-outputs/1926/6 "2022-06-02T13:32:14Z")

</div>

No worries! Let me know if you have any problem 😉
