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: Permute two groups of matches if first one has predecessors in the second one.
  Returns:
      bool: True if the matches groups are in the right order, False otherwise.
code: def _permutation(self):  # pragma: no cover
      """Permute two groups of matches if first one has predecessors in the second one.
      Returns:
          bool: True if the matches groups are in the right order, False otherwise.
      """
      for scenario in self.substitution_list:
          predecessors = set()
          for match in scenario.circuit_config:
              predecessors = predecessors | set(
                  self.circuit_dag.get_node(match).predecessors
              )
          predecessors = predecessors - set(scenario.circuit_config)
          index = self.substitution_list.index(scenario)
          for scenario_b in self.substitution_list[index::]:
              if set(scenario_b.circuit_config) & predecessors:
                  index1 = self.substitution_list.index(scenario)
                  index2 = self.substitution_list.index(scenario_b)
  
                  scenario_pop = self.substitution_list.pop(index2)
                  self.substitution_list.insert(index1, scenario_pop)
                  return False
      return True
  
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 7 for calling the TemplateSubstitution obj's underlying member method code with example usage: obj._permutation() and returns: True, False