In addition to the rotation, we have also and rotations. These parametric gates are available in PennyLane as qml.RX and qml.RY.

Write a QNode that applies qml.RX with an angle of to one of the computational basis states. What operation is this?

dev = qml.device("default.qubit", wires=1)


@qml.qnode(dev)
def apply_rx_pi(state):
"""Apply an RX gate with an angle of \pi to a particular basis state.

Args:
state (int): Either 0 or 1. If 1, initialize the qubit to state |1>
before applying other operations.

Returns:
np.array[complex]: The state of the qubit after the operations.
"""
if state == 1:
qml.PauliX(wires=0)

##################
# YOUR CODE HERE #
##################

# APPLY RX(pi) AND RETURN THE STATE

return


print(apply_rx_pi(0))
print(apply_rx_pi(1))

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Describe the action of the RX gate and its matrix representation.
  • Describe the action of the RY gate and its matrix representation.
  • Represent qubit states in 3-dimensional space using the Bloch sphere.