class_docstr: Tests for the density matrix function
class_docstr_tok: ["Tests","for","the","density","matrix","function"]
docstr: Test that the correct density matrix is returned for an example with
  three wires and a product state, tracing out various combinations.
docstr_tok: ["Test","that","the","correct","density","matrix","is","returned","for","an","example","with","three","wires","and","a","product","state",",","tracing","out","various","combinations","."]
code: def test_correct_density_matrix_three_wires_product(
      self, dev_name, return_wire_order
  ):
      """Test that the correct density matrix is returned for an example with
      three wires and a product state, tracing out various combinations.
      """
  
      dev = qml.device(dev_name, wires=3)
  
      @qml.qnode(dev)
      def func():
          qml.Hadamard(0)
          qml.PauliX(1)
          qml.PauliZ(2)
          return density_matrix(return_wire_order)
  
      density_full = func()
  
      single_states = [[1 / np.sqrt(2), 1 / np.sqrt(2)], [0, 1], [1, 0]]
      if len(return_wire_order) == 1:
          exp_statevector = np.array(
              single_states[return_wire_order[0]]
          )
      elif len(return_wire_order) == 2:
          i, j = return_wire_order
          exp_statevector = np.kron(single_states[i], single_states[j])
      elif len(return_wire_order) == 3:
          i, j, k = return_wire_order
          exp_statevector = np.kron(
              np.kron(single_states[i], single_states[j]),
              single_states[k],
          )
  
      expected = np.outer(exp_statevector.conj(), exp_statevector)
      assert np.allclose(expected, density_full)
  
      if dev_name != "default.mixed":
          assert np.allclose(
              expected,
              qml.density_matrix(wires=return_wire_order).process_state(
                  state=dev.state, wire_order=dev.wires
              ),
          )
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.measurements import State, Shots, density_matrix, expval, state
label_desc: Use image node_id 11 for calling the TestDensityMatrix obj's underlying member method code with example usage: obj.test_correct_density_matrix_three_wires_product(dev_name, return_wire_order) and returns: density_matrix