code: def test_doc_constrained_optimization() -> None:
      np.random.seed(12)  # avoid flakiness
      with warnings.catch_warnings():
          warnings.filterwarnings("ignore", category=UserWarning)
          # DOC_CONSTRAINED_2
          import nevergrad as ng
  
          def square(x):
              return sum((x - 0.5) ** 2)
  
          optimizer = ng.optimizers.NGOpt(parametrization=2, budget=100)
          # define a constraint on first variable of x:
          optimizer.parametrization.register_cheap_constraint(
              lambda x: x[0] - 1
          )
  
          recommendation = optimizer.minimize(square, verbosity=2)
          print(recommendation.value)
          # >>> [1.00037625, 0.50683314]
          # DOC_CONSTRAINED_3
      np.testing.assert_array_almost_equal(
          recommendation.value, [1, 0.5], decimal=1
      )
  
file_path: nevergrad/nevergrad/optimization/test_doc.py
imports: import warnings
  import numpy
  import nevergrad
label_desc: Use image node_id 6 for calling a global function with example usage: test_doc_constrained_optimization() and returns: sum