class_docstr: Abstract base class for PennyLane devices.
  
  Args:
      wires (int or Iterable[Number, str]]): Number of subsystems represented by the device,
          or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
          or strings (``['ancilla', 'q1', 'q2']``). Default 1 if not specified.
      shots (int): Number of circuit evaluations/random samples used to estimate
          expectation values of observables. Defaults to 1000 if not specified.
class_docstr_tok: ["Abstract","base","class","for","PennyLane","devices",".","Args",":","wires","(","int","or","Iterable","[","Number",",","str","]","]",")",":","Number","of","subsystems","represented","by","the","device",",","or","iterable","that","contains","unique","labels","for","the","subsystems","as","numbers","(","i.e.",",","``","[","-1",",","0",",","2","]","``",")","or","strings","(","``","[","'ancilla","'",",","'q1","'",",","'q2","'","]","``",")",".","Default","1","if","not","specified",".","shots","(","int",")",":","Number","of","circuit","evaluations\/random","samples","used","to","estimate","expectation","values","of","observables",".","Defaults","to","1000","if","not","specified","."]
docstr: Register a custom expansion function for the device.
  
  **Example**
  
  .. code-block:: python
  
      dev = qml.device("default.qubit.legacy", wires=2)
  
      @dev.custom_expand
      def my_expansion_function(self, tape, max_expansion=10):
          ...
          # can optionally call the default device expansion
          tape = self.default_expand_fn(tape, max_expansion=max_expansion)
          return tape
  
  The custom device expansion function must have arguments
  ``self`` (the device object), ``tape`` (the input circuit
  to transform and execute), and ``max_expansion`` (the number of
  times the circuit should be expanded).
  
  The default :meth:`~.default_expand_fn` method of the original
  device may be called. It is highly recommended to call this
  before returning, to ensure that the expanded circuit is supported
  on the device.
docstr_tok: ["Register","a","custom","expansion","function","for","the","device",".","*","*","Example","*","*","..","code-block",":",":","python","dev","=","qml.device","(","``","default.qubit.legacy","''",",","wires=2",")","@","dev.custom_expand","def","my_expansion_function","(","self",",","tape",",","max_expansion=10",")",":","...","#","can","optionally","call","the","default","device","expansion","tape","=","self.default_expand_fn","(","tape",",","max_expansion=max_expansion",")","return","tape","The","custom","device","expansion","function","must","have","arguments","``","self","``","(","the","device","object",")",",","``","tape","``","(","the","input","circuit","to","transform","and","execute",")",",","and","``","max_expansion","``","(","the","number","of","times","the","circuit","should","be","expanded",")",".","The","default",":","meth",":","`","~.default_expand_fn","`","method","of","the","original","device","may","be","called",".","It","is","highly","recommended","to","call","this","before","returning",",","to","ensure","that","the","expanded","circuit","is","supported","on","the","device","."]
code: def custom_expand(self, fn):
      """Register a custom expansion function for the device.
  
      **Example**
  
      .. code-block:: python
  
          dev = qml.device("default.qubit.legacy", wires=2)
  
          @dev.custom_expand
          def my_expansion_function(self, tape, max_expansion=10):
              ...
              # can optionally call the default device expansion
              tape = self.default_expand_fn(tape, max_expansion=max_expansion)
              return tape
  
      The custom device expansion function must have arguments
      ``self`` (the device object), ``tape`` (the input circuit
      to transform and execute), and ``max_expansion`` (the number of
      times the circuit should be expanded).
  
      The default :meth:`~.default_expand_fn` method of the original
      device may be called. It is highly recommended to call this
      before returning, to ensure that the expanded circuit is supported
      on the device.
      """
      self.custom_expand_fn = types.MethodType(fn, self)
  
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 28 for calling the Device obj's underlying member method code with example usage: obj.custom_expand(fn) without return types