class_docstr: Tests for the (reduced) density matrix for QNodes returning states.
docstr: Test the density matrix from matrix for single wires.
docstr_tok: ["Test","the","density","matrix","from","matrix","for","single","wires","."]
code: def test_density_matrix_from_qnode(
      self, device, wires, angle, interface, tol
  ):
      """Test the density matrix from matrix for single wires."""
      dev = qml.device(device, wires=2)
  
      @qml.qnode(dev, interface=interface)
      def circuit(x):
          qml.PauliX(0)
          qml.IsingXX(x, wires=[0, 1])
          return qml.state()
  
      density_matrix = qml.qinfo.reduced_dm(circuit, wires=wires)(angle)
  
      def expected_density_matrix(x, wires):
          if wires == [0]:
              return [[np.sin(x / 2) ** 2, 0], [0, np.cos(x / 2) ** 2]]
          if wires == [1]:
              return [[np.cos(x / 2) ** 2, 0], [0, np.sin(x / 2) ** 2]]
          if wires == [0, 1]:
              return [
                  [0, 0, 0, 0],
                  [
                      0,
                      np.sin(x / 2) ** 2,
                      0.0 - np.cos(x / 2) * np.sin(x / 2) * 1j,
                      0,
                  ],
                  [
                      0,
                      0.0 + np.cos(x / 2) * np.sin(x / 2) * 1j,
                      np.cos(x / 2) ** 2,
                      0,
                  ],
                  [0, 0, 0, 0],
              ]
          if wires == [1, 0]:
              return [
                  [0, 0, 0, 0],
                  [
                      0,
                      np.cos(x / 2) ** 2,
                      0.0 + np.cos(x / 2) * np.sin(x / 2) * 1j,
                      0,
                  ],
                  [
                      0,
                      0.0 - np.cos(x / 2) * np.sin(x / 2) * 1j,
                      np.sin(x / 2) ** 2,
                      0,
                  ],
                  [0, 0, 0, 0],
              ]
          return None
  
      assert np.allclose(
          expected_density_matrix(angle, wires),
          density_matrix,
          atol=tol,
          rtol=0,
      )
  
file_path: pennylane/tests/qinfo/test_reduced_dm.py
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestDensityMatrixQNode obj's underlying member method code with example usage: obj.test_density_matrix_from_qnode(device, wires, angle, interface, tol) and returns: qml, None, list, list, list, list