class_docstr: Pattern matching circuit optimization tests.
class_docstr_tok: ["Pattern","matching","circuit","optimization","tests","."]
docstr: Test pattern matching algorithm for vbe_adder_3 with a CNOTs template.
docstr_tok: ["Test","pattern","matching","algorithm","for","vbe_adder_3","with","a","CNOTs","template","."]
code: def test_vbe_adder_3_pattern_matching(self):
      """Test pattern matching algorithm for vbe_adder_3 with a CNOTs template."""
  
      def vbe_adder_3():
          qml.T(wires=7)
          qml.T(wires=8)
          qml.Hadamard(wires=3)
          qml.CNOT(wires=[2, 3])
          qml.adjoint(qml.T)(wires=3)
          qml.CNOT(wires=[1, 3])
          qml.CNOT(wires=[2, 3])
          qml.adjoint(qml.T)(wires=3)
          qml.CNOT(wires=[1, 3])
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[2, 3])
          qml.CNOT(wires=[0, 3])
          qml.T(wires=3)
          qml.CNOT(wires=[2, 3])
          qml.adjoint(qml.T)(wires=3)
          qml.CNOT(wires=[0, 3])
          qml.S(wires=3)
          qml.Hadamard(wires=3)
          qml.Hadamard(wires=6)
          qml.CNOT(wires=[5, 6])
          qml.adjoint(qml.T)(wires=6)
          qml.CNOT(wires=[4, 6])
          qml.CNOT(wires=[5, 6])
          qml.adjoint(qml.T)(wires=6)
          qml.CNOT(wires=[4, 6])
          qml.CNOT(wires=[4, 5])
          qml.CNOT(wires=[4, 6])
          qml.CNOT(wires=[3, 6])
          qml.T(wires=6)
          qml.CNOT(wires=[5, 6])
          qml.adjoint(qml.T)(wires=6)
          qml.CNOT(wires=[3, 6])
          qml.S(wires=6)
          qml.Hadamard(wires=6)
          qml.T(wires=6)
          qml.Hadamard(wires=9)
          qml.CNOT(wires=[8, 9])
          qml.adjoint(qml.T)(wires=9)
          qml.CNOT(wires=[7, 9])
          qml.CNOT(wires=[8, 9])
          qml.adjoint(qml.T)(wires=9)
          qml.CNOT(wires=[7, 9])
          qml.CNOT(wires=[7, 8])
          qml.CNOT(wires=[8, 9])
          qml.CNOT(wires=[6, 9])
          qml.T(wires=9)
          qml.CNOT(wires=[8, 9])
          qml.adjoint(qml.T)(wires=9)
          qml.CNOT(wires=[6, 9])
          qml.T(wires=9)
          qml.CNOT(wires=[6, 8])
          qml.adjoint(qml.T)(wires=8)
          qml.Hadamard(wires=9)
          qml.Hadamard(wires=6)
          qml.adjoint(qml.T)(wires=6)
          qml.CNOT(wires=[5, 6])
          qml.CNOT(wires=[3, 6])
          qml.adjoint(qml.T)(wires=6)
          qml.CNOT(wires=[5, 6])
          qml.T(wires=6)
          qml.CNOT(wires=[3, 6])
          qml.CNOT(wires=[4, 5])
          qml.CNOT(wires=[5, 6])
          qml.T(wires=6)
          qml.CNOT(wires=[4, 6])
          qml.CNOT(wires=[5, 6])
          qml.T(wires=6)
          qml.CNOT(wires=[4, 6])
          qml.CNOT(wires=[3, 5])
          qml.CNOT(wires=[4, 5])
          qml.Hadamard(wires=6)
          qml.Hadamard(wires=3)
          qml.adjoint(qml.S)(wires=3)
          qml.CNOT(wires=[2, 3])
          qml.CNOT(wires=[0, 3])
          qml.adjoint(qml.T)(wires=3)
          qml.CNOT(wires=[2, 3])
          qml.T(wires=3)
          qml.CNOT(wires=[0, 3])
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[2, 3])
          qml.T(wires=3)
          qml.CNOT(wires=[1, 3])
          qml.CNOT(wires=[2, 3])
          qml.T(wires=3)
          qml.CNOT(wires=[1, 3])
          qml.CNOT(wires=[0, 2])
          qml.CNOT(wires=[1, 2])
          qml.Hadamard(wires=3)
          return qml.expval(qml.PauliX(wires=0))
  
      with qml.queuing.AnnotatedQueue() as q_template:
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[0, 1])
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[0, 1])
          qml.CNOT(wires=[0, 2])
  
      template = qml.tape.QuantumScript.from_queue(q_template)
      dev = qml.device("default.qubit", wires=10)
  
      qnode = qml.QNode(vbe_adder_3, dev)
      qnode()
  
      optimized_qfunc = pattern_matching_optimization(
          vbe_adder_3, pattern_tapes=[template]
      )
      optimized_qnode = qml.QNode(optimized_qfunc, dev)
      optimized_qnode()
  
      cnots_qnode = qml.specs(qnode)()["resources"].gate_types["CNOT"]
      cnots_optimized_qnode = qml.specs(optimized_qnode)()[
          "resources"
      ].gate_types["CNOT"]
  
      assert len(qnode.qtape.operations) == 89
      assert cnots_qnode == 50
  
      assert len(optimized_qnode.qtape.operations) == 84
      assert cnots_optimized_qnode == 45
  
      assert np.allclose(
          qml.matrix(optimized_qnode)(), qml.matrix(qnode)()
      )
  
imports: import pytest
  import pennylane
  import pennylane.numpy
  from pennylane.transforms.commutation_dag import commutation_dag
  from pennylane.transforms.optimization.pattern_matching import pattern_matching, pattern_matching_optimization, ForwardMatch, BackwardMatch, _update_qubits
label_desc: Use image node_id 13 for calling the TestPatternMatchingOptimization obj's underlying member method code with example usage: obj.test_vbe_adder_3_pattern_matching() and returns: qml