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 the evolution of a parametrized hamiltonian defined with a pwc function be executed on a QNode.
docstr_tok: ["Test","that","the","evolution","of","a","parametrized","hamiltonian","defined","with","a","pwc","function","be","executed","on","a","QNode","."]
code: def test_qnode_pwc(self):
      """Test that the evolution of a parametrized hamiltonian defined with a pwc function be executed on a QNode."""
      import jax
  
      f1 = qml.pulse.pwc((1, 6))
      f2 = qml.pulse.pwc((0.5, 3))
      H = f1 * qml.PauliX(0) + f2 * qml.PauliY(1)
  
      t = (0, 4)
  
      dev = qml.device("default.qubit", wires=2)
  
      @qml.qnode(dev, interface="jax")
      def circuit(params):
          qml.evolve(H)(params=params, t=t)
          return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
  
      @qml.qnode(dev, interface="jax")
      def true_circuit(params):
          # ops X0 and Y1 are commuting - time evolution of f1*X0 + f2*X1 is exp(-i*F1*X0)exp(-i*F2*Y1)
          # Where Fj = integral of fj(p,t)dt over evolution time t
          coeff1 = partial(self.integral_pwc, 1, 6, 10, (0, 4), f1)
          coeff2 = partial(self.integral_pwc, 0.5, 3, 10, (0, 4), f2)
          qml.prod(
              qml.exp(qml.PauliX(0), -1j * coeff1(params[0])),
              qml.exp(qml.PauliY(1), -1j * coeff2(params[1])),
          )
          return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
  
      constants = np.linspace(0, 9, 10)
      params = [constants, constants]
  
      assert qml.math.allclose(
          circuit(params), true_circuit(params), atol=5e-3
      )
      assert qml.math.allclose(
          jax.grad(circuit)(params),
          jax.grad(true_circuit)(params),
          atol=5e-3,
      )
  
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 3 for calling the TestIntegration obj's underlying member method code with example usage: obj.test_qnode_pwc() and returns: qml, qml