# Stock in Problem H.6.1 summations of Unitaries

**URL:** <https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462>\
**Category:** Codebook\
**Created:** [April 19, 2024, 5:34am UTC](https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462 "2024-04-19T05:34:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SUDHIR\_KUMAR\_SAHOO](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/sudhir_kumar_sahoo/32/2254_2.png) [@SUDHIR\_KUMAR\_SAHOO](https://discuss.pennylane.ai/u/SUDHIR_KUMAR_SAHOO)\
**Post date:** [April 19, 2024, 5:34am UTC](https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462/1 "2024-04-19T05:34:24Z")

</div>

```aux
main = 1
n_bits = 2
dev = qml.device("default.qubit", wires=n_bits)

def add_two_unitaries(U, V):
    """A circuit to apply the sum of two unitaries non-deterministically.
    
    Args:
        U (array): A unitary matrix, stored as a complex array.
        V (array): A unitary matrix, stored as a complex array.
    """
    qml.Hadamard(wires=aux)
    ##################
    # YOUR CODE HERE #
    ##################
    qml.ControlledQubitUnitary(U, control_wires = [1,0], wires = 2) + 
    qml.ControlledQubitUnitary(V, control_wires = [1,0], wires = 2)
    qml.Hadamard(wires=aux)

```

I am trying to do linear combinations in this way. Where it went wrong conceptually not able to figure it out.

---

<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:** [April 19, 2024, 8:17pm UTC](https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462/2 "2024-04-19T20:17:04Z")

</div>

Hi @SUDHIR_KUMAR_SAHOO ,

Make sure to take a clear look at the figure showed right before the codercise. How many control wires do you actually need? What does it mean that the dot of the control for U is not fully coloured? What can you find in the documentation for `ControlledQubitUnitary`?

Also, note that you have a trailing `+` in your first line. This is not how addition works here 😉

I hope this helps you! 😃

---

<div class="post-metadata">

**Author:** ![SUDHIR\_KUMAR\_SAHOO](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/sudhir_kumar_sahoo/32/2254_2.png) [@SUDHIR\_KUMAR\_SAHOO](https://discuss.pennylane.ai/u/SUDHIR_KUMAR_SAHOO)\
**Post date:** [April 21, 2024, 8:24am UTC](https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462/3 "2024-04-21T08:24:46Z")

</div>

Hello @CatalinaAlbornoz ,

I got your point it should be kU + V. However, I wont understand the constant here is k is we to take as \sqrt(1/2)?

```auto
aux = 0
main = 1
n_bits = 2
dev = qml.device("default.qubit", wires=n_bits)

def add_two_unitaries(U, V):
    """A circuit to apply the sum of two unitaries non-deterministically.
    
    Args:
        U (array): A unitary matrix, stored as a complex array.
        V (array): A unitary matrix, stored as a complex array.
    """
    qml.Hadamard(wires=aux)
    ##################
    # YOUR CODE HERE #
    ##################
    qml.ControlledQubitUnitary(U, control_wires = [1,0], wires = 2)
    qml.ControlledQubitUnitary(V, control_wires = [0,1], wires = 2)
    qml.Hadamard(wires=aux)

```

---

<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:** [April 23, 2024, 9:33pm UTC](https://discuss.pennylane.ai/t/stock-in-problem-h-6-1-summations-of-unitaries/4462/4 "2024-04-23T21:33:53Z")

</div>

Hi @SUDHIR_KUMAR_SAHOO, there’s actually no constant k here. What I meant is that you should take a look at your control wires. If you look closely there’s actually just one control wire for U and V.

If you look at the tip in this codercise it says:

> Use [`qml.ControlledQubitUnitary`](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.ControlledQubitUnitary.html) to apply these unitaries with control bits.

What are these control bits? They’re not the same as control wires, so what are they? The answer is in the documentation!

Also, notice that you have something called “aux” and something called “main” at the beginning of the code. What are they referring to?

I hope this helps you!
