
    -jiwl                       S SK Jr  S SKJr  S SKJr  S SKJr  S SKrS SKrS SKrS SK	r	S SK
r
S SKJr  S SKrS SKrS SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SK J!r!  S SK"J#r#  S SK$J%r%  S SK$J&r&  \RN                  RQ                  \)5      r*Sr+Sr,Sr- " S S\R\                  5      r/ " S S\5      r0 " S S5      r1g)    )annotations)	Container)Iterable)SequenceN)Any)JSONSerializable)BaseDistribution) check_distribution_compatibility)distribution_to_json)json_to_distribution)DuplicatedStudyError)UpdateFinishedTrialError)BaseStorage)DEFAULT_STUDY_NAME_PREFIX)BaseJournalBackend)BaseJournalSnapshot)FrozenStudy)StudyDirection)FrozenTrial)
TrialStatezRecord does not exist.zATrial#{trial_number} has already finished and can not be updated.d   c                  <    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrg)JournalOperation(   r                           	    N)__name__
__module____qualname____firstlineno__CREATE_STUDYDELETE_STUDYSET_STUDY_USER_ATTRSET_STUDY_SYSTEM_ATTRCREATE_TRIALSET_TRIAL_PARAMSET_TRIAL_STATE_VALUESSET_TRIAL_INTERMEDIATE_VALUESET_TRIAL_USER_ATTRSET_TRIAL_SYSTEM_ATTR__static_attributes__r$       Z/home/james-whalen/.local/lib/python3.13/site-packages/optuna/storages/journal/_storage.pyr   r   (   s:    LLLO#$ r4   r   c                  t   \ rS rSrSrSS jrSS jrS S jrS!S jrS"S jr	S#S jr
 S$     S%S
 jjrS&S jrS'S jrS(S jrS)S jrS*S jrS+S jrS,S jrS,S jrS-S jrS$S.S jjr          S/S jrS0S jr S$       S1S jjr        S2S jrS3S jrS4S jrS5S jr  S6       S7S jjrSrg	)8JournalStorage5   aa  Storage class for Journal storage backend.

Note that library users can instantiate this class, but the attributes
provided by this class are not supposed to be directly accessed by them.

Journal storage writes a record of every operation to the database as it is executed and
at the same time, keeps a latest snapshot of the database in-memory. If the database crashes
for any reason, the storage can re-establish the contents in memory by replaying the
operations stored from the beginning.

Journal storage has several benefits over the conventional value logging storages.

1. The number of IOs can be reduced because of larger granularity of logs.
2. Journal storage has simpler backend API than value logging storage.
3. Journal storage keeps a snapshot in-memory so no need to add more cache.

Example:

    .. code::

        import optuna


        def objective(trial): ...


        storage = optuna.storages.JournalStorage(
            optuna.storages.journal.JournalFileBackend("./optuna_journal_storage.log")
        )

        study = optuna.create_study(storage=storage)
        study.optimize(objective)

In a Windows environment, an error message "A required privilege is not held by the
client" may appear. In this case, you can solve the problem with creating storage
by specifying :class:`~optuna.storages.journal.JournalFileOpenLock` as follows.

.. code::

    file_path = "./optuna_journal_storage.log"
    lock_obj = optuna.storages.journal.JournalFileOpenLock(file_path)

    storage = optuna.storages.JournalStorage(
        optuna.storages.journal.JournalFileBackend(file_path, lock_obj=lock_obj),
    )
c                   [        [        R                  " 5       5      S-   U l        Xl        [
        R                  " 5       U l        [        U R                  5      U l	        U R                     [        U R                  [        5      (       a.  U R                  R                  5       nUb  U R                  U5        U R                  5         S S S 5        g ! , (       d  f       g = fN-)struuiduuid4_worker_id_prefix_backend	threadingLock_thread_lockJournalStorageReplayResult_replay_result
isinstancer   load_snapshotrestore_replay_result_sync_with_backend)selflog_storagesnapshots      r5   __init__JournalStorage.__init__e   s    !$TZZ\!2S!8#%NN,89O9OP$--)<====668'..x8##% s   -AC
C"c                L    U R                   R                  5       nUS	 US	 US	 U$ )Nr?   rE   rC   )__dict__copyrJ   states     r5   __getstate__JournalStorage.__getstate__r   s3    ""$%&"#.!r4   c                    U R                   R                  U5        [        [        R                  " 5       5      S-   U l        [        U R
                  5      U l        [        R                  " 5       U l
        g r:   )rP   updater<   r=   r>   r?   rD   rE   rA   rB   rC   rR   s     r5   __setstate__JournalStorage.__setstate__y   sN    U#!$TZZ\!2S!889O9OP%NN,r4   c                D    [         R                  " U5      nUc  g [        U[        5      (       d  [        R                  S5        g U R                  Ul        0 Ul	        SUl
        X l        g ! [         R                  [        4 a    [        R                  S5         g f = f)Nz/Failed to restore `JournalStorageReplayResult`.z8The restored object is not `JournalStorageReplayResult`.)pickleloadsUnpicklingErrorKeyError_loggerwarningrF   rD   r?   _worker_id_to_owned_trial_id&_last_created_trial_id_by_this_processrE   )rJ   rL   rs      r5   rH   $JournalStorage.restore_replay_result   s    	39<<3IA 9!788OOVW"44)+&350 &&1 	OOMN	s   A- -/BBc                p    U R                   R                  nU R                  R                  XS.UE/5        g )N)op_code	worker_id)rE   rh   r@   append_logs)rJ   rg   extra_fieldsrh   s       r5   
_write_logJournalStorage._write_log   s1    ''11	!!w#_R^#_"`ar4   c                    U R                   R                  U R                  R                  5      nU R                  R	                  U5        g N)r@   	read_logsrE   log_number_read
apply_logs)rJ   logss     r5   rI   !JournalStorage._sync_with_backend   s6    }}&&t':':'J'JK&&t,r4   Nc                   U=(       d%    [         [        [        R                  " 5       5      -   nU R                     U R                  [        R                  X!S.5        U R                  5         U R                  R                  5        H  nUR                  U:w  a  M  [        R                  SR                  U5      5        UR                  n[!        U R"                  [$        5      (       aL  US:w  aF  U[&        -  S:X  a9  U R"                  R)                  [*        R,                  " U R                  5      5        Us  sS S S 5        $     S5       e! , (       d  f       g = f)N)
study_name
directionsz,A new study created in Journal with name: {}r   Should not reach.)r   r<   r=   r>   rC   rk   r   r)   rI   rE   get_all_studiesru   r`   infoformat	_study_idrF   r@   r   SNAPSHOT_INTERVALsave_snapshotr\   dumps)rJ   rv   ru   frozen_studystudy_ids        r5   create_new_studyJournalStorage.create_new_study   s     P#<s4::<?P#P
OO --j/c ##% $ 3 3 C C E**j8KRRS]^_'11 t}}.ABB A #449MM//T=P=P0QR+  !F  .--5- s   D E	E
Ec                    U R                      U R                  [        R                  SU05        U R	                  5         S S S 5        g ! , (       d  f       g = fNr   )rC   rk   r   r*   rI   rJ   r   s     r5   delete_studyJournalStorage.delete_study   s=    OO,99J;QR##% s   3A		
Ac                    XU0S.nU R                      U R                  [        R                  U5        U R	                  5         S S S 5        g ! , (       d  f       g = f)N)r   	user_attr)rC   rk   r   r+   rI   rJ   r   keyvaluelogs        r5   set_study_user_attr"JournalStorage.set_study_user_attr   sD    +3,OOO,@@#F##%    1A
Ac                    XU0S.nU R                      U R                  [        R                  U5        U R	                  5         S S S 5        g ! , (       d  f       g = f)N)r   system_attr)rC   rk   r   r,   rI   r   s        r5   set_study_system_attr$JournalStorage.set_study_system_attr   sD    +3%LQOO,BBCH##% r   c                   U R                      U R                  5         U R                  R                  5        H*  nUR                  U:X  d  M  UR
                  s  sS S S 5        $    [        [        5      e! , (       d  f       g = frn   )rC   rI   rE   rx   ru   r{   r_   NOT_FOUND_MSG)rJ   ru   studys      r5   get_study_id_from_name%JournalStorage.get_study_id_from_name   sd    ##%,,<<>##z1 ??*	 > =)) s   <A5A5$A55
Bc                    U R                      U R                  5         U R                  R                  U5      R                  sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   	get_studyru   r   s     r5   get_study_name_from_id%JournalStorage.get_study_name_from_id   =    ##%&&00:EE    5A
Ac                    U R                      U R                  5         U R                  R                  U5      R                  sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   r   rv   r   s     r5   get_study_directions#JournalStorage.get_study_directions   r   r   c                    U R                      U R                  5         U R                  R                  U5      R                  sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   r   
user_attrsr   s     r5   get_study_user_attrs#JournalStorage.get_study_user_attrs   r   r   c                    U R                      U R                  5         U R                  R                  U5      R                  sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   r   system_attrsr   s     r5   get_study_system_attrs%JournalStorage.get_study_system_attrs   s=    ##%&&00:GG r   c                    U R                      U R                  5         [        R                  " U R                  R                  5       5      sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rQ   deepcopyrE   rx   rJ   s    r5   rx   JournalStorage.get_all_studies   s>    ##%==!4!4!D!D!FG s   >A
A#c                $   U[         R                   R                  5       R                  SS9S.nU(       Gau  UR                  US'   UR                  b.  [        UR                  5      S:  a  S US'   UR                  US'   OUR                  US'   S US'   UR                  (       a  UR                  R                  SS9US'   OS US'   UR                  (       a  UR                  R                  SS9US	'   UR                  R                  5        VVs0 s H  u  pEU[        U5      _M     snnUS
'   UR                  R                  5        VVs0 s H#  u  pFXBR                  U   R                  U5      _M%     snnUS'   UR                  US'   UR                  US'   UR                   US'   U R"                     U R%                  [&        R(                  U5        U R+                  5         U R,                  R.                  n[1        U R2                  [4        5      (       aL  US:w  aF  U[6        -  S:X  a9  U R2                  R9                  [:        R<                  " U R,                  5      5        S S S 5        U$ s  snnf s  snnf ! , (       d  f       W$ = f)Nmicrosecondstimespec)r   datetime_startrS   r   r   valuesr   datetime_completedistributionsparamsr   r   intermediate_valuesr   )datetimenow	isoformatrS   r   lenr   r   r   r   itemsr   r   to_internal_reprr   r   r   rC   rk   r   r-   rI   rE   rc   rF   r@   r   r|   r}   r\   r~   )rJ   r   template_trialr   kdistparamtrial_ids           r5   create_new_trialJournalStorage.create_new_trial   sa    &//335???X

 )//CL$$0S9N9N5ORS5S#G . 5 5H-33G $H,,(6(E(E(O(O+ )P )$% )-$%//+9+K+K+U+U+ ,V ,'(
 >L=Y=Y=_=_=a$=a'!'--=a$C 
 !/ 5 5 ; ; = =HA //2CCEJJ =CM !/ 9 9C"0"="=C)7)K)KC%&OO,993?##%**QQH 4==*=>>M00A5++FLL9L9L,MN  /$  s   I4*I:8B2J  
Jc                    UUU[        U5      S.nU R                     U R                  [        R                  U5        U R                  5         S S S 5        g ! , (       d  f       g = f)N)r   
param_nameparam_value_internaldistribution)r   rC   rk   r   r.   rI   )rJ   r   r   r   r   r   s         r5   set_trial_paramJournalStorage.set_trial_param  sT     !$$80>	
 OO,<<cB##% s   1A
A%c                (   U R                      U R                  5         [        U R                  R                  U   5      U::  a  [        SR                  X!5      5      eU R                  R                  U   U   sS S S 5        $ ! , (       d  f       g = f)Nz?No trial with trial number {} exists in study with study_id {}.)rC   rI   r   rE   _study_id_to_trial_idsr_   rz   )rJ   r   trial_numbers      r5   'get_trial_id_from_study_id_trial_number6JournalStorage.get_trial_id_from_study_id_trial_number+  sz    ##%4&&==hGHLXU\\$ 
 &&==hGU s   A,B
Bc                   UUUS.nU[         R                  :X  a/  [        R                  R                  5       R	                  SS9US'   OCUR                  5       (       a.  [        R                  R                  5       R	                  SS9US'   U R                     U[         R                  :X  a  U R                  5         U R                  R                  R                  U5      nUc   S5       eUR                  R                  5       (       a&  [        [        R                  UR                  S95      eUR                  [         R                   :w  a
   S S S 5        gU R#                  [$        R&                  U5        U R                  5         U[         R                  :g  =(       d    XR                  R(                  :H  sS S S 5        $ ! , (       d  f       g = f)	N)r   rS   r   r   r   r   r   z@Please report your bug on GitHub if this line fails your script.r   F)r   RUNNINGr   r   r   is_finishedrC   rI   rE   _trialsgetrS   r   UNUPDATABLE_MSGrz   numberWAITINGrk   r   r/   owned_trial_id)rJ   r   rS   r   r   existing_trials         r5   set_trial_state_values%JournalStorage.set_trial_state_values6  s    !
 J&&&$,$5$5$9$9$;$E$E~$E$^C !  '/'8'8'<'<'>'H'HR`'H'aC#$
***
 '') "&!4!4!<!<!@!@!J%1 V1 "''33552'..N<Q<Q.R  "'':+=+== 3 4 OO,CCSI##%J...`(>Q>Q>`>`2`9 s   B8GA!G
Gc                    UUUS.nU R                      U R                  [        R                  U5        U R	                  5         S S S 5        g ! , (       d  f       g = f)N)r   stepintermediate_value)rC   rk   r   r0   rI   )rJ   r   r   r   r   s        r5   set_trial_intermediate_value+JournalStorage.set_trial_intermediate_valueb  sL     !"4
 OO,II3O##% r   c                    UX#0S.nU R                      U R                  [        R                  U5        U R	                  5         S S S 5        g ! , (       d  f       g = f)N)r   r   )rC   rk   r   r1   rI   rJ   r   r   r   r   s        r5   set_trial_user_attr"JournalStorage.set_trial_user_attro  sI     

 OO,@@#F##% r   c                    UX#0S.nU R                      U R                  [        R                  U5        U R	                  5         S S S 5        g ! , (       d  f       g = f)N)r   r   )rC   rk   r   r2   rI   r   s        r5   set_trial_system_attr$JournalStorage.set_trial_system_attry  sI     <

 OO,BBCH##% r   c                    U R                      U R                  5         U R                  R                  U5      sS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   	get_trialrJ   r   s     r5   r   JournalStorage.get_trial  s7    ##%&&00: s   +A
Ac                    U R                      U R                  5         U R                  R                  X5      nU(       a  [        R
                  " U5      sS S S 5        $ UsS S S 5        $ ! , (       d  f       g = frn   )rC   rI   rE   get_all_trialsrQ   r   )rJ   r   r   statesfrozen_trialss        r5   r   JournalStorage.get_all_trials  sW     ##% //>>xPM}}]3	 
 ! s   AA*A**
A8)r@   rE   rC   r?   )rK   r   returnNone)r   dict[Any, Any])rS   r   r   r   )rL   bytesr   r   )rg   intrj   dict[str, Any]r   r   )r   r   rn   )rv   zSequence[StudyDirection]ru   z
str | Noner   r   )r   r   r   r   )r   r   r   r<   r   r   r   r   )r   r   r   r<   r   r   r   r   )ru   r<   r   r   )r   r   r   r<   )r   r   r   zlist[StudyDirection])r   r   r   r   r   zlist[FrozenStudy])r   r   r   zFrozenTrial | Noner   r   )
r   r   r   r<   r   floatr   r	   r   r   )r   r   r   r   r   r   )r   r   rS   r   r   zSequence[float] | Noner   bool)r   r   r   r   r   r   r   r   )r   r   r   r<   r   r   r   r   )r   r   r   r<   r   r   r   r   r   r   r   r   )TN)r   r   r   r   r   Container[TrialState] | Noner   list[FrozenTrial])r%   r&   r'   r(   __doc__rM   rT   rX   rH   rk   rI   r   r   r   r   r   r   r   r   r   rx   r   r   r   r   r   r   r   r   r   r3   r$   r4   r5   r7   r7   5   s\   -^&-  b-
 NR.2.@J.	.:&
