code: def test_population_size() -> None:
      # Set `population_size` to 10.
      sampler = multi_objective.samplers.NSGAIIMultiObjectiveSampler(
          population_size=10
      )
  
      study = multi_objective.create_study(
          ["minimize"], sampler=sampler
      )
      study.optimize(
          lambda t: [t.suggest_float("x", 0, 9)], n_trials=40
      )
  
      generations = Counter(
          [
              t.system_attrs[
                  multi_objective.samplers._nsga2._GENERATION_KEY
              ]
              for t in study.trials
          ]
      )
      assert generations == {0: 10, 1: 10, 2: 10, 3: 10}
  
      # Set `population_size` to 2.
      sampler = multi_objective.samplers.NSGAIIMultiObjectiveSampler(
          population_size=2
      )
  
      study = multi_objective.create_study(
          ["minimize"], sampler=sampler
      )
      study.optimize(
          lambda t: [t.suggest_float("x", 0, 9)], n_trials=40
      )
  
      generations = Counter(
          [
              t.system_attrs[
                  multi_objective.samplers._nsga2._GENERATION_KEY
              ]
              for t in study.trials
          ]
      )
      assert generations == {i: 2 for i in range(20)}
  
      # Invalid population size.
      with pytest.raises(ValueError):
          # Less than 2.
          multi_objective.samplers.NSGAIIMultiObjectiveSampler(
              population_size=1
          )
  
      with pytest.raises(TypeError):
          # Not an integer.
          multi_objective.samplers.NSGAIIMultiObjectiveSampler(
              population_size=2.5
          )
  
file_path: optuna/tests/multi_objective_tests/samplers_tests/test_nsga2.py
imports: from collections import Counter
  from typing import List
  from typing import Tuple
  from unittest.mock import patch
  import pytest
  import optuna
  from optuna import multi_objective
  from optuna.study._study_direction import StudyDirection
label_desc: Use image node_id 1 for calling a global function with example usage: test_population_size() without return types