class_docstr: Represents a classical shadow measurement process occurring at the end of a
  quantum variational circuit.
  
  Please refer to :func:`classical_shadow` for detailed documentation.
  
  
  Args:
      wires (.Wires): The wires the measurement process applies to.
      seed (Union[int, None]): The seed used to generate the random measurements
      id (str): custom label given to a measurement instance, can be useful for some applications
          where the instance has to be identified
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
  quantum tapes containing randomized Pauli observables. Devices should override this
  if they can offer cleaner or faster implementations.
  
  .. seealso:: :func:`~pennylane.classical_shadow`
  
  Args:
      tape (QuantumTape): the quantum tape to be processed
      device (pennylane.Device): the device used to process the quantum tape
  
  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","quantum","tapes","containing","randomized","Pauli","observables",".","Devices","should","override","this","if","they","can","offer","cleaner","or","faster","implementations",".","..","seealso",":",":",":","func",":","`","~pennylane.classical_shadow","`","Args",":","tape","(","QuantumTape",")",":","the","quantum","tape","to","be","processed","device","(","pennylane.Device",")",":","the","device","used","to","process","the","quantum","tape","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 process(self, tape, device):
      """
      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
      quantum tapes containing randomized Pauli observables. Devices should override this
      if they can offer cleaner or faster implementations.
  
      .. seealso:: :func:`~pennylane.classical_shadow`
  
      Args:
          tape (QuantumTape): the quantum tape to be processed
          device (pennylane.Device): the device used to process the quantum tape
  
      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.
      """
      wires = self.wires
      n_snapshots = device.shots
      seed = self.seed
  
      with qml.workflow.set_shots(device, shots=1):
          # slow implementation but works for all devices
          n_qubits = len(wires)
          mapped_wires = np.array(device.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)
              ]
  
              device.reset()
              device.apply(
                  tape.operations,
                  rotations=tape.diagonalizing_gates + rotations,
              )
  
              outcomes[t] = device.generate_samples()[0][mapped_wires]
  
      return qml.math.cast(
          qml.math.stack([outcomes, recipes]), dtype=np.int8
      )
  
imports: import copy
  from collections.abc import Iterable
  from typing import Optional, Union, Sequence
  from string import ascii_letters
  import numpy
  import pennylane
  from pennylane.operation import Operator
  from pennylane.wires import Wires
  from .measurements import MeasurementShapeError, MeasurementTransform, Shadow, ShadowExpval
label_desc: Use image node_id 4 for calling the ClassicalShadowMP obj's underlying member method code with example usage: obj.process(tape, device) and returns: qml