code: def expand_tape_state_prep(tape, skip_first=True):
      """Expand all instances of StatePrepBase operations in the tape.
  
      Args:
          tape (QuantumScript): The tape to expand.
          skip_first (bool): If ``True``, will not expand a ``StatePrepBase`` operation if
              it is the first operation in the tape.
  
      Returns:
          QuantumTape: The expanded version of ``tape``.
  
      **Example**
  
      If a ``StatePrepBase`` occurs as the first operation of a tape, the operation will not be expanded:
  
      >>> ops = [qml.StatePrep([0, 1], wires=0), qml.PauliZ(1), qml.StatePrep([1, 0], wires=0)]
      >>> tape = qml.tape.QuantumScript(ops, [])
      >>> new_tape = qml.tape.tape.expand_tape_state_prep(tape)
      >>> new_tape.operations
      [StatePrep(array([0, 1]), wires=[0]), PauliZ(wires=[1]), MottonenStatePreparation(array([1, 0]), wires=[0])]
  
      To force expansion, the keyword argument ``skip_first`` can be set to ``False``:
  
      >>> new_tape = qml.tape.tape.expand_tape_state_prep(tape, skip_first=False)
      [MottonenStatePreparation(array([0, 1]), wires=[0]), PauliZ(wires=[1]), MottonenStatePreparation(array([1, 0]), wires=[0])]
      """
      first_op = tape.operations[0]
      new_ops = (
          [first_op]
          if not isinstance(first_op, StatePrepBase) or skip_first
          else first_op.decomposition()
      )
  
      for op in tape.operations[1:]:
          if isinstance(op, StatePrepBase):
              new_ops.extend(op.decomposition())
          else:
              new_ops.append(op)
  
      # preserves inheritance structure
      # if tape is a QuantumTape, returned object will be a quantum tape
      new_tape = tape.__class__(
          new_ops, tape.measurements, shots=tape.shots, _update=False
      )
  
      # Update circuit info
      new_tape.wires = copy.copy(tape.wires)
      new_tape.num_wires = tape.num_wires
      new_tape._batch_size = tape._batch_size
      new_tape._output_dim = tape._output_dim
      return new_tape
  
imports: import copy
  from threading import RLock
  import pennylane
  from pennylane.measurements import CountsMP, ProbabilityMP, SampleMP
  from pennylane.operation import DecompositionUndefinedError, Operator, StatePrepBase
  from pennylane.queuing import AnnotatedQueue, QueuingManager, process_queue
  from pennylane.pytrees import register_pytree
  from .qscript import QuantumScript
label_desc: Use image node_id 5 for calling a global function with example usage: expand_tape_state_prep(tape, skip_first) and returns: new_tape