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 single-term time-dependent Hamiltonian.
docstr_tok: ["Test","that","the","generators","are","correct","for","a","single-term","time-dependent","Hamiltonian","."]
code: def test_with_single_timedep_term_ham(self, term, t):
      """Test that the generators are correct for a single-term time-dependent Hamiltonian."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      H = jnp.polyval * term
      params = [jnp.array([0.4, 0.2, 0.1])]
      # Jacobian of the effective rotation parameter
      par_fn_jac = jax.grad(integral_of_polyval)(params[0], t)
  
      op = qml.evolve(H)(params, t)
      gens = _one_parameter_generators(op)
  
      # op has a single parameter in its parameter input list, so the
      # generators should be a length-1 tuple.
      assert isinstance(gens, tuple)
      assert len(gens) == 1
      gen = gens[0]
      # 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(params[0]),
          dim := 2 ** len(term.wires),
          dim,
      )
      # The outer product of the rotation parameter Jacobian and the matrix of
      # the Hamiltonian term yields the Jacobian of the pulse
      expected = jnp.tensordot(par_fn_jac, -1j * term.matrix(), 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 4 for calling the TestOneParameterGenerators obj's underlying member method code with example usage: obj.test_with_single_timedep_term_ham(term, t) without return types