code: def _measure_hamiltonian_with_samples(
      mp: List[SampleMeasurement],
      state: np.ndarray,
      shots: Shots,
      is_state_batched: bool = False,
      rng=None,
      prng_key=None,
  ):
      # the list contains only one element based on how we group measurements
      mp = mp[0]
  
      # if the measurement process involves a Hamiltonian, measure each
      # of the terms separately and sum
      def _sum_for_single_shot(s):
          results = measure_with_samples(
              [ExpectationMP(t) for t in mp.obs.terms()[1]],
              state,
              s,
              is_state_batched=is_state_batched,
              rng=rng,
              prng_key=prng_key,
          )
          return sum(
              c * res for c, res in zip(mp.obs.terms()[0], results)
          )
  
      unsqueezed_results = tuple(
          _sum_for_single_shot(type(shots)(s)) for s in shots
      )
      return (
          [unsqueezed_results]
          if shots.has_partitioned_shots
          else [unsqueezed_results[0]]
      )
  
file_path: pennylane/pennylane/devices/qubit/sampling.py
imports: from typing import List, Union, Tuple
  import numpy
  import pennylane
  from pennylane.ops import Sum, Hamiltonian, SProd, Prod
  from pennylane.measurements import SampleMeasurement, Shots, ExpectationMP, ClassicalShadowMP, ShadowExpvalMP, CountsMP
  from pennylane.typing import TensorLike
  from .apply_operation import apply_operation
  from .measure import flatten_state
label_desc: Use image node_id 7 for calling a global function with example usage: _measure_hamiltonian_with_samples(mp, state, shots, is_state_batched, rng, prng_key) and returns: unknown, sum