U
    Ph                     @  s,   d dl mZ d dlmZ G dd deZdS )    )annotations)
WeightTypec                      s   e Zd ZdZddddddd fddZedd	 Zejd
d	 Zedd Zejdd Zedd Z	e	jdd Z	dd Z
dd Zdd Zdd Zdd Z  ZS )ExchangeObjectaP  
    Contains the information shared between client and server.

    Args:
        weights: model weights.
        optim: optimizer weights.
        metrics: evaluation metrics.
        weight_type: type of weights (see monai.fl.utils.constants.WeightType).
        statistics: training statistics, i.e. number executed iterations.
    Nzdict | NonezWeightType | None)weightsoptimmetricsweight_type
statisticsc                   s2   t    || _|| _|| _|| _|| _i | _d S N)super__init__r   r   r   r   r	   _summary)selfr   r   r   r   r	   	__class__ S/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/fl/utils/exchange_object.pyr      s    
zExchangeObject.__init__c                 C  s   | j S r
   )_metricsr   r   r   r   r   -   s    zExchangeObject.metricsc                 C  s.   |d k	r$t |ts$tdt| || _d S )Nz1Expected metrics to be of type dict but received )
isinstancedict
ValueErrortyper   )r   r   r   r   r   r   1   s    
c                 C  s   | j S r
   )_statisticsr   r   r   r   r	   8   s    zExchangeObject.statisticsc                 C  s.   |d k	r$t |ts$tdt| || _d S )Nz4Expected statistics to be of type dict but received )r   r   r   r   r   )r   r	   r   r   r   r	   <   s    
c                 C  s   | j S r
   )_weight_typer   r   r   r   r   C   s    zExchangeObject.weight_typec                 C  s:   |d k	r0|t jt jfkr0tdt j dt j || _d S )Nz"Expected weight type to be either z or )r   ZWEIGHTSZWEIGHT_DIFFr   r   )r   r   r   r   r   r   G   s    c                 C  s   | j s
dS | jsdS dS )NFT)r   r   r   r   r   r   is_valid_weightsN   s
    zExchangeObject.is_valid_weightsc                 C  sF   |rBt |trt|| j|< n$t |tr4|| j|< nt|| j|< d S r
   )r   r   lenr   r   r   )r   keyvaluer   r   r   _add_to_summaryU   s    

zExchangeObject._add_to_summaryc                 C  sP   | j |  tdddddg| j| j| j| j| jgD ]\}}| || q4| j S )Nr   r   r   r   r	   )	r   updatezipr   r   r   r   r	   r   )r   kvr   r   r   summary^   s    zExchangeObject.summaryc                 C  s   t |  S r
   strr$   r   r   r   r   __repr__g   s    zExchangeObject.__repr__c                 C  s   t |  S r
   r%   r   r   r   r   __str__j   s    zExchangeObject.__str__)NNNNN)__name__
__module____qualname____doc__r   propertyr   setterr	   r   r   r   r$   r'   r(   __classcell__r   r   r   r   r      s0        





		r   N)
__future__r   Zmonai.fl.utils.constantsr   r   r   r   r   r   r   <module>   s   