o
    ]i                     @   sf   d Z ddlmZ ddlmZ dd Zdd Zdd	 Zd
d Zdd Z	dddZ
edkr1e  dS dS )z^Example of FieldReference usage.

This shows how to use FieldReferences for lazy computation.
    )app)config_dictc                  C   s`   t d} t|   |  d }| d }t| t|  | d t| t|  dS )zDSimple example of lazy computation with `configdict.FieldReference`.   
      N)r   FieldReferenceprintgetset)refadd_tenadd_ten_lazy r   g/home/ubuntu/.local/lib/python3.10/site-packages/ml_collections/config_dict/examples/field_reference.pylazy_computation   s   

r   c                  C   s   t  } d| _| dd | _| dd | _| dd | _t| j t| j t| j t| j d| _t| j t| j t| j t| j dS )	z"Overriding lazily computed values.r   	referencer      reference_1d      N)r   
ConfigDictr   get_refreference_0r   reference_1_0r   configr   r   r   change_lazy_computation*   s   






r   c               
   C   sf   t  } d| _| dd | _z| dd | _W dS  t jy2 } zt| W Y d}~dS d}~ww )z$Creates a cycle within a ConfigDict.r   integer_fieldr   bigger_integer_field   N)r   r   r   r   r   MutabilityErrorr   )r   er   r   r   create_cycle?   s   r"   c                  C   s   t  } t d| _d| _d| _| j| j | _| d| j | _| j| d | _	| d| d | _
d| _t| j t| j d| _t| j	 t| j
 dS )	z2Example usage of lazy computation with ConfigDict.r   r   g      @r   float_field   g      @N)r   r   r   reference_fieldr   r#   no_lazyr   lazy_integer
lazy_float	lazy_bothr   r   r   r   r   lazy_configdictM   s    


r*   c                  C   s   t  } d| _d| _g d| _| dd | _t| j d| _t| j | dg d | _t| j d	g| _t| j | d| d
 | _	t| j	 d| _t| j	 dS )z*Advanced lazy computation with ConfigDict.g333333)@{   )r   r   r   r#   r$   g      $@
list_field)r$      r   r   r   N)
r   r   r#   r   r,   r   float_multiply_fieldr   longer_list_fieldref_subtractionr   r   r   r   lazy_configdict_advancedk   s"   





r2   r   c                 C   s$   ~ t   t  t  t  t  d S )N)r   r*   r   r"   r2   )argvr   r   r   main   s   
r4   __main__N)r   )__doc__abslr   ml_collectionsr   r   r   r"   r*   r2   r4   __name__runr   r   r   r   <module>   s   
	