code: def _local_tape_expand(tape, depth, stop_at):
      """Expand all objects in a tape to a specific depth excluding measurements.
      see `pennylane.tape.tape.expand_tape` for examples.
  
      Args:
          tape (QuantumTape): The tape to expand
          depth (int): the depth the tape should be expanded
          stop_at (Callable): A function which accepts a queue object,
              and returns ``True`` if this object should *not* be expanded.
              If not provided, all objects that support expansion will be expanded.
  
      Returns:
          QuantumTape: The expanded version of ``tape``.
      """
      # This function mimics `pennylane.tape.tape.expand_tape()`, but does not expand measurements and
      # does not perform validation checks for non-commuting measurements on the same wires.
      if depth == 0:
          return tape
  
      new_ops = []
      new_measurements = []
  
      for queue, new_queue in [
          (tape.operations, new_ops),
          (tape.measurements, new_measurements),
      ]:
          for obj in queue:
              if isinstance(obj, MeasurementProcess) or stop_at(obj):
                  new_queue.append(obj)
                  continue
  
              if isinstance(obj, Operator):
                  if obj.has_decomposition:
                      with QueuingManager.stop_recording():
                          obj = QuantumScript(
                              obj.decomposition(), _update=False
                          )
                  else:
                      new_queue.append(obj)
                      continue
  
              # recursively expand out the newly created tape
              expanded_tape = _local_tape_expand(
                  obj, stop_at=stop_at, depth=depth - 1
              )
  
              new_ops.extend(expanded_tape.operations)
              new_measurements.extend(expanded_tape.measurements)
  
      # preserves inheritance structure
      # if tape is a QuantumTape, returned object will be a quantum tape
      new_tape = tape.__class__(
          new_ops, new_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 abc
  import copy
  import types
  import warnings
  from collections import OrderedDict
  from collections.abc import Iterable, Sequence
  from functools import lru_cache
  import numpy
  import pennylane
  from pennylane.measurements import MeasurementProcess, CountsMP, Expectation, ExpectationMP, MidMeasureMP, Probability, ProbabilityMP, Sample, SampleMP, ShadowExpvalMP, State, Variance
  from pennylane.operation import Observable, Operation, Tensor, Operator, StatePrepBase
  from pennylane.ops import Hamiltonian, Sum
  from pennylane.tape import QuantumScript, QuantumTape, expand_tape_state_prep
  from pennylane.wires import WireError, Wires
  from pennylane.queuing import QueuingManager
label_desc: Use image node_id 1 for calling a global function with example usage: _local_tape_expand(tape, depth, stop_at) and returns: new_tape, tape