code: def test_mutable_dict():
      a = MutableDict({"a": 1, "b": Categorical([1, 2, 3]), "c": 3})
      assert list(a.default().values()) == [1, 1, 3]
      assert list(a.default().keys()) == ["a", "b", "c"]
      assert list(a.grid()) == [
          {"a": 1, "b": 1, "c": 3},
          {"a": 1, "b": 2, "c": 3},
          {"a": 1, "b": 3, "c": 3},
      ]
      a.pop("b")
      assert list(a.grid()) == [
          {"a": 1, "c": 3},
      ]
      assert a.random() == {"a": 1, "c": 3}
      a["b"] = Numerical(0, 1)
      assert a.default() == {"a": 1, "b": 0.5, "c": 3}
      assert list(a.default().values()) == [1, 3, 0.5]
  
      search_space = MutableDict(
          {
              "trainer": MutableDict(
                  {
                      "optimizer": Categorical(["sgd", "adam"]),
                      "learning_rate": Numerical(
                          1e-4, 1e-2, log_distributed=True
                      ),
                      "decay_epochs": MutableList(
                          [Categorical([10, 20]), Categorical([30, 50])]
                      ),
                  }
              ),
              "model": MutableDict(
                  {
                      "type": Categorical(["resnet18", "resnet50"]),
                      "pretrained": Categorical([True, False]),
                  }
              ),
          }
      )
  
      assert len(search_space.random()) == 2
      assert len(list(search_space.grid(granularity=2))) == 96
  
      keys = list(search_space.simplify().keys())
  
      sample = search_space.freeze(
          {
              keys[0]: "adam",
              keys[1]: 0.0001,
              keys[2]: 10,
              keys[3]: 50,
              keys[4]: "resnet50",
              keys[5]: False,
          }
      )
      assert sample["trainer"]["decay_epochs"][1] == 50
  
      search_space = MutableList(
          [
              MutableDict(
                  {
                      "in_features": Categorical(
                          [10, 20], label="hidden_dim"
                      ),
                      "out_features": Categorical(
                          [10, 20], label="hidden_dim"
                      )
                      * 2,
                  }
              ),
              MutableDict(
                  {
                      "in_features": Categorical(
                          [10, 20], label="hidden_dim"
                      )
                      * 2,
                      "out_features": Categorical(
                          [10, 20], label="hidden_dim"
                      )
                      * 4,
                  }
              ),
          ]
      )
      sample = search_space.default()
      assert sample[0]["out_features"] * 2 == sample[1]["out_features"]
  
imports: import math
  from collections import Counter
  import numpy
  import pytest
  from nni.mutable import *
  from nni.mutable.mutable import _dedup_labeled_mutables, _mutable_equal
label_desc: Use image node_id 7 for calling a global function with example usage: test_mutable_dict() without return types