class_docstr: Test integration of pwc functions with the pulse module.
class_docstr_tok: ["Test","integration","of","pwc","functions","with","the","pulse","module","."]
docstr: Test that a function decorated by pwc_from_function can be used to create a ParametrizedHamiltonian
docstr_tok: ["Test","that","a","function","decorated","by","pwc_from_function","can","be","used","to","create","a","ParametrizedHamiltonian"]
code: def test_parametrized_hamiltonian_with_pwc_from_function(self):
      """Test that a function decorated by pwc_from_function can be used to create a ParametrizedHamiltonian"""
  
      @qml.pulse.pwc_from_function((2, 5), 20)
      def f1(params, t):
          return params + t
  
      @qml.pulse.pwc_from_function((3, 7), 10)
      def f2(params, t):
          return params[0] + params[1] * t**2
  
      H = f1 * qml.PauliX(0) + f2 * qml.PauliY(1)
      params = [1.2, [2.3, 3.4]]
  
      assert isinstance(H, ParametrizedHamiltonian)
  
      # at t=8 and t=1, both terms are 0
      assert qml.math.allequal(qml.matrix(H(params, t=8)), 0)
      assert qml.math.allequal(qml.matrix(H(params, t=1)), 0)
  
      # at t=2.5, only term 1 is non-zero
      true_mat = qml.matrix(
          f1(params[0], 2.5) * qml.PauliX(0), wire_order=[0, 1]
      )
      assert qml.math.allequal(qml.matrix(H(params, t=2.5)), true_mat)
  
      # # at t=6, only term 2 is non-zero
      true_mat = qml.matrix(
          f2(params[1], 6) * qml.PauliY(1), wire_order=[0, 1]
      )
      assert qml.math.allequal(qml.matrix(H(params, t=6)), true_mat)
      #
      # # at t=4, both are non-zero and output is as expected
      true_mat = qml.matrix(
          f1(params[0], 4) * qml.PauliX(0), wire_order=[0, 1]
      ) + qml.matrix(
          f2(params[1], 4) * qml.PauliY(1), wire_order=[0, 1]
      )
      assert qml.math.allequal(qml.matrix(H(params, t=4)), true_mat)
  
imports: import inspect
  from functools import partial
  import numpy
  import pytest
  import pennylane
  from pennylane.pulse.parametrized_hamiltonian import ParametrizedHamiltonian
label_desc: Use image node_id 5 for calling the TestIntegration obj's underlying member method code with example usage: obj.test_parametrized_hamiltonian_with_pwc_from_function() and returns: unknown, unknown