class_docstr: Abstract base class for PennyLane qubit devices.
  
  The following abstract method **must** be defined:
  
  * :meth:`~.apply`: append circuit operations, compile the circuit (if applicable),
    and perform the quantum computation.
  
  Devices that generate their own samples (such as hardware) may optionally
  overwrite :meth:`~.probability`. This method otherwise automatically
  computes the probabilities from the generated samples, and **must**
  overwrite the following method:
  
  * :meth:`~.generate_samples`: Generate samples from the device from the
    exact or approximate probability distribution.
  
  Analytic devices **must** overwrite the following method:
  
  * :meth:`~.analytic_probability`: returns the probability or marginal probability from the
    device after circuit execution. :meth:`~.marginal_prob` may be used here.
  
  This device contains common utility methods for qubit-based devices. These
  do not need to be overwritten. Utility methods include:
  
  * :meth:`~.expval`, :meth:`~.var`, :meth:`~.sample`: return expectation values,
    variances, and samples of observables after the circuit has been rotated
    into the observable eigenbasis.
  
  Args:
      wires (int, Iterable[Number, str]]): Number of subsystems represented by the device,
          or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
          or strings (``['ancilla', 'q1', 'q2']``). Default 1 if not specified.
      shots (None, int, list[int]): Number of circuit evaluations/random samples used to estimate
          expectation values of observables. If ``None``, the device calculates probability, expectation values,
          and variances analytically. If an integer, it specifies the number of samples to estimate these quantities.
          If a list of integers is passed, the circuit evaluations are batched over the list of shots.
      r_dtype: Real floating point precision type.
      c_dtype: Complex floating point precision type.
docstr: Returns the measured bits and recipes in the classical shadow protocol.
  
  The protocol is described in detail in the `classical shadows paper <https://arxiv.org/abs/2002.08953>`_.
  This measurement process returns the randomized Pauli measurements (the ``recipes``)
  that are performed for each qubit and snapshot as an integer:
  
  - 0 for Pauli X,
  - 1 for Pauli Y, and
  - 2 for Pauli Z.
  
  It also returns the measurement results (the ``bits``); 0 if the 1 eigenvalue
  is sampled, and 1 if the -1 eigenvalue is sampled.
  
  The device shots are used to specify the number of snapshots. If ``T`` is the number
  of shots and ``n`` is the number of qubits, then both the measured bits and the
  Pauli measurements have shape ``(T, n)``.
  
  This implementation is device-agnostic and works by executing single-shot
  tapes containing randomized Pauli observables. Devices should override this
  if they can offer cleaner or faster implementations.
  
  .. seealso:: :func:`~.pennylane.classical_shadow`
  
  Args:
      obs (~.pennylane.measurements.ClassicalShadowMP): The classical shadow measurement process
      circuit (~.tape.QuantumTape): The quantum tape that is being executed
  
  Returns:
      tensor_like[int]: A tensor with shape ``(2, T, n)``, where the first row represents
      the measured bits and the second represents the recipes used.