&&*F
F
F
H
H0d&& & $	&
 '& 
&$	V RV*a*a$.*a8N*a	*aX&&#&&<A&	&&&; /3	!! ! -	!
 
! !r4   r7   c                     \ rS rSrSS jrSS jrSS jrSS jrSS jr      SS jr	\
SS j5       r\
S S	 j5       rS!S
 jrS"S jrS#S jrS#S jrS#S jrS#S jrS#S jrS#S jrS#S jrS#S jrS#S jrS#S jrS$S jrSrg)%rD   i  c                r    SU l         Xl        0 U l        0 U l        0 U l        0 U l        SU l        0 U l        g )Nr   )rp   r?   _studiesr   r   _trial_id_to_study_id_next_study_idrb   )rJ   worker_id_prefixs     r5   rM   #JournalStorageReplayResult.__init__  s>     !102/1<>#57"#$<>)r4   c                l   U GH  nU =R                   S-  sl         US   nU[        R                  :X  a  U R                  U5        ME  U[        R                  :X  a  U R                  U5        Ml  U[        R                  :X  a  U R                  U5        M  U[        R                  :X  a  U R                  U5        M  U[        R                  :X  a  U R                  U5        M  U[        R                  :X  a  U R                  U5        GM	  U[        R                  :X  a  U R                  U5        GM1  U[        R                   :X  a  U R#                  U5        GMY  U[        R$                  :X  a  U R'                  U5        GM  U[        R(                  :X  a  U R+                  U5        GM   S5       e   g )Nr   rg   rw   )rp   r   r)   _apply_create_studyr*   _apply_delete_studyr+   _apply_set_study_user_attrr,   _apply_set_study_system_attrr-   _apply_create_trialr.   _apply_set_trial_paramr/   _apply_set_trial_state_valuesr0   #_apply_set_trial_intermediate_valuer1   _apply_set_trial_user_attrr2   _apply_set_trial_system_attr)rJ   rr   r   ops       r5   rq   %JournalStorageReplayResult.apply_logs  sS   C  A% YB%222((-'444((-';;;//4'===11#6'444((-'777++C0'>>>2237'DDD88=';;;//4'===11#6111u1 r4   c                \    XR                   ;  a  [        [        5      eU R                   U   $ rn   )r  r_   r   r   s     r5   r   $JournalStorageReplayResult.get_study  s&    ==(=))}}X&&r4   c                H    [        U R                  R                  5       5      $ rn   )listr  r   r   s    r5   rx   *JournalStorageReplayResult.get_all_studies  s    DMM((*++r4   c                \    XR                   ;  a  [        [        5      eU R                   U   $ rn   )r   r_   r   r   s     r5   r   $JournalStorageReplayResult.get_trial  s&    <<'=))||H%%r4   c                    XR                   ;  a  [        [        5      e/ nU R                  U    H8  nU R                  U   nUb  UR
                  U;   d  M'  UR                  U5        M:     U$ rn   )r  r_   r   r   r   rS   append)rJ   r   r   r   r   trials         r5   r   )JournalStorageReplayResult.get_all_trials  sg     ==(=))+-33H=HLL*E~!6$$U+ > r4   c                X    U R                   [        [        R                  " 5       5      -   $ rn   )r?   r<   rA   	get_identr   s    r5   rh   $JournalStorageReplayResult.worker_id  s!    %%I,?,?,A(BBBr4   c                L    U R                   R                  U R                  5      $ rn   )rb   r   rh   r   s    r5   r   )JournalStorageReplayResult.owned_trial_id  s    0044T^^DDr4   c                &    US   U R                   :H  $ )Nrh   )rh   )rJ   r   s     r5   _is_issued_by_this_worker4JournalStorageReplayResult._is_issued_by_this_worker  s    ;4>>11r4   c                n    XR                   ;   a  gU R                  U5      (       a  [        [        5      eg)NTF)r  r%  r_   r   )rJ   r   r   s      r5   _study_exists(JournalStorageReplayResult._study_exists  s.    }}$))#..=))r4   c           	        US   nUS    Vs/ s H  n[        U5      PM     nnX R                  R                  5        Vs/ s H  oUR                  PM     sn;   a1  U R	                  U5      (       a  [        SR                  U5      5      eg U R                  nU =R                  S-  sl        [        US 0 0 UUS9U R                  U'   / U R                  U'   g s  snf s  snf )Nru   rv   zAnother study with name '{}' already exists. Please specify a different name, or reuse the existing one by setting `load_if_exists` (for Python API) or `--skip-if-exists` flag (for CLI).r   )ru   	directionr   r   r   rv   )
