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, device, 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, device=device
      )
      bits, recipes = circuit()
      new_bits, new_recipes = circuit.tape.measurements[0].process(
          circuit.tape, circuit.device
      )
  
      # 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)
      new_ratios = np.unique(new_recipes, return_counts=True)[1] / (
          wires * shots
      )
      assert np.allclose(new_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)
      assert qml.math.allequal(new_bits[new_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)
      new_bits1 = new_bits[new_recipes == (basis_recipe + 1) % 3]
      new_ratios1 = (
          np.unique(new_bits1, return_counts=True)[1]
          / new_bits1.shape[0]
      )
      assert np.allclose(new_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)
  
      new_bits2 = new_bits[new_recipes == (basis_recipe + 2) % 3]
      new_ratios2 = (
          np.unique(new_bits2, return_counts=True)[1]
          / new_bits2.shape[0]
      )
      assert np.allclose(new_ratios2, 1 / 2, atol=1e-1)
  
imports: import autograd.numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.measurements import Shots
label_desc: Use image node_id 4 for calling the TestClassicalShadow obj's underlying member method code with example usage: obj.test_return_distribution(wires, interface, device, circuit_fn, basis_recipe) without return types