docstr_tok: ["Returns","the","measured","bits","and","recipes","in","the","classical","shadow","protocol",".","The","protocol","is","described","in","detail","in","the","`","classical","shadows","paper","<","https",":","\/\/arxiv.org\/abs\/2002.08953",">","`","_",".","This","measurement","process","returns","the","randomized","Pauli","measurements","(","the","``","recipes","``",")","that","are","performed","for","each","qubit","and","snapshot","as","an","integer",":","-","0","for","Pauli","X",",","-","1","for","Pauli","Y",",","and","-","2","for","Pauli","Z",".","It","also","returns","the","measurement","results","(","the","``","bits","``",")",";","0","if","the","1","eigenvalue","is","sampled",",","and","1","if","the","-1","eigenvalue","is","sampled",".","The","device","shots","are","used","to","specify","the","number","of","snapshots",".","If","``","T","``","is","the","number","of","shots","and","``","n","``","is","the","number","of","qubits",",","then","both","the","measured","bits","and","the","Pauli","measurements","have","shape","``","(","T",",","n",")","``",".","This","implementation","is","device-agnostic","and","works","by","executing","single-shot","tapes","containing","randomized","Pauli","observables",".","Devices","should","override","this","if","they","can","offer","cleaner","or","faster","implementations",".","..","seealso",":",":",":","func",":","`","~.pennylane.classical_shadow","`","Args",":","obs","(","~.pennylane.measurements.ClassicalShadowMP",")",":","The","classical","shadow","measurement","process","circuit","(","~.tape.QuantumTape",")",":","The","quantum","tape","that","is","being","executed","Returns",":","tensor_like","[","int","]",":","A","tensor","with","shape","``","(","2",",","T",",","n",")","``",",","where","the","first","row","represents","the","measured","bits","and","the","second","represents","the","recipes","used","."]
code: def classical_shadow(self, obs, circuit):
      """
      Returns the measured bits and recipes in the classical shadow protocol.
  
      The protocol is described in detail in the `classical shadows paper <https://arxiv.org/abs/2002.08953>`_.
      This measurement process returns the randomized Pauli measurements (the ``recipes``)
      that are performed for each qubit and snapshot as an integer:
  
      - 0 for Pauli X,
      - 1 for Pauli Y, and
      - 2 for Pauli Z.
  
      It also returns the measurement results (the ``bits``); 0 if the 1 eigenvalue
      is sampled, and 1 if the -1 eigenvalue is sampled.
  
      The device shots are used to specify the number of snapshots. If ``T`` is the number
      of shots and ``n`` is the number of qubits, then both the measured bits and the
      Pauli measurements have shape ``(T, n)``.
  
      This implementation is device-agnostic and works by executing single-shot
      tapes containing randomized Pauli observables. Devices should override this
      if they can offer cleaner or faster implementations.
  
      .. seealso:: :func:`~.pennylane.classical_shadow`
  
      Args:
          obs (~.pennylane.measurements.ClassicalShadowMP): The classical shadow measurement process
          circuit (~.tape.QuantumTape): The quantum tape that is being executed
  
      Returns:
          tensor_like[int]: A tensor with shape ``(2, T, n)``, where the first row represents
          the measured bits and the second represents the recipes used.
      """
      if circuit is None:  # pragma: no cover
          raise ValueError(
              "Circuit must be provided when measuring classical shadows"
          )
  
      wires = obs.wires
      n_snapshots = self.shots
      seed = obs.seed
  
      with set_shots(self, shots=1):
          # slow implementation but works for all devices
          n_qubits = len(wires)
          mapped_wires = np.array(self.map_wires(wires))
  
          # seed the random measurement generation so that recipes
          # are the same for different executions with the same seed
          rng = np.random.RandomState(seed)
          recipes = rng.randint(0, 3, size=(n_snapshots, n_qubits))
          obs_list = [qml.PauliX, qml.PauliY, qml.PauliZ]
  
          outcomes = np.zeros((n_snapshots, n_qubits))
  
          for t in range(n_snapshots):
              # compute rotations for the Pauli measurements
              rotations = [
                  rot
                  for wire_idx, wire in enumerate(wires)
                  for rot in obs_list[
                      recipes[t][wire_idx]
                  ].compute_diagonalizing_gates(wires=wire)
              ]
  
              self.reset()
              self.apply(
                  circuit.operations,
                  rotations=self._get_diagonalizing_gates(circuit)
                  + rotations,
              )
  
              outcomes[t] = self.generate_samples()[0][mapped_wires]
  
      return self._cast(self._stack([outcomes, recipes]), dtype=np.int8)
  
imports: import abc
  import itertools
  import warnings
  from collections import defaultdict
  from typing import Union, List
  import inspect
  import logging
  import numpy
  import pennylane
  from pennylane import Device, DeviceError
  from pennylane.workflow import set_shots
  from pennylane.math import multiply
  from pennylane.math import sum
  from pennylane.measurements import ClassicalShadowMP, CountsMP, ExpectationMP, MeasurementProcess, MeasurementTransform, MeasurementValue, MutualInfoMP, ProbabilityMP, SampleMeasurement, SampleMP, ShadowExpvalMP, StateMeasurement, StateMP, VarianceMP, VnEntropyMP, Shots
  from pennylane.resource import Resources
  from pennylane.operation import operation_derivative, Operation
  from pennylane.tape import QuantumTape
  from pennylane.wires import Wires
label_desc: Use image node_id 24 for calling the QubitDevice obj's underlying member method code with example usage: obj.classical_shadow(obs, circuit) and returns: self