class_docstr: Test the utility function _one_parameter_generators.
class_docstr_tok: ["Test","the","utility","function","_one_parameter_generators","."]
docstr: Test that the generators are correct for a Hamiltonian with multiple
  commuting time-dependent terms.
docstr_tok: ["Test","that","the","generators","are","correct","for","a","Hamiltonian","with","multiple","commuting","time-dependent","terms","."]
code: def test_with_commuting_timedep_terms_ham(self, terms, t):
      """Test that the generators are correct for a Hamiltonian with multiple
      commuting time-dependent terms."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      num_terms = len(terms)
      H = qml.math.dot([jnp.polyval for _ in range(num_terms)], terms)
      params = [
          jnp.array([0.4, 0.1, 0.2]),
          jnp.array([0.9, -0.2, 0.5]),
          jnp.array([-0.5, 0.2]),
      ]
      params = params[:num_terms]
      # Jacobian functions of the effective rotation parameter (all polyval)
      par_fn_jac_fn = jax.grad(integral_of_polyval)
      # Jacobian of the effective rotation parameter for the different terms
      par_fn_jac = [par_fn_jac_fn(p, t) for p in params]
  
      op = qml.evolve(H, dense=True, atol=1e-9)(params, t)
      gens = _one_parameter_generators(op)
  
      # op has as many parameters in its parameter input list as there are terms,
      # so generators should be a tuple with as many entries as Hamiltonian terms.
      assert isinstance(gens, tuple)
      assert len(gens) == num_terms
      dim = 2 ** len(H.wires)
      for gen, term, p, jac in zip(gens, terms, params, par_fn_jac):
          # The effective generator should have the shape of the parameters and the pulse
          # together. Here, the parameters are one-dimensional, so we get (num_params, dim, dim)
          assert gen.shape == (len(p), dim, dim)
          expected = jnp.tensordot(
              jac,
              -1j * expand_matrix(term.matrix(), term.wires, H.wires),
              axes=0,
          )
          assert qml.math.allclose(gen, expected)
  
imports: import copy
  import pytest
  import numpy
  import pennylane
  from pennylane import numpy
  from pennylane.ops.qubit.special_unitary import pauli_basis_matrices, pauli_basis_strings
  from pennylane.math import expand_matrix
  from pennylane.gradients.pulse_gradient_odegen import _generate_tapes_and_coeffs, pulse_odegen, _insert_op, _nonzero_coeffs_and_words, _one_parameter_generators, _one_parameter_paulirot_coeffs, _parshift_and_contract
label_desc: Use image node_id 5 for calling the TestOneParameterGenerators obj's underlying member method code with example usage: obj.test_with_commuting_timedep_terms_ham(terms, t) without return types