class_docstr: Tests for entropies in ClassicalShadow class
class_docstr_tok: ["Tests","for","entropies","in","ClassicalShadow","class"]
docstr: Test that the closest density matrix from the estimator is valid
docstr_tok: ["Test","that","the","closest","density","matrix","from","the","estimator","is","valid"]
code: def test_closest_density_matrix(self):
      """Test that the closest density matrix from the estimator is valid"""
      wires = 3
      dev = qml.device("default.qubit", wires=range(wires))
  
      # Just a simple circuit
      @qml.qnode(dev)
      def qnode(x):
          for i in range(wires):
              qml.RY(x[i], wires=i)
  
          for i in range(wires - 1):
              qml.CNOT((i, i + 1))
  
          return qml.state()
  
      x = np.linspace(0.5, 1.5, num=wires)
      state = qnode(x)
      rho = qml.math.dm_from_state_vector(state)
      lambdas = _project_density_matrix_spectrum(rho)
      assert np.isclose(np.sum(lambdas), 1.0)
      assert all(lambdas > 0)
  
file_path: pennylane/tests/shadow/test_shadow_entropies.py
imports: import pytest
  import pennylane
  import pennylane.numpy
  from pennylane.shadows import ClassicalShadow
  from pennylane.shadows.classical_shadow import _project_density_matrix_spectrum
label_desc: Use image node_id 4 for calling the TestShadowEntropies obj's underlying member method code with example usage: obj.test_closest_density_matrix() and returns: qml