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
  constant commuting terms.
docstr_tok: ["Test","that","the","generators","are","correct","for","a","Hamiltonian","with","multiple","constant","commuting","terms","."]
code: def test_with_commuting_const_terms_ham(self, terms, t):
      """Test that the generators are correct for a Hamiltonian with multiple
      constant commuting terms."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      num_terms = len(terms)
      H = qml.math.dot(
          [qml.pulse.constant for _ in range(num_terms)], terms
      )
      params = [jnp.array(0.4), jnp.array(0.9), jnp.array(-0.5)][
          :num_terms
      ]
      T = t[1] - t[0]
  
      op = qml.evolve(H, dense=True)(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)
      # A Hamiltonian with commuting terms and constant pulse envelopes yields
      # a product of rotation gates about its terms, with the effective rotation parameters
      # given by the duration of the constant pulse.
      for gen, term in zip(gens, terms):
          # The effective generator should have the shape of the pulse
          assert gen.shape == (dim, dim)
          expected = (
              -1j
              * T
              * expand_matrix(term.matrix(), term.wires, H.wires)
          )
          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 2 for calling the TestOneParameterGenerators obj's underlying member method code with example usage: obj.test_with_commuting_const_terms_ham(terms, t) without return types