When quantum states in a Hilbert space are prepared probabilistically, they are represented via a density matrix acting on

Here, the state is prepared with probability .

PennyLane can handle density matrices quite well on its own. But for the sake of learning, let us build some density matrices by hand. Using np.outer or otherwise, complete the function below that returns the density matrix when the qubit state_1 is prepared with probability p_1, and the qubit state_2 with probability p_2. You may assume that the qubits are normalized.

or to submit your code

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

Learning Objectives:

  • Define the concept of the density operator and state its properties.
  • Distinguish between pure and mixed states.