class_docstr: Unit tests for the ParametrizedEvolution class.
class_docstr_tok: ["Unit","tests","for","the","ParametrizedEvolution","class","."]
docstr: Test that the matrix is reused if it already exists in the cache, instead
  of being added to the cache a second time
docstr_tok: ["Test","that","the","matrix","is","reused","if","it","already","exists","in","the","cache",",","instead","of","being","added","to","the","cache","a","second","time"]
code: def test_label_reuses_cached_matrices(self):
      """Test that the matrix is reused if it already exists in the cache, instead
      of being added to the cache a second time"""
  
      H = (
          qml.PauliX(1)
          + qml.pulse.constant * qml.PauliY(0)
          + np.polyval * qml.PauliY(1)
          + np.polyval * qml.PauliY(2)
      )
      cache = {"matrices": []}
  
      params1 = [3, np.array([0.23, 0.47, 5]), np.array([3.4, 6.8])]
      params2 = [
          5.67,
          np.array([0.23, 0.47, 5]),
          np.array([[3.7, 6.2], [1.2, 4.6]]),
      ]
      op1 = qml.evolve(H)(params1, 2)
      op2 = qml.evolve(H)(params2, 2)
  
      assert (
          op1.label(decimals=2, cache=cache)
          == "Parametrized\nEvolution\n(p=[3.00,M0,M1], t=[0. 2.])"
      )
      assert len(cache["matrices"]) == 2
      assert np.all(cache["matrices"][0] == params1[1])
      assert np.all(cache["matrices"][1] == params1[2])
  
      assert (
          op2.label(decimals=2, cache=cache)
          == "Parametrized\nEvolution\n(p=[5.67,M0,M2], t=[0. 2.])"
      )
      assert len(cache["matrices"]) == 3
      assert np.all(cache["matrices"][0] == params2[1])
      assert np.all(cache["matrices"][2] == params2[2])
  
imports: from functools import reduce
  import numpy
  import pytest
  import pennylane
  from pennylane.operation import AnyWires
  from pennylane.ops import QubitUnitary
  from pennylane.pulse import ParametrizedEvolution, ParametrizedHamiltonian
  from pennylane.tape import QuantumTape
  from pennylane.devices import DefaultQubit, DefaultQubitLegacy
label_desc: Use image node_id 16 for calling the TestInitialization obj's underlying member method code with example usage: obj.test_label_reuses_cached_matrices() without return types