Hi @Vedant_Dwivedi. Thank you for posting your question here and welcome to the forum!
What node does this coding exercise correspond to?
I.9 Measurements. I think my y_basis rotation is wrong but somehow in exercise previous to this(attached) is made to pass correct.
Hi @Vedant_Dwivedi.
Your solution to the previous exercise is in fact correct.
In the last exercise look carefully into the rotation back to the computational basis. What is the effect of the operations you are using? What happens if you do an operation and then its adjoint? Do you really need to do both?
I hope this helps you!
I have been stuck in this exercise for quite a lot of time, and I think that the problem is either that the line:
qml.adjoint(y_basis_rotation())
is not working properly or I haven’t understood how to use it.
In the following image, I use what I was expecting from the adjoint and I finally get this exercise correctly.
@Guillem, qml.adjoint
is a type of operation in PennyLane that we call a transform. Loosely, transforms take functions as input, and return functions as outputs. What qml.adjoint
does is take a function (or operation) as input and returns a function that constructs the adjoint:
adjoint_of_S = qml.adjoint(qml.S)
adjoint_of_y_basis_rotation = qml.adjoint(y_basis_rotation)
But these are just functions - they don’t actually execute anything unless you call them; the new functions take exactly the same arguments as the old ones. qml.S
normally takes just a wires argument, so we use:
adjoint_of_S(wires=0)
and this is equivalent to just doing
qml.adjoint(qml.S)(wires=0)
And similarly for the y_basis_rotation
, which takes no arguments,
adjoint_of_y_basis_rotation()
or all in one line,
qml.adjoint(y_basis_rotation)()
There is some more information, and other examples in the PennyLane docs for the transforms module. (In particular, qml.ctrl
is a similar case, which you will find in later exercises in the Codebook!)
Aaaahh I see, thank you ^^
I didn’t notice I wrote qml.adjoint(y_basis_rotation()) instead of qml.adjoint(y_basis_rotation)()
Thanks a lot
Hi @Guillem!
Just to complement the answer, notice how in the first image you posted here you had line 12 where you performed a rotation and then in line 13 you basically reversed it using the adjoint.
Aside from the small detail of the parenthesis you can also notice that in your last try you removed line 12, which helped you get to the correct answer!