class_docstr: Test matrix method.
class_docstr_tok: ["Test","matrix","method","."]
docstr: Test matrix method for a time dependent hamiltonian. This test approximates the
  time-ordered exponential with a product of exponentials using small time steps.
  For more information, see https://en.wikipedia.org/wiki/Ordered_exponential.
docstr_tok: ["Test","matrix","method","for","a","time","dependent","hamiltonian",".","This","test","approximates","the","time-ordered","exponential","with","a","product","of","exponentials","using","small","time","steps",".","For","more","information",",","see","https",":","\/\/en.wikipedia.org\/wiki\/Ordered_exponential","."]
code: def test_time_dependent_hamiltonian(self):
      """Test matrix method for a time dependent hamiltonian. This test approximates the
      time-ordered exponential with a product of exponentials using small time steps.
      For more information, see https://en.wikipedia.org/wiki/Ordered_exponential.
      """
      import jax
      import jax.numpy as jnp
  
      H = time_dependent_hamiltonian()
  
      t = jnp.arange(0, jnp.pi / 4, 0.001)
      params = [1, 2]
      ev = ParametrizedEvolution(
          H=H, params=params, t=t, atol=1e-6, rtol=1e-6
      )
  
      def generator(params):
          for ti in t:
              yield jax.scipy.linalg.expm(
                  -1j * 0.001 * qml.matrix(H(params, t=ti))
              )
  
      true_mat = reduce(lambda x, y: y @ x, generator(params))
  
      assert qml.math.allclose(ev.matrix(), true_mat, atol=1e-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 2 for calling the TestMatrix obj's underlying member method code with example usage: obj.test_time_dependent_hamiltonian() without return types