code: def test_grid_search(named_model_space, engine, shuffle, dedup):
      name, model_space = named_model_space
      strategy = GridSearch(shuffle=shuffle, dedup=dedup)
      assert (
          repr(strategy)
          == f"GridSearch(shuffle={shuffle}, dedup={dedup})"
      )
      strategy(model_space, engine)
      if name == "base":
          assert len(list(engine.list_models())) == 24
      elif name == "constraint":
          assert len(list(engine.list_models())) == 12
      if name != "numerical":
          samples = [model.sample for model in engine.list_models()]
          expected_samples = [
              model.sample for model in model_space.grid()
          ]
          if shuffle:
              assert samples != expected_samples
          else:
              assert samples == expected_samples
      if shuffle and not dedup:
          assert next(strategy.list_models()).metric > 0.8
      else:
          assert (
              next(strategy.list_models()).metric == 1.0
          )  # optimal is always normalized to be 1.0
  
      with pytest.raises(
          RuntimeError, match="already been initialized"
      ):
          strategy(model_space, engine)
  
      # Strategy resume.
      state_dict = strategy.state_dict()
      previous_submitted = len(list(engine.list_models()))
      if name == "numerical":
          if shuffle or not dedup:
              assert state_dict["no_sample_found_counter"] == 0
          else:
              assert state_dict["no_sample_found_counter"] > 0
          if (
              not shuffle
          ):  # otherwise the first shuffle batch could not be exhausted.
              assert state_dict["granularity"] > 1
      else:
          assert state_dict["no_sample_found_counter"] == 0
          assert state_dict["granularity"] == 1
      assert "random_state" in state_dict and isinstance(
          state_dict["random_state"], tuple
      )
      strategy2 = GridSearch(shuffle=shuffle, dedup=dedup)
      strategy2.load_state_dict(state_dict)
  
      strategy2(model_space, engine)
      if dedup:
          assert len(list(engine.list_models())) == previous_submitted
  
imports: from __future__ import annotations
  import pytest
  import nni
  from nni.mutable import *
  from nni.nas.evaluator import FunctionalEvaluator
  from nni.nas.execution import SequentialExecutionEngine
  from nni.nas.space import *
  from nni.nas.strategy import GridSearch, Random, RegularizedEvolution, PolicyBasedRL
  import torch
  from torch import nn
  from tianshou.policy import A2CPolicy
  from tianshou.data import to_torch
label_desc: Use image node_id 4 for calling a global function with example usage: test_grid_search(named_model_space, engine, shuffle, dedup) without return types