class_docstr: The operations and measurements that represent instructions for
  execution on a quantum device.
  
  Args:
      ops (Iterable[Operator]): An iterable of the operations to be performed
      measurements (Iterable[MeasurementProcess]): All the measurements to be performed
  
  Keyword Args:
      shots (None, int, Sequence[int], ~.Shots): Number and/or batches of shots for execution.
          Note that this property is still experimental and under development.
      trainable_params (None, Sequence[int]): the indices for which parameters are trainable
      _update=True (bool): Whether or not to set various properties on initialization. Setting
          ``_update=False`` reduces computations if the script is only an intermediary step.
  
  .. seealso:: :class:`pennylane.tape.QuantumTape`
  
  **Example:**
  
  .. code-block:: python
  
      from pennylane.tape import QuantumScript
  
      ops = [qml.BasisState(np.array([1,1]), wires=(0,"a")),
             qml.RX(0.432, 0),
             qml.RY(0.543, 0),
             qml.CNOT((0,"a")),
             qml.RX(0.133, "a")]
  
      qscript = QuantumScript(ops, [qml.expval(qml.PauliZ(0))])
  
  >>> list(qscript)
  [BasisState(array([1, 1]), wires=[0, "a"]),
  RX(0.432, wires=[0]),
  RY(0.543, wires=[0]),
  CNOT(wires=[0, 'a']),
  RX(0.133, wires=['a']),
  expval(PauliZ(wires=[0]))]
  >>> qscript.operations
  [BasisState(array([1, 1]), wires=[0, "a"]),
  RX(0.432, wires=[0]),
  RY(0.543, wires=[0]),
  CNOT(wires=[0, 'a']),
  RX(0.133, wires=['a'])]
  >>> qscript.measurements
  [expval(PauliZ(wires=[0]))]
  
  Iterating over the quantum script can be done by:
  
  >>> for op in qscript:
  ...     print(op)
  BasisState(array([1, 1]), wires=[0, "a"])
  RX(0.432, wires=[0])
  RY(0.543, wires=[0])
  CNOT(wires=[0, 'a'])
  RX(0.133, wires=['a'])
  expval(PauliZ(wires=[0]))'
  
  Quantum scripts also support indexing and length determination:
  
  >>> qscript[0]
  BasisState(array([1, 1]), wires=[0, "a"])
  >>> len(qscript)
  6
  
  Once constructed, the script can be executed directly on a quantum device
  using the :func:`~.pennylane.execute` function:
  
  >>> dev = qml.device('default.qubit', wires=(0,'a'))
  >>> qml.execute([qscript], dev, gradient_fn=None)
  [array([-0.77750694])]
  
  Quantum scripts can also store information about the number and batches of
  executions by setting the ``shots`` keyword argument. This information is internally
  stored in a :class:`pennylane.measurements.Shots` object:
  
  >>> s_vec = [1, 1, 2, 2, 2]
  >>> qscript = QuantumScript([qml.Hadamard(0)], [qml.expval(qml.PauliZ(0))], shots=s_vec)
  >>> qscript.shots.shot_vector
  (ShotCopies(1 shots x 2), ShotCopies(2 shots x 3))
  
  ``ops`` and ``measurements`` are converted to lists upon initialization,
  so those arguments accept any iterable object:
  
  >>> qscript = QuantumScript((qml.PauliX(i) for i in range(3)))
  >>> qscript.circuit
  [PauliX(wires=[0]), PauliX(wires=[1]), PauliX(wires=[2])]
