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: Initialize TemplateSubstitution with necessary arguments.
  Args:
      max_matches (list(int)): list of maximal matches obtained from the running the pattern matching algorithm.
      circuit_dag (.CommutationDAG): circuit in the dag dependency form.
      template_dag (.CommutationDAG): template in the dag dependency form.
      custom_quantum_cost (dict): Optional, quantum cost that overrides the default cost dictionnary.
code: def __init__(
      self,
      max_matches,
      circuit_dag,
      template_dag,
      custom_quantum_cost=None,
  ):
      """
      Initialize TemplateSubstitution with necessary arguments.
      Args:
          max_matches (list(int)): list of maximal matches obtained from the running the pattern matching algorithm.
          circuit_dag (.CommutationDAG): circuit in the dag dependency form.
          template_dag (.CommutationDAG): template in the dag dependency form.
          custom_quantum_cost (dict): Optional, quantum cost that overrides the default cost dictionnary.
      """
  
      self.match_stack = max_matches
      self.circuit_dag = circuit_dag
      self.template_dag = template_dag
  
      self.substitution_list = []
      self.unmatched_list = []
  
      if custom_quantum_cost is not None:
          self.quantum_cost = dict(custom_quantum_cost)
      else:
          self.quantum_cost = {
              "Identity": 0,
              "PauliX": 1,
              "PauliY": 1,
              "PauliZ": 1,
              "RX": 1,
              "RY": 1,
              "RZ": 1,
              "Hadamard": 1,
              "T": 1,
              "Adjoint(T)": 1,
              "S": 1,
              "Adjoint(S)": 1,
              "CNOT": 2,
              "CZ": 4,
              "SWAP": 6,
              "CSWAP": 63,
              "Toffoli": 21,
          }
  
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 1 to create a new TemplateSubstitution object  with example: obj = TemplateSubstitution(max_matches, circuit_dag, template_dag, custom_quantum_cost)