class_docstr: Test matrix method.
class_docstr_tok: ["Test","matrix","method","."]
docstr: Test that intermediate time evolution matrices are returned.
docstr_tok: ["Test","that","intermediate","time","evolution","matrices","are","returned","."]
code: def test_return_intermediate_and_complementary(self, comp, len_t):
      """Test that intermediate time evolution matrices are returned."""
      import jax
      from jax import numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      H = time_independent_hamiltonian()
      t = np.linspace(0.4, 0.7, len_t)
      params = [1, 2]
      ev = ParametrizedEvolution(
          H=H,
          params=params,
          t=t,
          return_intermediate=True,
          complementary=comp,
          rtol=1e-10,
      )
      matrices = ev.matrix()
      assert isinstance(matrices, jnp.ndarray)
      assert matrices.shape == (len_t, 4, 4)
  
      H_mat = qml.matrix(H(params, t=t[-1]))
      if comp:
          true_matrices = [
              qml.math.expm(-1j * H_mat * (t[-1] - _t)) for _t in t
          ]
      else:
          true_matrices = [
              qml.math.expm(-1j * H_mat * (_t - t[0])) for _t in t
          ]
      assert qml.math.allclose(
          matrices, true_matrices, atol=1e-6, rtol=0.0
      )
  
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 3 for calling the TestMatrix obj's underlying member method code with example usage: obj.test_return_intermediate_and_complementary(comp, len_t) without return types