class_docstr: Class to run the substitution algorithm from the list of maximal matches.
class_docstr_tok: ["Class","to","run","the","substitution","algorithm","from","the","list","of","maximal","matches","."]
docstr: From the list of maximal matches, it chooses which one will be used and gives the necessary details for
  each substitution(template inverse, predecessors of the match).
code: def substitution(self):
      """From the list of maximal matches, it chooses which one will be used and gives the necessary details for
      each substitution(template inverse, predecessors of the match).
      """
  
      while self.match_stack:
          # Get the first match scenario of the list
          current = self.match_stack.pop(0)
  
          current_match = current.match
          current_qubit = current.qubit
  
          template_sublist = [x[0] for x in current_match]
          circuit_sublist = [x[1] for x in current_match]
          circuit_sublist.sort()
  
          template_list = range(0, self.template_dag.size)
          template_complement = list(
              set(template_list) - set(template_sublist)
          )
  
          # If the match obey the rule then it is added to the list.
          if self._rules(
              circuit_sublist, template_sublist, template_complement
          ):
              template_sublist_inverse = self._template_inverse(
                  template_list, template_sublist, template_complement
              )
  
              config = SubstitutionConfig(
                  circuit_sublist,
                  template_sublist_inverse,
                  [],
                  current_qubit,
                  self.template_dag,
              )
              self.substitution_list.append(config)
  
      # Remove incompatible matches.
      self._remove_impossible()
  
      # First sort the matches according to the smallest index in the matches (circuit).
      self.substitution_list.sort(key=lambda x: x.circuit_config[0])
  
      # Change position of the groups due to predecessors of other groups.
      self._substitution_sort()
  
      for scenario in self.substitution_list:
          index = self.substitution_list.index(scenario)
          scenario.pred_block = self._pred_block(
              scenario.circuit_config, index
          )
  
      circuit_list = []
      for elem in self.substitution_list:
          circuit_list = (
              circuit_list + elem.circuit_config + elem.pred_block
          )
  
      # Unmatched gates that are not predecessors of any group of matches.
      self.unmatched_list = sorted(
          list(set(range(0, self.circuit_dag.size)) - set(circuit_list))
      )
  
imports: import copy
  import itertools
  from collections import OrderedDict
  from typing import Sequence, Callable
  import numpy
  import pennylane
  from pennylane.transforms import transform
  from pennylane import adjoint
  from pennylane.ops.qubit.attributes import symmetric_over_all_wires
  from pennylane.tape import QuantumTape, QuantumScript
  from pennylane.transforms.commutation_dag import commutation_dag
  from pennylane.wires import Wires
label_desc: Use image node_id 9 for calling the TemplateSubstitution obj's underlying member method code with example usage: obj.substitution() without return types