code: def _make_pyomo_variable_to_parametrization(
      model_component: pyomo.Var, params: ParamDict
  ) -> ParamDict:
      # https://pyomo.readthedocs.io/en/stable/pyomo_modeling_components/Sets.html
      # Refer to the implementation in pyomo/core/base/var.py
      # To further improve the readability function, we should find out how to represent {None: ng.p.Scalar(), 1: ng.p.Scalar()} in ng.p.Dict
      # We do not adopt nested parameterization, which will require type information between string and int.
      # Such conversion has to be done in _pyomo_obj_function_wrapper and _pyomo_constraint_wrapper, which slows down optimization.
      if not isinstance(
          model_component,
          (pyomo.base.var.IndexedVar, pyomo.base.var.SimpleVar),
      ):
          raise NotImplementedError  # Normally, Pyomo will create a set for the indices used by a variable
      for k, v in model_component._data.items():
          if isinstance(v, pyomo.base.var._GeneralVarData):
              if v.is_fixed():
                  raise NotImplementedError
              if k is None:
                  params_name = str(model_component.name)
              else:
                  params_name = f"{model_component.name}[{_convert_to_ng_name(k)}]"
              if isinstance(v.domain, pyomo.RangeSet):
                  params = _make_pyomo_range_set_to_parametrization(
                      v.domain, params, params_name
                  )
              elif (
                  isinstance(v.domain, pyomo.Set)
                  and v.domain.isfinite()
              ):
                  if v.domain.isordered():
                      params[params_name] = p.Choice(
                          list(v.domain.ordered_data())
                      )
                  else:
                      params[params_name] = p.Choice(
                          list(v.domain.data())
                      )
              else:
                  raise NotImplementedError(
                      f"Cannot handle domain type {type(v.domain)}"
                  )
          else:
              raise NotImplementedError(
                  f"Cannot handle variable type {type(v)}"
              )
      return params
  
file_path: nevergrad/nevergrad/functions/pyomo/core.py
imports: from functools import partial
  import numpy
  import pyomo.environ
  import nevergrad.common.typing
  from nevergrad.parametrization import parameter
  from ..None import base
label_desc: Use image node_id 3 for calling a global function with example usage: _make_pyomo_variable_to_parametrization(model_component, params) and returns: params