A quantum gate maps a pure state into In turn, a mixed state is mapped by that same gate into

Let's look at how to simulate the action of gates on density operators using code!

The code below intends to calculate the effect of a quantum gate U on a quantum state with density operator rho. Complete the missing lines to compute the resulting density operator after applying U on rho.

def apply_gate_mixed(rho,U):
"""
Args:
rho: (np.array(array[complex]): The density matrix of the input state
U (np.array(array[complex])): A matrix representing the unitary gate U to be applied.
Returns:
(np.array([array[complex]])): The density matrix of the output state.
"""

################
#YOUR CODE HERE#
################
return # Return the density matrix

U = qml.matrix(qml.RX(np.pi/3,0))
rho = np.array([[3/4,1/4],[1/4,1/4]])

print("A pi/3 RX rotation applied on [[3/4,1/4],[1/4,1/4]] gives:")
print(apply_gate_mixed(rho,U).round(2))

or to submit your code

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

Learning Objectives:

  • Explain the effect of applying gates to mixed states.
  • Determine the measurement probabilities and post-measurement states when measuring a mixed state.
  • Calculate expectation values for observables on a given mixed state.