
    Q-j'                        d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 erd dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  ed       G d de
             Zy)    )annotations)Any)TYPE_CHECKING)experimental_class)optuna_warn)BaseSampler)Sequence)BaseDistribution)Study)FrozenTrial)
TrialStatez2.4.0c                      e Zd ZdZd
dZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZddZ		 	 	 	 	 	 	 	 	 	 ddZ
y	)PartialFixedSamplera  Sampler with partially fixed parameters.

    Example:

        After several steps of optimization, you can fix the value of ``y`` and re-optimize it.

        .. testcode::

            import optuna


            def objective(trial):
                x = trial.suggest_float("x", -1, 1)
                y = trial.suggest_int("y", -1, 1)
                return x**2 + y


            study = optuna.create_study()
            study.optimize(objective, n_trials=10)

            best_params = study.best_params
            fixed_params = {"y": best_params["y"]}
            partial_sampler = optuna.samplers.PartialFixedSampler(fixed_params, study.sampler)

            study.sampler = partial_sampler
            study.optimize(objective, n_trials=10)

    Args:

        fixed_params:
            A dictionary of parameters to be fixed.

        base_sampler:
            A sampler which samples unfixed parameters.

    c                     || _         || _        y N)_fixed_params_base_sampler)selffixed_paramsbase_samplers      l/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/optuna/samplers/_partial_fixed.py__init__zPartialFixedSampler.__init__;   s    ))    c                8    | j                   j                          y r   )r   
reseed_rng)r   s    r   r   zPartialFixedSampler.reseed_rng?   s    %%'r   c                    | j                   j                  ||      }| j                  j                         D ]
  }||v s||=  |S r   )r   infer_relative_search_spacer   keys)r   studytrialsearch_space
param_names        r   r   z/PartialFixedSampler.infer_relative_search_spaceB   sO     ))EEeUS ,,113J\) , 4 r   c                <    | j                   j                  |||      S r   )r   sample_relative)r   r   r    r!   s       r   r$   z#PartialFixedSampler.sample_relativeN   s     !!11%MMr   c           	         || j                   vr| j                  j                  ||||      S | j                   |   }|j                  |      }|j	                  |      }|st        d| d| d| d       |S )NzFixed parameter 'z' with value z" is out of range for distribution .)r   r   sample_independentto_internal_repr	_containsr   )r   r   r    r"   param_distributionparam_valueparam_value_in_internal_repr	containeds           r   r'   z&PartialFixedSampler.sample_independentW   s     T///%%88uj*<  ,,Z8K+=+N+N{+[(*445QRI'
|= N((:';1> r   c                <    | j                   j                  ||       y r   )r   before_trial)r   r   r    s      r   r/   z PartialFixedSampler.before_trialr   s    ''u5r   c                @    | j                   j                  ||||       y r   )r   after_trial)r   r   r    statevaluess        r   r1   zPartialFixedSampler.after_trialu   s     	&&ueUFCr   N)r   dict[str, Any]r   r   returnNone)r5   r6   )r   r   r    r   r5   dict[str, BaseDistribution])r   r   r    r   r!   r7   r5   r4   )
r   r   r    r   r"   strr*   r
   r5   r   )r   r   r    r   r5   r6   )
r   r   r    r   r2   r   r3   zSequence[float] | Noner5   r6   )__name__
__module____qualname____doc__r   r   r   r$   r'   r/   r1    r   r   r   r      s    #J*(

#.
	$
NN N 2	N
 
N  	
 - 
66DD D 	D
 'D 
Dr   r   N)
__future__r   typingr   r   optuna._experimentalr   optuna._warningsr   optuna.samplersr   collections.abcr	   optuna.distributionsr
   optuna.studyr   optuna.trialr   r   r   r=   r   r   <module>rG      sQ    "    3 ( ' (5"(' GgD+ gD gDr   