class_docstr: Unit tests testing the integration of convenience functions with parametrized hamiltonians.
class_docstr_tok: ["Unit","tests","testing","the","integration","of","convenience","functions","with","parametrized","hamiltonians","."]
docstr: Test that convenience functions can be used to define parametrized hamiltonians.
docstr_tok: ["Test","that","convenience","functions","can","be","used","to","define","parametrized","hamiltonians","."]
code: def test_parametrized_hamiltonian(self):
      """Test that convenience functions can be used to define parametrized hamiltonians."""
  
      def f1(p, t):
          return p * t
  
      windows1 = [(0, 0.5), (1, 1.5)]
  
      coeffs = [qml.pulse.rect(f1, windows1), qml.pulse.constant]
      ops = [qml.PauliX(0), qml.PauliY(1)]
      H = qml.dot(coeffs, ops)
  
      assert isinstance(H, ParametrizedHamiltonian)
      # assert that at t=0.3 both coefficients are non-zero
      true_mat = qml.matrix(
          f1(1, 0.3) * qml.PauliX(0) + 2 * qml.PauliY(1),
          wire_order=[0, 1],
      )
      assert qml.math.allclose(
          qml.matrix(H(params=[1, 2], t=0.3)), true_mat
      )
      # assert that at t=0.7 only the second coefficient is non-zero
      true_mat = qml.matrix(2 * qml.PauliY(1), wire_order=[0, 1])
      assert qml.math.allclose(
          qml.matrix(H(params=[1, 2], t=0.7)), true_mat
      )
  
imports: import inspect
  from functools import reduce
  import numpy
  import pytest
  import pennylane
  from pennylane.pulse import ParametrizedHamiltonian
label_desc: Use image node_id 1 for calling the TestIntegration obj's underlying member method code with example usage: obj.test_parametrized_hamiltonian() and returns: unknown