class_docstr_tok: ["The","operations","and","measurements","that","represent","instructions","for","execution","on","a","quantum","device",".","Args",":","ops","(","Iterable","[","Operator","]",")",":","An","iterable","of","the","operations","to","be","performed","measurements","(","Iterable","[","MeasurementProcess","]",")",":","All","the","measurements","to","be","performed","Keyword","Args",":","shots","(","None",",","int",",","Sequence","[","int","]",",","~.Shots",")",":","Number","and\/or","batches","of","shots","for","execution",".","Note","that","this","property","is","still","experimental","and","under","development",".","trainable_params","(","None",",","Sequence","[","int","]",")",":","the","indices","for","which","parameters","are","trainable","_update=True","(","bool",")",":","Whether","or","not","to","set","various","properties","on","initialization",".","Setting","``","_update=False","``","reduces","computations","if","the","script","is","only","an","intermediary","step",".","..","seealso",":",":",":","class",":","`","pennylane.tape.QuantumTape","`","*","*","Example",":","*","*","..","code-block",":",":","python","from","pennylane.tape","import","QuantumScript","ops","=","[","qml.BasisState","(","np.array","(","[","1,1","]",")",",","wires=","(","0",",","''","a","''",")",")",",","qml.RX","(","0.432",",","0",")",",","qml.RY","(","0.543",",","0",")",",","qml.CNOT","(","(","0",",","''","a","''",")",")",",","qml.RX","(","0.133",",","``","a","''",")","]","qscript","=","QuantumScript","(","ops",",","[","qml.expval","(","qml.PauliZ","(","0",")",")","]",")",">",">",">","list","(","qscript",")","[","BasisState","(","array","(","[","1",",","1","]",")",",","wires=","[","0",",","``","a","''","]",")",",","RX","(","0.432",",","wires=","[","0","]",")",",","RY","(","0.543",",","wires=","[","0","]",")",",","CNOT","(","wires=","[","0",",","'","a","'","]",")",",","RX","(","0.133",",","wires=","[","'","a","'","]",")",",","expval","(","PauliZ","(","wires=","[","0","]",")",")","]",">",">",">","qscript.operations","[","BasisState","(","array","(","[","1",",","1","]",")",",","wires=","[","0",",","``","a","''","]",")",",","RX","(","0.432",",","wires=","[","0","]",")",",","RY","(","0.543",",","wires=","[","0","]",")",",","CNOT","(","wires=","[","0",",","'","a","'","]",")",",","RX","(","0.133",",","wires=","[","'","a","'","]",")","]",">",">",">","qscript.measurements","[","expval","(","PauliZ","(","wires=","[","0","]",")",")","]","Iterating","over","the","quantum","script","can","be","done","by",":",">",">",">","for","op","in","qscript",":","...","print","(","op",")","BasisState","(","array","(","[","1",",","1","]",")",",","wires=","[","0",",","``","a","''","]",")","RX","(","0.432",",","wires=","[","0","]",")","RY","(","0.543",",","wires=","[","0","]",")","CNOT","(","wires=","[","0",",","'","a","'","]",")","RX","(","0.133",",","wires=","[","'","a","'","]",")","expval","(","PauliZ","(","wires=","[","0","]",")",")","'","Quantum","scripts","also","support","indexing","and","length","determination",":",">",">",">","qscript","[","0","]","BasisState","(","array","(","[","1",",","1","]",")",",","wires=","[","0",",","``","a","''","]",")",">",">",">","len","(","qscript",")","6","Once","constructed",",","the","script","can","be","executed","directly","on","a","quantum","device","using","the",":","func",":","`","~.pennylane.execute","`","function",":",">",">",">","dev","=","qml.device","(","'default.qubit","'",",","wires=","(","0",",","'","a","'",")",")",">",">",">","qml.execute","(","[","qscript","]",",","dev",",","gradient_fn=None",")","[","array","(","[","-0.77750694","]",")","]","Quantum","scripts","can","also","store","information","about","the","number","and","batches","of","executions","by","setting","the","``","shots","``","keyword","argument",".","This","information","is","internally","stored","in","a",":","class",":","`","pennylane.measurements.Shots","`","object",":",">",">",">","s_vec","=","[","1",",","1",",","2",",","2",",","2","]",">",">",">","qscript","=","QuantumScript","(","[","qml.Hadamard","(","0",")","]",",","[","qml.expval","(","qml.PauliZ","(","0",")",")","]",",","shots=s_vec",")",">",">",">","qscript.shots.shot_vector","(","ShotCopies","(","1","shots","x","2",")",",","ShotCopies","(","2","shots","x","3",")",")","``","ops","``","and","``","measurements","``","are","converted","to","lists","upon","initialization",",","so","those","arguments","accept","any","iterable","object",":",">",">",">","qscript","=","QuantumScript","(","(","qml.PauliX","(","i",")","for","i","in","range","(","3",")",")",")",">",">",">","qscript.circuit","[","PauliX","(","wires=","[","0","]",")",",","PauliX","(","wires=","[","1","]",")",",","PauliX","(","wires=","[","2","]",")","]"]
docstr: Produces the output shape of the quantum script by inspecting its measurements
  and the device used for execution.
  
  .. note::
  
      The computed shape is not stored because the output shape may be
      dependent on the device used for execution.
  
  Args:
      device (pennylane.Device): the device that will be used for the script execution
  
  Returns:
      Union[tuple[int], tuple[tuple[int]]]: the output shape(s) of the quantum script result
  
  **Examples**
  
  .. code-block:: pycon
  
      >>> dev = qml.device('default.qubit', wires=2)
      >>> qs = QuantumScript(measurements=[qml.state()])
      >>> qs.shape(dev)
      (4,)
      >>> m = [qml.state(), qml.expval(qml.PauliZ(0)), qml.probs((0,1))]
      >>> qs = QuantumScript(measurements=m)
      >>> qs.shape(dev)
      ((4,), (), (4,))
