code: def optimise_partition(self, partition, n_iterations=2):
      
  
      itr = 0
      diff = 0
      continue_iteration = itr < n_iterations or n_iterations < 0
      while continue_iteration:
        diff_inc = _c_leiden._Optimiser_optimise_partition(self._optimiser, partition._partition)
        diff += diff_inc
        itr += 1
        if n_iterations < 0:
          continue_iteration = (diff_inc > 0)
        else:
          continue_iteration = itr < n_iterations
  
      partition._update_internal_membership()
      return diff
docs: Optimise the given partition.
  
      Parameters
      ----------
      partition
        The :class:`~VertexPartition.MutableVertexPartition` to optimise.
  
      n_iterations : int
        Number of iterations to run the Leiden algorithm. By default, 2 iterations
        are run. If the number of iterations is negative, the Leiden algorithm is
        run until an iteration in which there was no improvement.
  
      Returns
      -------
      float
        Improvement in quality function.
  
      Examples
      --------
  
      >>> G = ig.Graph.Famous('Zachary')
      >>> optimiser = la.Optimiser()
      >>> partition = la.ModularityVertexPartition(G)
      >>> diff = optimiser.optimise_partition(partition)