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: Return the parameters incident on the quantum script operations.
  
  The returned parameters are provided in order of appearance
  on the quantum script.
  
  Args:
      trainable_only (bool): if True, returns only trainable parameters
      operations_only (bool): if True, returns only the parameters of the
          operations excluding parameters to observables of measurements
  
  **Example**
  
  >>> ops = [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))])
  
  By default, all parameters are trainable and will be returned:
  
  >>> qscript.get_parameters()
  [0.432, 0.543, 0.133]
  
  Setting the trainable parameter indices will result in only the specified
  parameters being returned:
  
  >>> qscript.trainable_params = [1] # set the second parameter as trainable
  >>> qscript.get_parameters()
  [0.543]
  
  The ``trainable_only`` argument can be set to ``False`` to instead return
  all parameters:
  
  >>> qscript.get_parameters(trainable_only=False)
  [0.432, 0.543, 0.133]
code: def get_parameters(
      self, trainable_only=True, operations_only=False, **kwargs
  ):  # pylint:disable=unused-argument
      """Return the parameters incident on the quantum script operations.
  
      The returned parameters are provided in order of appearance
      on the quantum script.
  
      Args:
          trainable_only (bool): if True, returns only trainable parameters
          operations_only (bool): if True, returns only the parameters of the
              operations excluding parameters to observables of measurements
  
      **Example**
  
      >>> ops = [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))])
  
      By default, all parameters are trainable and will be returned:
  
      >>> qscript.get_parameters()
      [0.432, 0.543, 0.133]
  
      Setting the trainable parameter indices will result in only the specified
      parameters being returned:
  
      >>> qscript.trainable_params = [1] # set the second parameter as trainable
      >>> qscript.get_parameters()
      [0.543]
  
      The ``trainable_only`` argument can be set to ``False`` to instead return
      all parameters:
  
      >>> qscript.get_parameters(trainable_only=False)
      [0.432, 0.543, 0.133]
      """
      if trainable_only:
          params = []
          for p_idx in self.trainable_params:
              par_info = self._par_info[p_idx]
              if operations_only and isinstance(
                  self[par_info["op_idx"]], MeasurementProcess
              ):
                  continue
  
              op = par_info["op"]
              op_idx = par_info["p_idx"]
              params.append(op.data[op_idx])
          return params
  
      # If trainable_only=False, return all parameters
      # This is faster than the above and should be used when indexing `_par_info` is not needed
      params = [d for op in self.operations for d in op.data]
      if operations_only:
          return params
      for m in self.measurements:
          if m.obs is not None:
              params.extend(m.obs.data)
      return params
  
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 34 for calling the QuantumScript obj's underlying member method code with example usage: obj.get_parameters(trainable_only, operations_only) and returns: params, params, params