class_docstr: Unit tests for classical_shadow measurement
class_docstr_tok: ["Unit","tests","for","classical_shadow","measurement"]
docstr: Test that the distribution of the bits and recipes are correct for a circuit
  that prepares all qubits in a Pauli basis
docstr_tok: ["Test","that","the","distribution","of","the","bits","and","recipes","are","correct","for","a","circuit","that","prepares","all","qubits","in","a","Pauli","basis"]
code: def test_return_distribution(
      self, wires, interface, circuit_fn, basis_recipe
  ):
      """Test that the distribution of the bits and recipes are correct for a circuit
      that prepares all qubits in a Pauli basis"""
      # high number of shots to prevent true negatives
      np.random.seed(42)
      shots = 1000
  
      circuit = circuit_fn(wires, shots=shots, interface=interface)
      bits, recipes = circuit()
  
      # test that the recipes follow a rough uniform distribution
      ratios = np.unique(recipes, return_counts=True)[1] / (
          wires * shots
      )
      assert np.allclose(ratios, 1 / 3, atol=1e-1)
  
      # test that the bit is 0 for all X measurements
      assert qml.math.allequal(bits[recipes == basis_recipe], 0)
  
      # test that the bits are uniformly distributed for all Y and Z measurements
      bits1 = bits[recipes == (basis_recipe + 1) % 3]
      ratios1 = np.unique(bits1, return_counts=True)[1] / bits1.shape[0]
      assert np.allclose(ratios1, 1 / 2, atol=1e-1)
  
      bits2 = bits[recipes == (basis_recipe + 2) % 3]
      ratios2 = np.unique(bits2, return_counts=True)[1] / bits2.shape[0]
      assert np.allclose(ratios2, 1 / 2, atol=1e-1)
  
imports: import copy
  import autograd.numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.measurements import ClassicalShadowMP, Shots
  from pennylane.measurements.classical_shadow import ShadowExpvalMP
label_desc: Use image node_id 6 for calling the TestClassicalShadow obj's underlying member method code with example usage: obj.test_return_distribution(wires, interface, circuit_fn, basis_recipe) without return types