o
    xi                     @   s`   d dl Z d dlZddlmZmZ dd ZG dd de jdZG d	d
 d
eZ	G dd deZ
dS )    N   )SummaryItemSummaryRecordc                 C   s   t | tr| S t| S N)
isinstancedictvars)d r
   K/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/wandb_summary.py	_get_dict   s   
r   c                   @   sv   e Zd ZdZejdd ZejdefddZdd Z	dd
dZ
dd ZeZdd ZeZdd ZeZdefddZd	S )SummaryDictzdict-like wrapper for the nested dictionaries in a SummarySubDict.

    Triggers self._root._callback on property changes.
    c                 C      t r   NotImplementedErrorselfr
   r
   r   _as_dict      zSummaryDict._as_dictrecordc                 C   r   r   r   r   r   r
   r
   r   _update   r   zSummaryDict._updatec                 C   s   dd |   D S )Nc                 S   s   g | ]}|d kr|qS )_wandbr
   ).0kr
   r
   r   
<listcomp>   s    z$SummaryDict.keys.<locals>.<listcomp>)r   r   r
   r
   r   keys      zSummaryDict.keysNc                 C   s   |   ||S r   )r   get)r   keydefaultr
   r
   r   r      s   zSummaryDict.getc                 C   sN   |   | }t|tr%t }t|d| t|d|  t|d| |S |S N_items_parent_parent_key)r   r   r   SummarySubDictobject__setattr__)r   r   itemwrapped_itemr
   r
   r   __getitem__"   s   
zSummaryDict.__getitem__c                 C   s   |  ||i d S r   )update)r   r   valr
   r
   r   __setitem__3   r   zSummaryDict.__setitem__c                 C   s*   t  }t }|f|_|f|_| | d S r   )r   r   r   remover   )r   r   r   r(   r
   r
   r   __delattr__8   s
   zSummaryDict.__delattr__r	   c                 C   sF   t  }| D ]\}}t }|f|_||_|j| q| | d S r   )r   itemsr   r   valuer+   appendr   )r   r	   r   r   r1   r(   r
   r
   r   r+   A   s   zSummaryDict.updater   )__name__
__module____qualname____doc__abcabstractmethodr   r   r   r   r   r*   __getattr__r-   r'   r/   __delitem__r   r+   r
   r
   r
   r   r      s    

r   )	metaclassc                       sd   e Zd ZU dZejed< ejed< dejf fddZdejfdd	Zd
d Z	de
fddZ  ZS )Summarya3  Track single values for each metric for each run.

    By default, a metric's summary is the last value of its History.

    For example, `wandb.log({'accuracy': 0.9})` will add a new step to History and
    update Summary to the latest value. In some cases, it's more useful to have
    the maximum or minimum of a metric instead of the final value. You can set
    history manually `(wandb.summary['accuracy'] = best_acc)`.

    In the UI, summary metrics appear in the table to compare across runs.
    Summary metrics are also used in visualizations like the scatter plot and
    parallel coordinates chart.

    After training has completed, you may want to save evaluation metrics to a
    run. Summary can handle numpy arrays and PyTorch/TensorFlow tensors. When
    you save one of these types to Summary, we persist the entire tensor in a
    binary file and store high level metrics in the summary object, such as min,
    mean, variance, and 95th percentile.

    Examples:
        ```python
        wandb.init(config=args)

        best_accuracy = 0
        for epoch in range(1, args.epochs + 1):
            test_loss, test_accuracy = test()
            if test_accuracy > best_accuracy:
                wandb.run.summary["best_accuracy"] = test_accuracy
                best_accuracy = test_accuracy
        ```
    _update_callback_get_current_summary_callbackget_current_summary_callbackc                    s*   t    t| dd  t| d| d S )Nr=   r>   )super__init__r&   r'   )r   r?   	__class__r
   r   rA   p   s
   
zSummary.__init__update_callbackc                 C   s   t | d| d S )Nr=   )r&   r'   )r   rD   r
   r
   r   _set_update_callbackw   r   zSummary._set_update_callbackc                 C   s   |   S r   )r>   r   r
   r
   r   r   z   s   zSummary._as_dictr   c                 C   s   | j r
|  | d S d S r   )r=   r   r
   r
   r   r   }   s   zSummary._update)r3   r4   r5   r6   tCallable__annotations__rA   rE   r   r   r   __classcell__r
   r
   rB   r   r<   L   s   
 
 
r<   c                   @   sH   e Zd ZU dZeed< eed< eed< dd Zdd Z	d	e
fd
dZdS )r%   z_Non-root node of the summary data structure.

    Contains a path to itself from the root.
    r"   r#   r$   c                 C   s0   t | dt  t | dd  t | dd  d S r!   )r&   r'   r   r   r
   r
   r   rA      s   zSummarySubDict.__init__c                 C   s   | j S r   )r"   r   r
   r
   r   r      s   zSummarySubDict._as_dictr   c                 C   s   | j || jS r   )r#   r   _add_next_parentr$   r   r
   r
   r   r      s   zSummarySubDict._updateN)r3   r4   r5   r6   r   rH   r   strrA   r   r   r   r
   r
   r
   r   r%      s   
 r%   )r7   typingrF   interface.summary_recordr   r   r   ABCMetar   r<   r%   r
   r
   r
   r   <module>   s    >6