docs: def calculate_boundaries(fine_states, full_magnetic_states):
      r"""Calculate the boundary indices within a list of magnetic states.
  
      This function calculates the boundary indices of each fine state
      and each hyperfine state within a list of magnetic states. The output
      is a list of tuples (a,b) with a the starting index of a state and
      b it's ending index.
  
      >>> g=State("Rb", 87, 5, 0, 1/Integer(2))
      >>> full_magnetic_states=make_list_of_states([g],"magnetic")
      >>> calculate_boundaries([g], full_magnetic_states)
      ([(0, 8)], [(0, 3), (3, 8)])
  
      """
      N_magnetic = len(full_magnetic_states)
  
      # We calculate the boundaries of the various detail levels
      # First we will make a list of indices of that will tell where each fine
      # level begins and ends.
      fq = full_magnetic_states[0].quantum_numbers[:4]
      index_list_fine = []; start_fine = 0
      # And another list of indices that will tell where each hyperfine level
      # begins and ends.
      hq = full_magnetic_states[0].quantum_numbers[:5]
      index_list_hyperfine = []; start_hyperfine = 0
  
      for i in range(N_magnetic):
          magnetic = full_magnetic_states[i]
          if magnetic.quantum_numbers[:4] != fq:
              index_list_fine += [(start_fine, i)]
              start_fine = i
              fq = magnetic.quantum_numbers[:4]
  
          if magnetic.quantum_numbers[:5] != hq:
              index_list_hyperfine += [(start_hyperfine, i)]
              start_hyperfine = i
              hq = magnetic.quantum_numbers[:5]
  
          if i == N_magnetic-1:
              index_list_fine += [(start_fine, i+1)]
              index_list_hyperfine += [(start_hyperfine, i+1)]
      return index_list_fine, index_list_hyperfine