class_docstr: Pattern matching circuit optimization tests.
class_docstr_tok: ["Pattern","matching","circuit","optimization","tests","."]
docstr: Test pattern matching algorithm for circuit optimization with parameters.
docstr_tok: ["Test","pattern","matching","algorithm","for","circuit","optimization","with","parameters","."]
code: def test_parametrized_pattern_matching(self):
      """Test pattern matching algorithm for circuit optimization with parameters."""
  
      def circuit(x, y):
          qml.Toffoli(wires=[3, 4, 0])
          qml.RZ(x, wires=[0])
          qml.RZ(-x, wires=[0])
          qml.RZ(-x, wires=[1])
          qml.CNOT(wires=[1, 4])
          qml.RZ(x, wires=[1])
          qml.CNOT(wires=[2, 1])
          qml.Hadamard(wires=3)
          qml.PauliZ(wires=1)
          qml.RX(y, wires=[3])
          qml.CNOT(wires=[2, 3])
          qml.RX(-y, wires=[3])
          qml.Toffoli(wires=[2, 3, 0])
          qml.CNOT(wires=[1, 4])
          return qml.expval(qml.PauliX(wires=0))
  
      with qml.queuing.AnnotatedQueue() as q_template_rz:
          qml.RZ(0.1, wires=[0])
          qml.RZ(-0.1, wires=[0])
  
      template_rz = qml.tape.QuantumScript.from_queue(q_template_rz)
      with qml.queuing.AnnotatedQueue() as q_template_rx:
          qml.RX(0.2, wires=[0])
          qml.RX(-0.2, wires=[0])
  
      template_rx = qml.tape.QuantumScript.from_queue(q_template_rx)
      dev = qml.device("default.qubit", wires=5)
  
      qnode = qml.QNode(circuit, dev)
      qnode(0.1, 0.2)
  
      optimized_qfunc = pattern_matching_optimization(
          circuit, pattern_tapes=[template_rx, template_rz]
      )
      optimized_qnode = qml.QNode(optimized_qfunc, dev)
      optimized_qnode(0.1, 0.2)
  
      rx_qnode = qml.specs(qnode)(0.1, 0.2)["resources"].gate_types[
          "RX"
      ]
      rx_optimized_qnode = qml.specs(optimized_qnode)(0.1, 0.2)[
          "resources"
      ].gate_types["RX"]
  
      rz_qnode = qml.specs(qnode)(0.1, 0.2)["resources"].gate_types[
          "RZ"
      ]
      rz_optimized_qnode = qml.specs(optimized_qnode)(0.1, 0.2)[
          "resources"
      ].gate_types["RZ"]
  
      assert len(qnode.qtape.operations) == 14
      assert rx_qnode == 2
      assert rz_qnode == 4
  
      assert len(optimized_qnode.qtape.operations) == 8
      assert rx_optimized_qnode == 0
      assert rz_optimized_qnode == 0
  
      assert np.allclose(
          qml.matrix(optimized_qnode)(0.1, 0.2),
          qml.matrix(qnode)(0.1, 0.2),
      )
  
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 10 for calling the TestPatternMatchingOptimization obj's underlying member method code with example usage: obj.test_parametrized_pattern_matching() and returns: qml