A common use of the gate is in initializing the state of a qubit at the beginning of an algorithm. Quite often, we would like our qubits to start in state (which is the default in PennyLane), however there are many cases where we instead would like to start from Complete the function below by using qml.PauliX to initialize the qubit's state to or based on an input flag. Then, use qml.QubitUnitary to apply the provided unitary U.

Hint.

The PauliX operation is a non-parametrized gate, meaning to call it in PennyLane, all we need to do is specify the wires:

qml.PauliX(wires=wire)

or to submit your code

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

Learning Objectives:

  • Explain why we can understand how an operation works by applying it to the basis states.
  • Describe the action of the X gate, its matrix representation, and eigenvalues.
  • Describe the action of the Hadamard gate, its matrix representation, and eigenvalues.