code: def test_numerical():
      a = Numerical(0, 1, label="a")
      assert a.simplify() == {"a": a}
      assert a.freeze({"a": 0.5}) == 0.5
      exc = a.check_contains({"a": 4})
      assert exc is not None and "higher than" in exc.msg
      assert a.contains({"a": 0.8})
      assert a.default() == 0.5
      assert 0 < a.random() < 1
  
      grid = a.grid()
      assert list(grid) == [0.5]
  
      grid = a.grid(granularity=2)
      assert list(grid) == [0.25, 0.5, 0.75]
  
      a = Numerical(0, 1, log_distributed=True, label="a")
      assert a.simplify() == {"a": a}
  
      a = Numerical(mu=0, sigma=1, label="a")
      assert -5 < a.random() < 5
  
      a = Numerical(mu=0, sigma=1, log_distributed=True, label="a")
      for _ in range(10):
          assert a.random() > 0
  
      a = Numerical(mu=0, sigma=1, low=-1, high=1)
      assert min(a.grid(granularity=4)) == -1
  
      a = Numerical(mu=2, sigma=3)
      x = [a.random() for _ in range(1000)]
      assert 0.5 < np.mean(x) < 2.5
      assert 2 < np.std(x) < 4
      assert np.mean(list(a.grid(granularity=4))) == 2
  
      a = Numerical(low=0, high=100, quantize=2)
      assert len(list(a.grid(granularity=10))) == 51
      assert a.random() % 2 == 0
  
      a = Numerical(low=1, high=3, quantize=0.75)
      assert len(list(a.grid(granularity=10))) == 4
      for x in a.grid(granularity=10):
          assert a.contains({a.label: x})
  
      a = Numerical(low=2, high=6, log_distributed=True, label="x")
      for _ in range(10):
          assert 2 < a.random() < 6
      with pytest.raises(
          SampleValidationError, match=r"than lower bound"
      ):
          a.freeze({"x": 1.5})
  
      from scipy.stats import beta
  
      a = Numerical(distribution=beta(2, 5), label="x")
      assert 0 < a.random() < 1
      assert 0.1 < a.default() < 0.3
  
      with pytest.raises(
          SampleValidationError, match=r"not in the distribution"
      ):
          a.freeze({"x": 1.5})
  
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 5 for calling a global function with example usage: test_numerical() without return types