code: def _run_minimization(
      Q_ini,
      M_source,
      M_target,
      weights=None,
      metric="euclid",
      tol_step=1e-9,
      maxiter=10_000,
      maxiter_linesearch=32,
  ):
      Q_1 = Q_ini
  
      # loop over iterations
      for _ in range(maxiter):
          # get the current value for the loss function
          F_1 = _loss(Q_1, M_target, M_source, weights, metric=metric)
  
          # get the direction of steepest descent
          direction = _project(
              Q_1,
              _grad(Q_1, M_target, M_source, weights, metric=metric),
          )
  
          # backtracking line search
          alpha = 1.0
          tau = 0.50
          r = 1e-4
          Q = _retract(Q_1, -alpha * direction)
          F = _loss(Q, M_target, M_source, weights, metric=metric)
          for _ in range(maxiter_linesearch):
              if F_1 - F > r * alpha * np.linalg.norm(direction) ** 2:
                  break
              alpha = tau * alpha
              Q = _retract(Q_1, -alpha * direction)
              F = _loss(Q, M_target, M_source, weights, metric=metric)
  
          # test if the step size is small
          crit = np.linalg.norm(-alpha * direction)
          if crit <= tol_step:
              break
  
          # update variables for next iteration
          Q_1 = Q
          F_1 = F
  
      else:
          warnings.warn("Convergence not reached.")
  
      return Q, F
  
file_path: pyRiemann/pyriemann/transfer/_rotate.py
imports: import warnings
  import numpy
  from ..utils.distance import distance
  from ..utils.utils import check_weights
label_desc: Use image node_id 6 for calling a global function with example usage: _run_minimization(Q_ini, M_source, M_target, weights, metric, tol_step, maxiter, maxiter_linesearch) and returns: Q,  F