o
    Ù­jÑ  ã                   @   sü   d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddlZddlZddlmZ ddlmZ ddlmZ e d	¡Zd
eeef dddefdd„Zde	eeef  dede
e	e ef fdd„Zedefdd„ƒZedefdd„ƒZedefdd„ƒZdS )z)Utilities for the XGBoost Dask interface.é    N)Úcache)ÚAnyÚDictÚOptionalÚTuple)ÚVersion)Úparseé   )ÚConfigz[xgboost.dask]Úlocal_paramÚworkerzdistributed.WorkerÚreturnc                 C   st   t |dƒr	|jjn|j}d}dD ]}|  |d¡dur-|  ||¡|kr-t d¡ | | } nq|dks6|du r8|}|S )zIGet the number of threads from a worker and the user-supplied parameters.ÚstateN)ÚnthreadÚn_jobsz-Overriding `nthreads` defined in dask worker.r   )Úhasattrr   ÚnthreadsÚgetÚLOGGERÚinfo)r   r   ÚdwntÚ	n_threadsÚp© r   úO/var/www/html/CropPilot/venv/lib/python3.10/site-packages/xgboost/dask/utils.pyÚget_n_threads   s    
€r   ÚdconfigÚcoll_cfgc                 C   sP  dg}d}d}| dur&| D ]}||vrt d|› �ƒ‚t d|› d�t¡ qni } |  dd¡}|durB| d¡rB| d¡rB|d	d
… }|durZz
tj 	|¡\}}W n	 t yY   Y nw |du rat
ƒ }|jdur~|dur{|j|kr{t d|› d|j› d�ƒ‚|j}|jdur¤|dkr¡|dur¡|jdkr¡||jkr¡t d|› d|j› d�ƒ‚|j}||fS )a  Get the tracker address from the optional user configuration.

    Parameters
    ----------
    dconfig :
        Dask global configuration.

    coll_cfg :
        Collective configuration.

    Returns
    -------
    The IP address along with the port number.

    Úscheduler_addressNr   zUnknown configuration: zeUse `coll_cfg` instead of the Dask global configuration store for the XGBoost tracker configuration: Ú.ú[ú]é   éÿÿÿÿz\Conflicting host IP addresses from the dask configuration and the collective configuration: z v.s. zPConflicting ports from the dask configuration and the collective configuration: )Ú
ValueErrorÚwarningsÚwarnÚFutureWarningr   Ú
startswithÚendswithÚdistributedÚcommÚget_address_host_portr
   Útracker_host_ipÚtracker_port)r   r   Úvalid_configÚhost_ipÚportÚkr   r   r   Úget_address_from_user!   sd   ÿûýÿ
ÿÿÿ


ÿÿÿr3   c                   C   s
   t tjƒS )N)Úparse_versionÚdaskÚ__version__r   r   r   r   Ú_DASK_VERSIONj   s   
r7   c                   C   ó   t ƒ tdƒkS )Nz	2024.12.1©r7   r4   r   r   r   r   Ú_DASK_2024_12_1o   ó   r:   c                   C   r8   )Nz2025.3.0r9   r   r   r   r   Ú_DASK_2025_3_0t   r;   r<   )Ú__doc__Úloggingr%   Ú	functoolsr   ÚfcacheÚtypingr   r   r   r   r5   r*   Úpackaging.versionr   r   r4   Ú
collectiver
   Ú	getLoggerr   ÚstrÚintr   r3   r7   Úboolr:   r<   r   r   r   r   Ú<module>   s2    
ÿÿ
þI