o
    1 i\                     @   sP   d dl Z d dlZd dlZd dlZd dlmZ dZdZG dd deZ	dd Z
dS )	    N)	TrainableZmock_trainableZ
mock_errorc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )MyTrainableClasszExample agent whose learning curve is a random sigmoid.

    The dummy hyperparameters "width" and "height" determine the slope and
    maximum reward value reached.
    c                 C   s:   | dd| _| td| _| dd| _d| _d| _d S )Nsleepr   FZpersistent_error)get_sleep_timeMOCK_ERROR_KEY_mock_error_persistent_errortimesteprestored)selfconfig r   i/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/tune/utils/mock_trainable.pysetup   s
   
zMyTrainableClass.setupc                 C   s   | j r| jdkr| js| jstd| j| jdkr!t| j |  jd7  _t	t
| j| jdd }|| jdd9 }d|iS )Nr   z"Failing on purpose! self.timestep=   widthheightZepisode_reward_mean)r   r
   r	   r   RuntimeErrorr   timer   nptanhfloatr   r   )r   vr   r   r   step   s   

zMyTrainableClass.stepc                 C   sT   t j|d}t|d}|td| ji W d    d S 1 s#w   Y  d S )N
checkpointwr
   )ospathjoinopenwritejsondumpsr
   r   Zcheckpoint_dirr   fr   r   r   save_checkpoint/   s   "z MyTrainableClass.save_checkpointc                 C   sV   t j|d}t|d}t| d | _W d    n1 s!w   Y  d| _d S )Nr   rr
   T)	r   r   r   r    r"   loadsreadr
   r   r$   r   r   r   load_checkpoint4   s
   
z MyTrainableClass.load_checkpointN)__name__
__module____qualname____doc__r   r   r&   r*   r   r   r   r   r      s    r   c                  C   s   ddl m}  | tt d S )Nr   register_trainable)ray.tuner0   MOCK_TRAINABLE_NAMEr   r/   r   r   r   register_mock_trainable<   s   r3   )r"   r   r   numpyr   r1   r   r2   r   r   r3   r   r   r   r   <module>   s    /