
    rii                        d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZmZmZ dddddd	d
ee         dee         dee         dee         dee         de	egef         fdZ edd          deddfd            Z edd          de
eef         fd            Ze edddd          deded         fd                        ZdS )z Global configuration for XGBoost    N)contextmanager)wraps)AnyCallableDictIteratorOptionalcast   )_F)_LIB_check_callc_strpy_str)header
extra_note
parametersreturnssee_alsor   r   r   r   r   returnc           	           dddt           t                   dt          fddt          dt          f fd}|S )aD  Decorator to format docstring for config functions.

    Parameters
    ----------
    header: str
        An introducion to the function
    extra_note: str
        Additional notes
    parameters: str
        Parameters of the function
    returns: str
        Return value
    see_also: str
        Related functions
    a  
    {header}

    Global configuration consists of a collection of parameters that can be applied in the
    global scope. See :ref:`global_config` for the full list of parameters supported in
    the global configuration.

    {extra_note}

    .. versionadded:: 1.4.0
    af  
    Example
    -------

    .. code-block:: python

        import xgboost as xgb

        # Show all messages, including ones pertaining to debugging
        xgb.set_config(verbosity=2)

        # Get current value of global configuration
        # This is a dict containing all parameters in the global configuration,
        # including 'verbosity'
        config = xgb.get_config()
        assert config['verbosity'] == 2

        # Example of using the context manager xgb.config_context().
        # The context manager will restore the previous value of the global
        # configuration upon exiting.
        with xgb.config_context(verbosity=0):
            # Suppress warning caused by model generated with XGBoost version < 1.0.0
            bst = xgb.Booster(model_file='./old_model.bin')
        assert xgb.get_config()['verbosity'] == 2  # old value restored

    Nested configuration context is also supported:

    Example
    -------

    .. code-block:: python

        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
            with xgb.config_context(verbosity=2):
                assert xgb.get_config()["verbosity"] == 2

        xgb.set_config(verbosity=2)
        assert xgb.get_config()["verbosity"] == 2
        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
    valuer   c                     | dn| S )N  )r   s    T/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/xgboost/config.pynone_to_strzconfig_doc.<locals>.none_to_str\   s    ]rr-    funcc                 L                                                                    z              z              z    	          z    _        t                     dt          dt          dt          f fd            }t	          t
          |          S )N)r   r   argskwargsr   c                       | i |S Nr   )r!   r"   r   s     r   wrapz6config_doc.<locals>.config_doc_decorator.<locals>.wrapj   s    4((((r   )format__doc__r   r   r
   r   )
r   r%   common_exampledoc_templater   r   r   r   r   r   s
   ` r   config_doc_decoratorz(config_doc.<locals>.config_doc_decorator_   s    "{6**{{:7N7N     k*%%& k'""	#
 k.))* k(##$ 	 
t	) 	)s 	)s 	) 	) 	) 	) 	) 
	) B~~r   )r	   strr   )	r   r   r   r   r   r*   r(   r)   r   s	   ````` @@@r   
config_docr,      s    0
L)NV.8C= .S . . . .2 "             "  r   z#
    Set global configuration.
    z
    Parameters
    ----------
    new_config: Dict[str, Any]
        Keyword arguments representing the parameters and their values
            )r   r   
new_configc                      i }|                                  D ]\  }}||||<   t          j        |          }t          t	          j        t          |                               d S r$   )itemsjsondumpsr   r   XGBSetGlobalConfigr   )r-   not_nonekvconfigs        r   
set_configr7   s   sk     H  ""  1=HQKZ!!F'f6677777r   z9
    Get current values of the global configuration.
    zu
    Returns
    -------
    args: Dict[str, Any]
        The list of global parameters and their values
            )r   r   c                      t          j                    } t          t          j        t          j        |                                | j        }|sJ t          j        t          |                    }|S r$   )
ctypesc_char_pr   r   XGBGetGlobalConfigbyrefr   r0   loadsr   )
config_strr   r6   s      r   
get_configr?      s_     ""J'Z(@(@AABBBELLLZu&&FMr   z;
    Context manager for global XGBoost configuration.
    z
    .. note::

        All settings, not just those presently modified, will be returned to their
        previous values when the context manager is exited. This is not thread-safe.
            z
    See Also
    --------
    set_config: Set global XGBoost configuration
    get_config: Get current values of the global configuration
            )r   r   r   r   c               +      K   t                                                      }t          di |  	 d V  t          di | d S # t          di | w xY w)Nr   )r?   copyr7   )r-   
old_configs     r   config_contextrC      ss      2 ""$$J!  Z     
  Z    s   A A)r'   r9   r0   
contextlibr   	functoolsr   typingr   r   r   r   r	   r
   _typingr   corer   r   r   r   r+   r,   r7   r?   rC   r   r   r   <module>rI      sC   & &   % % % % % %       @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @       2 2 2 2 2 2 2 2 2 2 2 2
 ! $ $!"c  c  c SMc  c  	c 
 c]c  smc  rdBhc  c  c  c L 	
 
 
8S 8T 8 8 8
 
8 	
 
 
DcN   
 
 !  .! !$ ! ! !/  0! ! !r   