o
    -wis	                     @  sF   d dl mZ d dlmZ d dlmZ d dlmZ eG dd dZdS )    )annotations)	dataclass)Union)parsec                   @  sJ   e Zd ZU dZded< 	 ded< 	 dZded< 	 dd	 ZedddZdS )	RunMomentzA moment in a run.

    Defines a branching point in a finished run to fork or resume from.
    A run moment is identified by a run ID and a metric value.
    Currently, only the metric '_step' is supported.
    strrunzUnion[int, float]value_stepmetricc                 C  s`   | j dkrtd| j  dt| jttfstd| j dt| jts.td| j dd S )Nr
   z+Only the metric '_step' is supported, got 'z'.z-Only int or float values are supported, got 'z*Only string run names are supported, got ')	r   
ValueError
isinstancer	   intfloat	TypeErrorr   r   )self r   U/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/lib/run_moment.py__post_init__   s   
zRunMoment.__post_init__urireturnc              
   C  s  d| }t d| d}zt|}W n t y" } z||d }~ww |jdkr*||js/||j}|js;|js;|jr=|t|j	}t
|dkrK|t| d }|dkrY||| d }	z|	 rht|	nt|	}
W n t y| } z||d }~ww | |||
dS )	Nzrunmoment://z*Could not parse passed run moment string 'z', expected format '<run>?<metric>=<numeric_value>'. Currently, only the metric '_step' is supported. Example: 'ans3bsax?_step=123'.	runmoment   r   r
   )r   r   r	   )r   r   urlparseschemenetlocpathparamsfragmentparse_qsquerylenlistkeysisdigitr   r   )clsr   parsable	parse_errparseder   r    r   r	   	num_valuer   r   r   from_uri*   s>   

zRunMoment.from_uriN)r   r   r   r   )	__name__
__module____qualname____doc____annotations__r   r   classmethodr+   r   r   r   r   r      s   
 r   N)	
__future__r   dataclassesr   typingr   urllibr   r   r   r   r   r   <module>   s    