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 pwc function can be used to create a ParametrizedHamiltonian
docstr_tok: ["Test","that","a","pwc","function","can","be","used","to","create","a","ParametrizedHamiltonian"]
code: def test_parametrized_hamiltonian_with_pwc(self):
      """Test that a pwc function can be used to create a ParametrizedHamiltonian"""
  
      f1 = qml.pulse.pwc((1, 6))
      f2 = qml.pulse.pwc((0.5, 3))
      H = f1 * qml.PauliX(0) + f2 * qml.PauliY(1)
  
      constants = np.linspace(0, 9, 10)
  
      assert isinstance(H, ParametrizedHamiltonian)
  
      # at t=7 and t=0.2, both terms are 0
      assert qml.math.allequal(
          qml.matrix(H(params=[constants, constants], t=7)), 0
      )
      assert qml.math.allequal(
          qml.matrix(H(params=[constants, constants], t=0.2)), 0
      )
  
      # at t=4, only term 1 is non-zero
      true_mat = qml.matrix(
          f1(constants, 4) * qml.PauliX(0), wire_order=[0, 1]
      )
      assert qml.math.allequal(
          qml.matrix(H(params=[constants, constants], t=4)), true_mat
      )
  
      # at t=0.7, only term 2 is non-zero
      true_mat = qml.matrix(
          f2(constants, 0.7) * qml.PauliY(1), wire_order=[0, 1]
      )
      assert qml.math.allequal(
          qml.matrix(H(params=[constants, constants], t=0.7)), true_mat
      )
  
      # at t=1.5, both are non-zero and output is as expected
      true_mat = qml.matrix(
          f1(constants, 1.5) * qml.PauliX(0), wire_order=[0, 1]
      ) + qml.matrix(
          f2(constants, 1.5) * qml.PauliY(1), wire_order=[0, 1]
      )
      assert qml.math.allequal(
          qml.matrix(H(params=[constants, constants], t=1.5)), 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 2 for calling the TestIntegration obj's underlying member method code with example usage: obj.test_parametrized_hamiltonian_with_pwc() without return types