In PennyLane, unitary operations specified by a matrix can be implemented in a quantum circuit using the QubitUnitary operation. QubitUnitary is a parametrized gate, and can be called like so:

qml.QubitUnitary(U, wires=wire)

Complete the quantum function below to create a circuit that applies U to the qubit and returns its state. (Compare this to the earlier function apply_u that you wrote before - isn't it nice to not have to worry about the matrix arithmetic?)

or to submit your code

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

Learning Objectives:

  • Define what it means for a matrix to be unitary.
  • Express a single-qubit unitary operation in terms of 3 real parameters.