
    Гh                         S r SSKrSSKrSSKrSSKJrJr  SSKJrJ	r	J
r
  SSKJrJrJrJr  S\S\4S	 jr " S
 S5      rg)zTracker for XGBoost collective.    N)IntEnumunique)DictOptionalUnion   )_LIB_check_call_deprecate_positional_argsmake_jcargsaddrreturnc                 <    [         R                  " U S5      S   S   $ )z Get network family from address.Nr   )socketgetaddrinfo)r   s    bC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\xgboost/tracker.py
get_familyr      s    dD)!,Q//    c                       \ rS rSrSr\ " S S\5      5       r\ SSSS.S\	S	\
\   S
\	S\S\	SS4S jjj5       rSS jrSS jrSS jrSS\
\	   SS4S jjrS\\\\\	4   4   4S jrSrg)RabitTracker   a  Tracker for the collective used in XGBoost, acting as a coordinator between
workers.

Parameters
----------

n_workers:

    The total number of workers in the communication group.

host_ip:

    The IP address of the tracker node. XGBoost can try to guess one by probing with
    sockets. But it's best to explicitly pass an address.

port:

    The port this tracker should listen to. XGBoost can query an available port from
    the OS, this configuration is useful for restricted network environments.

sortby:

    How to sort the workers for rank assignment. The default is host, but users can
    set the `DMLC_TASK_ID` via arguments of :py:meth:`~xgboost.collective.init` and
    obtain deterministic rank assignment through sorting by task name. Available
    options are:

      - host
      - task

timeout :

    Timeout for constructing (bootstrap) and shutting down the communication group,
    doesn't apply to communication when the group is up and running.

    The timeout value should take the time of data loading and pre-processing into
    account, due to potential lazy execution. By default the Tracker doesn't have
    any timeout to avoid pre-mature aborting.

    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.

Examples
--------

.. code-block:: python

    from xgboost.tracker import RabitTracker
    from xgboost import collective as coll

    tracker = RabitTracker(host_ip="127.0.0.1", n_workers=2)
    tracker.start()

    with coll.CommunicatorContext(**tracker.worker_args()):
        ret = coll.broadcast("msg", 0)
        assert str(ret) == "msg"

c                       \ rS rSrSrSrSrg)RabitTracker._SortByN   r   r    N)__name__
__module____qualname____firstlineno__HOSTTASK__static_attributes__r   r   r   _SortByr   N   s    r   r#   r   host)sortbytimeout	n_workershost_ipportr%   r&   r   Nc          
      n   [         R                  " 5       nUS;  a  [        S5      eUb  [        U5        [	        UUUSUS:X  a  U R
                  R                  OU R
                  R                  [        U5      S9n[        [        R                  " U[         R                  " U5      5      5        X`l        g )N)r$   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&   r4   argss           r   __init__RabitTracker.__init__S   s     "))LMMw%(.&(84<<$$dll>O>OL
 	D((v||F/CDEr   c                     [        U S5      (       a.  U R                  nU ?[        [        R                  " U5      5        gg)zInternal function for testing.r4   N)hasattrr4   r
   r	   XGTrackerFree)r5   r4   s     r   freeRabitTracker.freen   s5    4""[[F**623 #r   c                 $    U R                  5         g N)r<   r5   s    r   __del__RabitTracker.__del__u   s    		r   c                 h    [        [        R                  " U R                  [	        5       5      5        g)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	   XGTrackerRunr4   r   r@   s    r   startRabitTracker.startx   s     	D%%dkk;=ABr   c           	      f    [        [        R                  " U R                  [	        US95      5        g)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	   XGTrackerWaitForr4   r   )r5   r&   s     r   wait_forRabitTracker.wait_for   s"     	D))$++{77STUr   c                 
   [         R                  " 5       n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  c   e[        R                  " UR                  5      nU$ )zGet arguments for workers.)
r.   c_char_pr
   r	   XGTrackerWorkerArgsr4   r3   valuejsonloads)r5   c_envenvs      r   worker_argsRabitTracker.worker_args   sW    !D,,T[[&,,u:MNO{{&&&jj%
r   )r4   )r   )r   Nr?   )r   r   r   r   __doc__r   r   r#   r   r1   r   strr7   r<   rA   rE   rI   r   r   rS   r"   r   r   r   r   r      s    :x '    
 	  # 	   
  44CV V VT#uS#X"67 r   r   )rU   r.   rO   r   enumr   r   typingr   r   r   corer	   r
   r   r   rV   r1   r   r   r   r   r   <module>rZ      s?    %      ( ( L L0S 0S 0
} }r   