code: def test_nsga2_ranking_4():
      params = ng.p.Tuple(ng.p.Scalar(lower=0, upper=2))
      loss_values = [0.0, 1.0, -10.0, 1.0, 3.0, 1.0]
      candidates: tp.List[p.Parameter] = []
      for v in loss_values:
          candidate = params.spawn_child().set_standardized_data(v)
          candidate.loss = np.array(v)
          candidates.append(candidate)
  
      n_selected = 3
      rank_result = nsga2.rank(candidates, n_selected)
      candidates.sort(
          key=lambda x: rank_result[x.uid][0]
          if x.uid in rank_result
          else float("inf")
      )
      loss_from_rank = [r.loss for r in candidates[:n_selected]]
      loss_from_sorted = [
          np.array(v) for v in sorted(loss_values)[:n_selected]
      ]
      assert loss_from_rank == loss_from_sorted
  
file_path: nevergrad/nevergrad/optimization/multiobjective/test_nsga2.py
imports: import random
  import numpy
  import nevergrad
  import nevergrad.common.typing
  from nevergrad.parametrization import parameter
  from .None import nsga2
label_desc: Use image node_id 7 for calling a global function with example usage: test_nsga2_ranking_4() without return types