r   r  r   ru   r%  r   rz   r  r   r   )rJ   r   ru   drv   sr   s          r5   r  .JournalStorageReplayResult._apply_create_study  s    &
14\1BC1BAnQ'1B
C0D0D0FG0F1,,0FGG--c22*9 :@
9K	  &&q "-!!#
h 13##H-/ DGs   C Cc                    US   nU R                  X!5      (       a.  U R                  R                  U5      nUR                  U:X  d   eg g r   )r(  r  popr{   )rJ   r   r   fss       r5   r	  .JournalStorageReplayResult._apply_delete_study  sG    z?h,,""8,B<<8+++ -r4   c                    US   nU R                  X!5      (       a@  [        US   5      S:X  d   eU R                  U   R                  R	                  US   5        g g )Nr   r   r   )r(  r   r  r   rW   rJ   r   r   s      r5   r
  5JournalStorageReplayResult._apply_set_study_user_attr  s[    z?h,,s;'(A---MM(#..55c+6FG -r4   c                    US   nU R                  X!5      (       a@  [        US   5      S:X  d   eU R                  U   R                  R	                  US   5        g g )Nr   r   r   )r(  r   r  r   rW   r4  s      r5   r  7JournalStorageReplayResult._apply_set_study_system_attr  s[    z?h,,s=)*a///MM(#0077M8JK -r4   c                   US   nU R                  X!5      (       d  g [        U R                  5      n0 nSU;   a1  US   R                  5        VVs0 s H  u  pVU[	        U5      _M     nnn0 nSU;   a9  US   R                  5        VVs0 s H  u  pXXTU   R                  U5      _M     nnnUS   b#  [        R                  R                  US   5      n	OS n	SU;   a#  [        R                  R                  US   5      n
OS n
[        U[        U R                  U   5      [        UR                  S[        R                  R                  5      5      UUUR                  S0 5      UR                  S0 5      UR                  S	S 5      UR                  S
0 5      R                  5        VVs0 s H  u  pV[        U5      U_M     snnU	U
UR                  SS 5      S9U R                  U'   U R                  U   R                  U5        X R                   U'   U R#                  U5      (       aK  X0l        U R                  U   R&                  [        R                  :X  a  X0R(                  U R*                  '   g g g s  snnf s  snnf s  snnf )Nr   r   r   r   r   rS   r   r   r   r   r   )r   r   rS   r   r   r   r   r   r   r   r   r   )r(  r   r   r   r   to_external_reprr   fromisoformatr   r   r   r   r   r   r   r  r  r%  rc   rS   rb   rh   )rJ   r   r   r   r   r   vr   pr   r   s              r5   r  .JournalStorageReplayResult._apply_create_trial  sS   z?!!(00t||$c!DGDXD^D^D`aD`DAQ 4Q 77D`Mas?JMh-J]J]J_`J_$!aq)::1==J_F` ,%..<<SAQ=RSN!N#% ( 1 1 ? ?DW@X Y $!,t228<=SWWWj.@.@.F.FGH'ww|R04'''4(7:ww?TVX7Y7_7_7a b7atqQ7a b)/778T*"
X 	##H-44X>/7""8,))#..:B7||H%++z/A/AADL11$..A B /? b a& !cs   I5	 I;)Jc                   US   nU R                  X!5      (       d  g US   nUS   n[        US   5      nU R                  U   nU R                  U    HK  nU R                  U   nX8R
                  R                  5       ;   d  M1   [        UR                  U   U5          O   [        R                  " U R                  U   5      n	0 [        R                  " U	R
                  5      EX5R                  U5      0EU	l        0 [        R                  " U	R                  5      EX50EU	l        XR                  U'   g ! [         a    U R                  U5      (       a  e    g f = f)Nr   r   r   r   )_trial_exists_and_updatabler   r  r   r   r   keysr
   r   	Exceptionr%  rQ   r9  )
rJ   r   r   r   r   r   r   prev_trial_id
prev_trialr  s
             r5   r  1JournalStorageReplayResult._apply_set_trial_paramF  sR   z?//>>&
"#9:+C,?@--h7!88BMm4J..33554"00<l  C 		$,,x01
ii%
556JK
 [5+>+>!?ZZ!&X ! 55c::s   D77!EEc                   US   nU R                  X!5      (       d  g [        US   5      nX0R                  U   R                  :X  a  U[        R                  :X  a  g [
        R
                  " U R                  U   5      nU[        R                  :X  aU  [        R                  R                  US   5      Ul        U R                  U5      (       a  X R                  U R                  '   UR                  5       (       a'  [        R                  R                  US   5      Ul        X4l        US   b
  US   Ul        X@R                  U'   g )Nr   rS   r   r   r   )r?  r   r   rS   r   rQ   r   r:  r   r%  rb   rh   r   r   r   )rJ   r   r   rS   r  s        r5   r  8JournalStorageReplayResult._apply_set_trial_state_valuesg  s   z?//>>3w<(LL*000Uj>P>P5P		$,,x01J&&&#+#4#4#B#B3GWCX#YE --c22DL11$..A&.&7&7&E&EcJ]F^&_E#x=$x=EL!&Xr4   c                    US   nU R                  X!5      (       ac  [        R                  " U R                  U   5      n0 [        R                  " UR                  5      EUS   US   0EUl        X0R                  U'   g g )Nr   r   r   )r?  rQ   r   r   rJ   r   r   r  s       r5   r  >JournalStorageReplayResult._apply_set_trial_intermediate_value  s{    z?++H::IIdll845E)))E556)FS!56)E% &+LL" ;r4   c                   US   nU R                  X!5      (       ar  [        US   5      S:X  d   e[        R                  " U R                  U   5      n0 [        R                  " UR                  5      EUS   EUl        X0R                  U'   g g )Nr   r   r   )r?  r   rQ   r   r   rH  s       r5   r  5JournalStorageReplayResult._apply_set_trial_user_attr  s    z?++H::s;'(A---IIdll845ER$))E,<,<"=R[AQRE%*LL"	 ;r4   c                   US   nU R                  X!5      (       ar  [        US   5      S:X  d   e[        R                  " U R                  U   5      n0 [        R                  " UR                  5      EUS   EUl        X0R                  U'   g g )Nr   r   r   )r?  r   rQ   r   r   rH  s       r5   r  7JournalStorageReplayResult._apply_set_trial_system_attr  s    z?++H::s=)*a///IIdll845E"))E../"m$"E &+LL" ;r4   c                Z   XR                   ;  a&  U R                  U5      (       a  [        [        5      egU R                   U   R                  R                  5       (       aJ  U R                  U5      (       a3  [        [        R                  U R                   U   R                  S95      egg)NFr   T)
r   r%  r_   r   rS   r   r   r   rz   r   )rJ   r   r   s      r5   r?  6JournalStorageReplayResult._trial_exists_and_updatable  s    <<'--c22}--\\(#))5577--c22.#**X8N8U8U*V  r4   )	rc   r  r  r   r  r   r?   rb   rp   N)r  r<   r   r   )rr   zIterable[dict[str, Any]]r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r<   )r   z
int | None)r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   )r%   r&   r'   r(   rM   rq   r   rx   r   r   propertyrh   r   r%  r(  r  r	  r
  r  r  r  r  r  r  r  r?  r3   r$   r4   r5   rD   rD     s    	?26'
,&
%A	 C C E E236,HL+MZ'B'0	++
+r4   rD   )2
__future__r   collections.abcr   r   r   rQ   r   enumr\   rA   typingr   r=   optunaoptuna._typingr   optuna.distributionsr	   r
   r   r   optuna.exceptionsr   r   optuna.storagesr   optuna.storages._baser   optuna.storages.journal._baser   r   optuna.study._frozenr   optuna.study._study_directionr   optuna.trialr   r   logging
get_loggerr%   r`   r   r   r|   IntEnumr   r7   rD   r$   r4   r5   <module>rb     s    " % $ $         + 1 A 5 5 2 6 ' ; < = , 8 $ # ..
#
#H
-(U 
t|| 
^![ ^!BU Ur4   