
    :[g                     |    d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZmZ dedefd	Z G d
 d      Zy)zTracker for XGBoost collective.    N)IntEnumunique)DictOptionalUnion   )_LIB_check_callmake_jcargsaddrreturnc                 :    t        j                  | d      d   d   S )z Get network family from address.Nr   )socketgetaddrinfo)r   s    J/var/www/html/bid-api/venv/lib/python3.12/site-packages/xgboost/tracker.py
get_familyr      s    dD)!,Q//    c                       e Zd ZdZe G d de             Z	 	 	 ddedee	   dede	ded	d
fdZ
ddZddZddZddee   d	d
fdZd	ee	ee	ef   f   fdZy
)RabitTrackera  Tracker for the collective used in XGBoost, acting as a coordinator between
    workers.

    Parameters
    ..........
    sortby:

        How to sort the workers for rank assignment. The default is host, but users can
        set the `DMLC_TASK_ID` via RABIT initialization arguments and obtain
        deterministic rank assignment. Available options are:
          - host
          - task

    timeout :

        Timeout for constructing the communication group and waiting for the tracker to
        shutdown when it's instructed to, doesn't apply to communication when tracking
        is running.

        The timeout value should take the time of data loading and pre-processing into
        account, due to potential lazy execution.

        The :py:meth:`.wait_for` method has a different timeout parameter that can stop
        the tracker even if the tracker is still being used. A value error is raised
        when timeout is reached.

    c                       e Zd ZdZdZy)RabitTracker._SortByr   r   N)__name__
__module____qualname__HOSTTASK r   r   _SortByr   .   s    r   r   	n_workershost_ipportsortbytimeoutr   Nc           
      h   t        j                         }|dvrt        d      |t        |       t	        |||d|dk(  r| j
                  j                  n| j
                  j                  t        |            }t        t        j                  |t        j                  |                   || _        y )N)hosttaskz-Expecting either 'host' or 'task' for sortby.rabitr%   )r%   r   r!   dmlc_communicatorr"   r#   )ctypesc_void_p
ValueErrorr   r   r   r   r   intr
   r	   XGTrackerCreatebyrefhandle)selfr   r    r!   r"   r#   r/   argss           r   __init__zRabitTracker.__init__3   s     "))LMMw%(.&(84<<$$dll>O>OL
 	D((v||F/CDEr   c                 v    t        | d      r-| j                  }| `t        t        j                  |             yy)zInternal function for testing.r/   N)hasattrr/   r
   r	   XGTrackerFree)r0   r/   s     r   freezRabitTracker.freeL   s2    4"[[F**623 #r   c                 $    | j                          y N)r6   r0   s    r   __del__zRabitTracker.__del__S   s    		r   c                 f    t        t        j                  | j                  t	                            y)zStart the tracker. Once started, the client still need to call the
        :py:meth:`wait_for` method in order to wait for it to finish (think of it as a
        thread).

        N)r
   r	   XGTrackerRunr/   r   r9   s    r   startzRabitTracker.startV   s     	D%%dkk;=ABr   c                 j    t        t        j                  | j                  t	        |                   y)zWait for the tracker to finish all the work and shutdown. When timeout is
        reached, a value error is raised. By default we don't have timeout since we
        don't know how long it takes for the model to finish training.

        )r#   N)r
   r	   XGTrackerWaitForr/   r   )r0   r#   s     r   wait_forzRabitTracker.wait_for^   s"     	D))$++{77STUr   c                     t        j                         }t        t        j                  | j
                  t        j                  |                   |j                  J t        j                  |j                        }|S )zGet arguments for workers.)
r)   c_char_pr
   r	   XGTrackerWorkerArgsr/   r.   valuejsonloads)r0   c_envenvs      r   worker_argszRabitTracker.worker_argsf   sW    !D,,T[[&,,u:MNO{{&&&jj%
r   )r   r%   r   )r   Nr8   )r   r   r   __doc__r   r   r   r,   r   strr2   r6   r:   r=   r@   r   r   rI   r   r   r   r   r      s    8 '    # 	
   
24CV V VT#uS#X"67 r   r   )rJ   r)   rE   r   enumr   r   typingr   r   r   corer	   r
   r   rK   r,   r   r   r   r   r   <module>rO      s?    %      ( ( 0 00S 0S 0
[ [r   