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 constant Hamiltonian.
docstr_tok: ["Test","that","the","generators","are","correct","for","a","single-term","constant","Hamiltonian","."]
code: def test_with_single_const_term_ham(self, term, t):
      """Test that the generators are correct for a single-term constant Hamiltonian."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      H = qml.pulse.constant * term
      params = [jnp.array(0.4)]
      T = t[1] - t[0]
  
      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 pulse
      assert gen.shape == (2 ** len(term.wires),) * 2
      # A Hamiltonian with a single term and a constant pulse envelope yields
      # a rotation gate about said term, with the effective rotation parameter
      # given by the duration of the constant pulse.
      expected = -1j * T * term.matrix()
      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 1 for calling the TestOneParameterGenerators obj's underlying member method code with example usage: obj.test_with_single_const_term_ham(term, t) without return types