class_docstr: Test integration of pwc functions with the pulse module.
class_docstr_tok: ["Test","integration","of","pwc","functions","with","the","pulse","module","."]
docstr: Helper function that integrates a pwc function.
docstr_tok: ["Helper","function","that","integrates","a","pwc","function","."]
code: def integral_pwc(  # pylint:disable = too-many-arguments
      self,
      t1,
      t2,
      num_bins,
      integration_bounds,
      fn,
      params,
      pwc_from_function=False,
  ):
      """Helper function that integrates a pwc function."""
      from jax import numpy as jnp
  
      # constants set by array if pwc, constants must be found if pwc_from_function
      constants = jnp.array(params)
      if pwc_from_function:
          time_bins = np.linspace(t1, t2, num_bins)
          constants = jnp.array(list(fn(params, time_bins)) + [0])
  
      # get start and end point as indicies, without casting to int
      start = num_bins / (t2 - t1) * (integration_bounds[0] - t1)
      end = num_bins / (t2 - t1) * (integration_bounds[1] - t1)
  
      # get indices of bins that are completely within the integration window
      complete_indices = np.linspace(
          int(start) + 1,
          int(end) - 1,
          int(end) - int(start) - 1,
          dtype=int,
      )
      relevant_indices = np.array(
          [i for i in complete_indices if -1 < i < num_bins]
      )
      # find area contributed by bins that are completely within the integration window
      bin_width = (t2 - t1) / num_bins
      main_area = np.sum(constants[relevant_indices] * bin_width)
  
      # if start index is not out of range, add contribution from partial bin at start
      if start >= 0:
          width = bin_width * 1 - (start - int(start))
          main_area += constants[int(start)] * width
  
      # if end index is not out of range, add contribution from partial bin at end
      if end < num_bins:
          width = bin_width * (end - int(end))
          main_area += constants[int(end)] * width
  
      return main_area
  
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 1 for calling the TestIntegration obj's underlying member method code with example usage: obj.integral_pwc(t1, t2, num_bins, integration_bounds, fn, params, pwc_from_function) and returns: main_area