code: def shape(self, device):
      """Produces the output shape of the quantum script by inspecting its measurements
      and the device used for execution.
  
      .. note::
  
          The computed shape is not stored because the output shape may be
          dependent on the device used for execution.
  
      Args:
          device (pennylane.Device): the device that will be used for the script execution
  
      Returns:
          Union[tuple[int], tuple[tuple[int]]]: the output shape(s) of the quantum script result
  
      **Examples**
  
      .. code-block:: pycon
  
          >>> dev = qml.device('default.qubit', wires=2)
          >>> qs = QuantumScript(measurements=[qml.state()])
          >>> qs.shape(dev)
          (4,)
          >>> m = [qml.state(), qml.expval(qml.PauliZ(0)), qml.probs((0,1))]
          >>> qs = QuantumScript(measurements=m)
          >>> qs.shape(dev)
          ((4,), (), (4,))
      """
  
      if isinstance(device, qml.devices.Device):
          # MP.shape (called below) takes 2 arguments: `device` and `shots`.
          # With the new device interface, shots are stored on tapes rather than the device
          # TODO: refactor MP.shape to accept `wires` instead of device (not currently done
          # because probs.shape uses device.cutoff)
          shots = self.shots
      else:
          shots = (
              Shots(device._raw_shot_sequence)
              if device.shot_vector is not None
              else Shots(device.shots)
          )
  
      if len(shots.shot_vector) > 1 and self.batch_size is not None:
          raise NotImplementedError(
              "Parameter broadcasting when using a shot vector is not supported yet."
          )
  
      shapes = tuple(
          meas_process.shape(device, shots)
          for meas_process in self.measurements
      )
  
      if self.batch_size is not None:
          shapes = tuple((self.batch_size,) + shape for shape in shapes)
  
      if len(shapes) == 1:
          return shapes[0]
  
      if shots.num_copies > 1:
          # put the shot vector axis before the measurement axis
          shapes = tuple(zip(*shapes))
  
      return shapes
  
imports: import contextlib
  import copy
  from collections import Counter
  from typing import List, Union, Optional, Sequence
  from warnings import warn
  import pennylane
  from pennylane.measurements import ClassicalShadowMP, CountsMP, MeasurementProcess, ProbabilityMP, SampleMP, ShadowExpvalMP, StateMP, Shots
  from pennylane.typing import TensorLike
  from pennylane.operation import Observable, Operator, Operation, _UNSET_BATCH_SIZE
  from pennylane.pytrees import register_pytree
  from pennylane.queuing import AnnotatedQueue, process_queue
  from pennylane.wires import Wires
label_desc: Use image node_id 36 for calling the QuantumScript obj's underlying member method code with example usage: obj.shape(device) and returns: shapes, shapes