# QHack 2023 challenge: Introduction to LCUs

**URL:** <https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713>\
**Category:** PennyLane Challenges\
**Created:** [June 17, 2024, 12:00pm UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713 "2024-06-17T12:00:29Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [June 17, 2024, 12:00pm UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713/1 "2024-06-17T12:00:29Z")

</div>

Use this topic to ask your questions about the QHack 2023 challenge: [Introduction to LCUs](https://pennylane.ai/challenges/intro_to_LCUs/)

---

<div class="post-metadata">

**Author:** ![Ji\_Ching](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ji_ching/32/2425_2.png) [@Ji\_Ching](https://discuss.pennylane.ai/u/Ji_Ching)\
**Post date:** [July 2, 2024, 5:50am UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713/2 "2024-07-02T05:50:55Z")

</div>

Hi Catalina, I have a question regarding my solution for this challenge.  
I have constructed the matrix W as such:  
# Put your code here #  
normalisation\_factor = 1 / np.sqrt(alpha + beta)  
W\_matrix = np.array([[np.sqrt(alpha), -np.sqrt(beta)],  
[np.sqrt(beta), np.sqrt(alpha)]])  
# Return the real matrix of the unitary W, in terms of the coefficients.  
return W\_matrix \* normalisation\_factor

And my linear combination quantum circuit as such:  
# Put your code here #  
qml.QubitUnitary(W(alpha, beta), wires = 0)  
qml.ControlledQubitUnitary(U, 0, 1, 0)  
qml.ControlledQubitUnitary(V, 0, 1, 1)  
qml.QubitUnitary(np.transpose(W(alpha, beta)), wires = 0)  
# Return the probabilities on the first wire  
return qml.probs(1)

where the first element is the probability of measuring |0\> on the main register (wire 1). However, my output is 0.875 while the expected output is 0.890 for the public test set. I am confused about where I get wrong or is it just rounding errors when matrix W is constructed? Thank you.

---

<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:** [July 2, 2024, 10:19pm UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713/3 "2024-07-02T22:19:09Z")

</div>

Hi @Ji_Ching ,

Remember that in Python the first element has index zero. So in an array `arr = np.array(['a','b','c'])` you would have `arr[0] = 'a'`. You’re very close!

---

<div class="post-metadata">

**Author:** ![Ji\_Ching](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ji_ching/32/2425_2.png) [@Ji\_Ching](https://discuss.pennylane.ai/u/Ji_Ching)\
**Post date:** [July 3, 2024, 3:46am UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713/4 "2024-07-03T03:46:34Z")

</div>

Hi Catalina, thank you for your reply. After changing the return function to return qml.probs(0), which now return the probability distribution of the auxiliary wire (wire = 0), my solution passes the test.

However, I believe there is a typo in the challenge statement which made me confused. In the output section, the instruction is “The output used to test your solution is a `float` corresponding to the probability of measuring on the **main register**. This is the first element of your output of `linear_combination` . We will extract this element for you in our testing functions!”

which asks us to return the probabilities of the main register (wire =1), and this contradicts with what the solution is expected to be.

---

<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:** [July 3, 2024, 8:29pm UTC](https://discuss.pennylane.ai/t/qhack-2023-challenge-introduction-to-lcus/4713/5 "2024-07-03T20:29:14Z")

</div>

Hi @Ji_Ching ,

You’re right! In the output section of the description it should say **auxiliary register** instead of **main register**. Thank you for pointing it out! We’ll make sure to fix it.
