Ë
    þÍ:j~n  ã                  ó  — U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z
d dl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 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 d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& erHd dl'm(Z( d dlm)Z) d dl*Z*d dlm+Z+ d dl%m,Z, e*jZ                  e*j\                  z  e*j^                  z  Z0de1d<   n ed«      Z* ejd                  e3«      Z4dZ5dZ6 G d„ de«      Z7	 	 	 	 	 	 d!d „Z8y)"é    )ÚannotationsN)ÚAny)Úcast)ÚTYPE_CHECKING)Ú_deprecated)Úlogging)Úconvert_positional_args)Úwarn_experimental_argument)Ú_LazyImport)Ú_SearchSpaceTransform)Úoptuna_warn)ÚFloatDistribution)ÚIntDistribution)ÚBaseSampler)Ú&_INDEPENDENT_SAMPLING_WARNING_TEMPLATE)ÚLazyRandomState)ÚIntersectionSearchSpace)ÚStudyDirection)Ú
TrialState)ÚSequence)Ú	TypeAlias)ÚBaseDistribution)ÚFrozenTrialr   ÚCmaClassÚcmaesg»½×Ùß|Û=iý  c                  ó‚  — e Zd ZdZ eg d¢dd¬«      ddddddd	ddd
d	d	d	ddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdd„Z	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 dd„Ze	d d„«       Z
e	d d„«       Zd!d„Zd"d„Z	 	 	 	 d#d„Z	 	 	 	 	 	 d$d„Z	 	 	 	 	 	 	 	 	 	 d%d„Zd&d„Zd'd„Z	 	 	 	 	 	 d(d„Zd)d„Z	 	 	 	 	 	 	 	 	 	 d*d„Zy)+ÚCmaEsSampleruž(  A sampler using `cmaes <https://github.com/CyberAgentAILab/cmaes>`__ as the backend.

    Example:

        Optimize a simple quadratic function by using :class:`~optuna.samplers.CmaEsSampler`.

        .. code-block:: console

           $ pip install cmaes

        .. testcode::

            import optuna


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


            sampler = optuna.samplers.CmaEsSampler()
            study = optuna.create_study(sampler=sampler)
            study.optimize(objective, n_trials=20)

    Please note that this sampler does not support CategoricalDistribution.
    If your search space includes categorical parameters, it is recommended to use
    `CatCmawmSampler <https://hub.optuna.org/samplers/catcmawm/>`__ available on
    `OptunaHub <https://hub.optuna.org/>`__.

    Furthermore, there is room for performance improvements in parallel
    optimization settings. This sampler cannot use some trials for updating
    the parameters of multivariate normal distribution.

    For further information about CMA-ES algorithm, please refer to the following papers:

    - `N. Hansen, The CMA Evolution Strategy: A Tutorial. arXiv:1604.00772, 2016.
      <https://arxiv.org/abs/1604.00772>`__
    - `A. Auger and N. Hansen. A restart CMA evolution strategy with increasing population
      size. In Proceedings of the IEEE Congress on Evolutionary Computation (CEC 2005),
      pages 1769â€“1776. IEEE Press, 2005. <https://doi.org/10.1109/CEC.2005.1554902>`__
    - `N. Hansen. Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed.
      GECCO Workshop, 2009. <https://doi.org/10.1145/1570256.1570333>`__
    - `Raymond Ros, Nikolaus Hansen. A Simple Modification in CMA-ES Achieving Linear Time and
      Space Complexity. 10th International Conference on Parallel Problem Solving From Nature,
      Sep 2008, Dortmund, Germany. inria-00287367. <https://doi.org/10.1007/978-3-540-87700-4_30>`__
    - `Masahiro Nomura, Shuhei Watanabe, Youhei Akimoto, Yoshihiko Ozaki, Masaki Onishi.
      Warm Starting CMA-ES for Hyperparameter Optimization, AAAI. 2021.
      <https://doi.org/10.1609/aaai.v35i10.17109>`__
    - `R. Hamano, S. Saito, M. Nomura, S. Shirakawa. CMA-ES with Margin: Lower-Bounding Marginal
      Probability for Mixed-Integer Black-Box Optimization, GECCO. 2022.
      <https://doi.org/10.1145/3512290.3528827>`__
    - `M. Nomura, Y. Akimoto, I. Ono. CMA-ES with Learning Rate Adaptation: Can CMA-ES with
      Default Population Size Solve Multimodal and Noisy Problems?, GECCO. 2023.
      <https://doi.org/10.1145/3583131.3590358>`__

    .. seealso::
        You can also use `optuna_integration.PyCmaSampler <https://optuna-integration.readthedocs.io/en/stable/reference/generated/optuna_integration.PyCmaSampler.html#optuna_integration.PyCmaSampler>`__ which is a sampler using cma
        library as the backend.

    Args:

        x0:
            A dictionary of an initial parameter values for CMA-ES. By default, the mean of ``low``
            and ``high`` for each distribution is used. Note that ``x0`` is sampled uniformly
            within the search space domain for each restart if you specify ``restart_strategy``
            argument.

            .. warning::
                Deprecated in v4.9.0. ``x0`` argument will be removed in the future.
                The removal of this feature is currently scheduled for v6.0.0,
                but this schedule is subject to change.

        sigma0:
            Initial standard deviation of CMA-ES. By default, ``sigma0`` is set to
            ``min_range / 6``, where ``min_range`` denotes the minimum range of the distributions
            in the search space.

            .. warning::
                Deprecated in v4.9.0. ``sigma0`` argument will be removed in the future.
                The removal of this feature is currently scheduled for v6.0.0,
                but this schedule is subject to change.

        seed:
            A random seed for CMA-ES.

        n_startup_trials:
            The independent sampling is used instead of the CMA-ES algorithm until the given number
            of trials finish in the same study.

        independent_sampler:
            A :class:`~optuna.samplers.BaseSampler` instance that is used for independent
            sampling. The parameters not contained in the relative search space are sampled
            by this sampler.
            The search space for :class:`~optuna.samplers.CmaEsSampler` is determined by
            :func:`~optuna.search_space.intersection_search_space()`.

            If :obj:`None` is specified, :class:`~optuna.samplers.RandomSampler` is used
            as the default.

            .. seealso::
                :class:`optuna.samplers` module provides built-in independent samplers
                such as :class:`~optuna.samplers.RandomSampler` and
                :class:`~optuna.samplers.TPESampler`.

        warn_independent_sampling:
            If this is :obj:`True`, a warning message is emitted when
            the value of a parameter is sampled by using an independent sampler.

            Note that the parameters of the first trial in a study are always sampled
            via an independent sampler, so no warning messages are emitted in this case.

        restart_strategy:
            Strategy for restarting CMA-ES optimization when converges to a local minimum.
            If :obj:`None` is given, CMA-ES will not restart (default).
            If 'ipop' is given, CMA-ES will restart with increasing population size.
            if 'bipop' is given, CMA-ES will restart with the population size
            increased or decreased.
            Please see also ``inc_popsize`` parameter.

            .. warning::
                Deprecated in v4.4.0. ``restart_strategy`` argument will be removed in the future.
                The removal of this feature is currently scheduled for v6.0.0,
                but this schedule is subject to change.
                From v4.4.0 onward, ``restart_strategy`` automatically falls back to ``None``, and
                ``restart_strategy`` will be supported in OptunaHub.
                See https://github.com/optuna/optuna/releases/tag/v4.4.0.

        popsize:
            A population size of CMA-ES.

        inc_popsize:
            Multiplier for increasing population size before each restart.
            This argument will be used when ``restart_strategy = 'ipop'``
            or ``restart_strategy = 'bipop'`` is specified.

            .. warning::
                Deprecated in v4.4.0. ``inc_popsize`` argument will be removed in the future.
                The removal of this feature is currently scheduled for v6.0.0,
                but this schedule is subject to change.
                From v4.4.0 onward, ``inc_popsize`` is no longer utilized within Optuna, and
                ``inc_popsize`` will be supported in OptunaHub.
                See https://github.com/optuna/optuna/releases/tag/v4.4.0.

        consider_pruned_trials:
            If this is :obj:`True`, the PRUNED trials are considered for sampling.

            .. note::
                Added in v2.0.0 as an experimental feature. The interface may change in newer
                versions without prior notice. See
                https://github.com/optuna/optuna/releases/tag/v2.0.0.

            .. note::
                It is suggested to set this flag :obj:`False` when the
                :class:`~optuna.pruners.MedianPruner` is used. On the other hand, it is suggested
                to set this flag :obj:`True` when the :class:`~optuna.pruners.HyperbandPruner` is
                used. Please see `the benchmark result
                <https://github.com/optuna/optuna/pull/1229>`__ for the details.

        use_separable_cma:
            If this is :obj:`True`, the covariance matrix is constrained to be diagonal.
            Due to reduce the model complexity, the learning rate for the covariance matrix
            is increased. Consequently, this algorithm outperforms CMA-ES on separable functions.

            .. note::
                Added in v2.6.0 as an experimental feature. The interface may change in newer
                versions without prior notice. See
                https://github.com/optuna/optuna/releases/tag/v2.6.0.

        with_margin:
            If this is :obj:`True`, CMA-ES with margin is used. This algorithm prevents samples in
            each discrete distribution (:class:`~optuna.distributions.FloatDistribution` with
            ``step`` and :class:`~optuna.distributions.IntDistribution`) from being fixed to a single
            point.
            Currently, this option cannot be used with ``use_separable_cma=True``.

            .. note::
                Added in v3.1.0 as an experimental feature. The interface may change in newer
                versions without prior notice. See
                https://github.com/optuna/optuna/releases/tag/v3.1.0.

        lr_adapt:
            If this is :obj:`True`, CMA-ES with learning rate adaptation is used.
            This algorithm focuses on working well on multimodal and/or noisy problems
            with default settings.
            Currently, this option cannot be used with ``use_separable_cma=True`` or
            ``with_margin=True``.

            .. note::
                Added in v3.3.0 or later, as an experimental feature.
                The interface may change in newer versions without prior notice. See
                https://github.com/optuna/optuna/releases/tag/v3.3.0.

        source_trials:
            This option is for Warm Starting CMA-ES, a method to transfer prior knowledge on
            similar HPO tasks through the initialization of CMA-ES. This method estimates a
            promising distribution from ``source_trials`` and generates the parameter of
            multivariate gaussian distribution. Please note that it is prohibited to use
            ``use_separable_cma`` argument together.

            .. note::
                Added in v2.6.0 as an experimental feature. The interface may change in newer
                versions without prior notice. See
                https://github.com/optuna/optuna/releases/tag/v2.6.0.

    )ÚselfÚx0Úsigma0Ún_startup_trialsÚindependent_samplerÚwarn_independent_samplingÚseedú4.9.0ú6.0.0)Úprevious_positional_arg_namesÚdeprecated_versionÚremoved_versionNé   TFéÿÿÿÿ)r   r    r!   r"   r#   r$   Úconsider_pruned_trialsÚrestart_strategyÚpopsizeÚinc_popsizeÚuse_separable_cmaÚwith_marginÚlr_adaptÚsource_trialsc               óV  — |€|
dk7  r5t         j                  j                  ddd¬«      }t        |› d�t        «       |�2t         j                  j                  ddd¬«      }t        |t        «       |�2t         j                  j                  d	dd¬«      }t        |t        «       || _        || _        |xs  t        j                  j                  |¬
«      | _
        || _        || _        t        |«      | _        t        «       | _        || _        |	| _        || _        || _        || _        || _        | j&                  rd| _        n| j(                  rd| _        nd| _        | j"                  rt1        d«       | j&                  rt1        d«       | j,                  �t1        d«       | j(                  rt1        d«       | j*                  rt1        d«       |�|€|�t3        d«      ‚|�|rt3        d«      ‚|r|s|rt3        d«      ‚| j&                  r| j(                  rt3        d«      ‚y y )Nr+   z`restart_strategy`z4.4.0r&   )ÚnameÚd_verÚr_verz~ From v4.4.0 onward, `restart_strategy` automatically falls back to `None`. `restart_strategy` will be supported in OptunaHub.z`x0`r%   z`sigma0`)r$   zsepcma:zcmawm:zcma:r,   r0   r3   r1   r2   zQIt is prohibited to pass `source_trials` argument when x0 or sigma0 is specified.zNIt is prohibited to pass `source_trials` argument when using separable CMA-ES.z]It is prohibited to pass `use_separable_cma` or `with_margin` argument when using `lr_adapt`.zMCurrently, we do not support `use_separable_cma=True` and `with_margin=True`.)r   Ú_DEPRECATION_WARNING_TEMPLATEÚformatr   ÚFutureWarningÚ_x0Ú_sigma0ÚoptunaÚsamplersÚRandomSamplerÚ_independent_samplerÚ_n_startup_trialsÚ_warn_independent_samplingr   Ú_cma_rngr   Ú_search_spaceÚ_consider_pruned_trialsÚ_popsizeÚ_use_separable_cmaÚ_with_marginÚ	_lr_adaptÚ_source_trialsÚ_attr_prefixr
   Ú
ValueError)r   r   r    r!   r"   r#   r$   r,   r-   r.   r/   r0   r1   r2   r3   Úmsgs                   úk/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/samplers/_cmaes.pyÚ__init__zCmaEsSampler.__init__  sC  € ð> Ð'¨;¸"Ò+<Ü×;Ñ;×BÑBØ)°Àð Có ˆCô Ø�%ð Mð Mäôð
 ˆ>Ü×;Ñ;×BÑBØ 7°'ð Có ˆCô ˜œ]Ô+ØÐÜ×;Ñ;×BÑBØ w°gð Có ˆCô ˜œ]Ô+àˆŒØˆŒØ$7Ò$c¼6¿?¹?×;XÑ;XÐ^bÐ;XÓ;cˆÔ!Ø!1ˆÔØ*CˆÔ'Ü'¨Ó-ˆŒÜ4Ó6ˆÔØ'=ˆÔ$ØˆŒØ"3ˆÔØ'ˆÔØ!ˆŒØ+ˆÔà×"Ò"Ø )ˆDÕØ×ÒØ (ˆDÕà &ˆDÔà×'Ò'Ü&Ð'?Ô@à×"Ò"Ü&Ð':Ô;à×ÑÐ*Ü& Ô7à×ÒÜ& }Ô5à�>Š>Ü& zÔ2àÐ$¨"¨.¸FÐ<NÜØcóð ð
 Ð$Ñ):ÜØ`óð ñ Ñ*©kÜð$óð ð ×"Ò" t×'8Ò'8ÜØ_óð ð (9Ð"ó    c                ó8   — | j                   j                  «        y ©N)r@   Ú
reseed_rng©r   s    rN   rS   zCmaEsSampler.reseed_rngp  s   € à×!Ñ!×,Ñ,Õ.rP   c                óÆ   — i }| j                   j                  |«      j                  «       D ]2  \  }}|j                  «       rŒt	        |t
        t        f«      sŒ.|||<   Œ4 |S rR   )rD   Ú	calculateÚitemsÚsingleÚ
isinstancer   r   )r   ÚstudyÚtrialÚsearch_spacer5   Údistributions         rN   Úinfer_relative_search_spacez(CmaEsSampler.infer_relative_search_spacet  sm   € ð 57ˆØ"&×"4Ñ"4×">Ñ">¸uÓ"E×"KÑ"KÓ"Mò 
	.ÑˆD�,Ø×"Ñ"Ô$ð ä˜lÔ->ÄÐ,PÔQàØ!-ˆL˜Òð
	.ð ÐrP   c                ó  — | j                  |«       t        |«      dk(  ri S | j                  |«      }t        |«      | j                  k  ri S t	        || j
                   d¬«      }| j                  |«      }|€| j                  ||j                  «      }|j                  t        |j                  «      k7  rN| j                  r@| j                  j                  j                  }t        j!                  d|› d�«       d| _        i S | j#                  ||j$                  «      }t        |«      |j&                  k\  �r@g }	|d |j&                   D ]¶  }
|
j(                  €J d«       ‚t+        |t,        j.                  «      r#t1        j2                  |
j4                  d   «      }n|j7                  |
j8                  «      }|j                  t:        j<                  k(  r|
j(                  n|
j(                   }|	j?                  ||f«       Œ¸ |jA                  |	«       tC        jD                  |«      jG                  «       }| jI                  |«      }|D ],  }|jJ                  jM                  |jN                  |||   «       Œ. | jP                  jR                  jU                  d	d
«      |jV                  z   }|jX                  j[                  |«       t+        |t,        j.                  «      rI|j]                  «       \  }}|jJ                  jM                  |jN                  d|j_                  «       «       n|j]                  «       }| j`                  }|jJ                  jM                  |jN                  ||j$                  «       |jc                  |«      }|S )Nr   T)Útransform_stepÚtransform_0_1z7`CmaEsSampler` does not support dynamic search space. `z$` is used instead of `CmaEsSampler`.Fz"completed trials must have a valueÚ
x_for_tellr*   i   )2Ú_raise_error_if_multi_objectiveÚlenÚ_get_trialsrA   r   rH   Ú_restore_optimizerÚ_init_optimizerÚ	directionÚdimÚboundsrB   r@   Ú	__class__Ú__name__Ú_loggerÚwarningÚ_get_solution_trialsÚ
generationÚpopulation_sizeÚvaluerY   r   ÚCMAwMÚnpÚarrayÚsystem_attrsÚ	transformÚparamsr   ÚMINIMIZEÚappendÚtellÚpickleÚdumpsÚhexÚ_split_optimizer_strÚ_storageÚset_trial_system_attrÚ	_trial_idrC   ÚrngÚrandintÚnumberÚ_rngr$   ÚaskÚtolistÚ_attr_key_generationÚuntransform)r   rZ   r[   r\   Úcompleted_trialsÚtransÚ	optimizerÚind_sampler_nameÚsolution_trialsÚ	solutionsÚtÚxÚyÚoptimizer_strÚoptimizer_attrsÚkeyr$   rx   rb   Úgeneration_attr_keyÚexternal_valuess                        rN   Úsample_relativezCmaEsSampler.sample_relative†  s  € ð 	×,Ñ,¨UÔ3äˆ|Ó Ò!ØˆIà×+Ñ+¨EÓ2ÐÜÐÓ  4×#9Ñ#9Ò9ØˆIô &Ø¨T×->Ñ->Ð)>Èdô
ˆð ×+Ñ+Ð,<Ó=ˆ	ØÐØ×,Ñ,¨U°E·O±OÓDˆIà�=‰=œC §¡Ó-Ò-Ø×.Ò.Ø#'×#<Ñ#<×#FÑ#F×#OÑ#OÐ Ü—‘ðØ(Ð)Ð)MðOôð 38�Ô/ØˆIð ×3Ñ3Ð4DÀi×FZÑFZÓ[ˆäˆÓ 9×#<Ñ#<Ó<Ø8:ˆIØ$Ð%@ y×'@Ñ'@ÐAò )�Ø—w‘wÐ*ÐPÐ,PÓPÐ*Ü˜i¬¯©Ô5ÜŸ™ §¡°Ñ!=Ó>‘AàŸ™¨¯©Ó1�AØ$Ÿ™´.×2IÑ2IÒI�A—G’GÐPQ×PWÑPWÈx�Ø× Ñ  ! Q Õ(ð)ð �N‰N˜9Ô%ô #ŸL™L¨Ó3×7Ñ7Ó9ˆMØ"×7Ñ7¸ÓFˆOØ&ò a�Ø—‘×4Ñ4°U·_±_ÀcÈ?Ð[^ÑK_Õ`ðað �}‰}× Ñ ×(Ñ(¨¨EÓ2°U·\±\ÑAˆØ�‰×Ñ˜DÔ!Ü�i¤§¡Ô-Ø!*§¡£ÑˆF�JØ�N‰N×0Ñ0Ø—‘ ¨z×/@Ñ/@Ó/Bõð —]‘]“_ˆFà"×7Ñ7ÐØ�‰×,Ñ,Ø�O‰OÐ0°)×2FÑ2Fô	
ð  ×+Ñ+¨FÓ3ˆàÐrP   c                ó    — | j                   dz   S )Nrp   ©rK   rT   s    rN   r‰   z!CmaEsSampler._attr_key_generationÓ  s   € à× Ñ  <Ñ/Ð/rP   c                ó    — | j                   dz   S )Nr�   r›   rT   s    rN   Ú_attr_key_optimizerz CmaEsSampler._attr_key_optimizer×  s   € à× Ñ  ;Ñ.Ð.rP   c                ó`   ‡ ‡— dj                  ˆˆ fd„t        t        ‰«      «      D «       «      S )NÚ c              3  óF   •K  — | ]  }‰‰j                   › d |› �   –— Œ y­w)ú:N)r�   )Ú.0Úir•   r   s     €€rN   ú	<genexpr>z7CmaEsSampler._concat_optimizer_attrs.<locals>.<genexpr>Ü  s-   øè ø€ ò 
ØCDˆO˜t×7Ñ7Ð8¸¸!¸Ð=Õ>ñ
ùs   ƒ!)ÚjoinÚrangerd   )r   r•   s   ``rN   Ú_concat_optimizer_attrsz$CmaEsSampler._concat_optimizer_attrsÛ  s,   ù€ Ø�w‰wô 
ÜHMÌcÐRaÓNbÓHcô
ó 
ð 	
rP   c                óà   — t        |«      }i }t        t        j                  |t        z  «      «      D ]8  }|t        z  }t        |dz   t        z  |«      }||| || j                  › d|› �<   Œ: |S )Nr*   r¡   )rd   r¦   ÚmathÚceilÚ_SYSTEM_ATTR_MAX_LENGTHÚminr�   )r   r”   Úoptimizer_lenÚattrsr£   ÚstartÚends          rN   r   z!CmaEsSampler._split_optimizer_strà  s�   € Ü˜MÓ*ˆØˆÜ”t—y‘y Ô1HÑ!HÓIÓJò 	PˆAØÔ/Ñ/ˆEÜ�q˜1‘uÔ 7Ñ7¸ÓGˆCØ7DÀUÈ3Ð7OˆE�T×-Ñ-Ð.¨a°¨sÐ3Ò4ð	Pð ˆrP   c                óR  — t        |«      D ]“  }|j                  j                  «       D ��ci c]#  \  }}|j                  | j                  «      r||“Œ% }}}t        |«      dk(  rŒZ| j                  |«      }t        j                  t        j                  |«      «      c S  y c c}}w )Nr   )Úreversedrv   rW   Ú
startswithr�   rd   r§   r|   ÚloadsÚbytesÚfromhex)r   r‹   r[   r–   rr   r•   r”   s          rN   rf   zCmaEsSampler._restore_optimizeré  s¥   € ô
 Ð.Ó/ò 
	>ˆEð #(×"4Ñ"4×":Ñ":Ó"<÷á�C˜Ø—>‘> $×":Ñ":Ô;ð �U‘
ðˆOñ ô
 �?Ó# qÒ(Øà ×8Ñ8¸ÓIˆMÜ—<‘<¤§¡¨mÓ <Ó=Ò=ð
	>ð ùós   ¬(B#c                óÈ  — |j                   d d …df   }|j                   d d …df   }t        |j                   «      }| j                  €j| j                  €|||z
  dz  z   }n|j	                  | j                  «      }| j
                  €t        j                  ||z
  dz  «      }n| j
                  }d }nôt        j                  g}	| j                  r|	j                  t        j                  «       |t        j                  k(  rdnd}
| j                  D �cg c]Z  }|j                  |	v rJt!        ||j"                  «      r4|j	                  |j$                  «      |
t'        d|j(                  «      z  f‘Œ\ }}t        |«      dk(  rt+        d«      ‚t-        j.                  |«      \  }}}t1        |t2        «      }| j4                  rt        |j                   «      dk(  rt7        dt8        «       nVt-        j:                  |||j                   | j<                  j>                  jA                  dd	«      d
|z  | jB                  ¬«      S | jD                  �r/t        jF                  t        |jH                  «      tJ        ¬«      }tM        |jH                  jO                  «       «      D ]ƒ  \  }}tQ        |tR        tT        f«      sJ ‚|jV                  �|jX                  rd||<   Œ<|jZ                  |j\                  k(  rd||<   Œ[|jV                  |j\                  |jZ                  z
  z  ||<   Œ… t-        j^                  |||j                   ||| j<                  j>                  jA                  dd	«      d
|z  | jB                  ¬«      S t-        j`                  ||||j                   | j<                  j>                  jA                  dd	«      d
|z  | jB                  | jb                  ¬«      S c c}w )Nr   r*   é   é   r+   ÚfloatzNo compatible source_trialsz‰Separable CMA-ES does not operate meaningfully on single-dimensional search spaces. The setting `use_separable_cma=True` will be ignored.iþÿÿé
   )ÚmeanÚsigmarj   r$   Ún_max_resamplingrq   )Údtypeg        g      ð?)r¼   r½   rj   ÚstepsÚcovr$   r¾   rq   )r¼   r½   rÁ   rj   r$   r¾   rq   r2   )2rj   rd   rJ   r;   rw   r<   rt   r¬   r   ÚCOMPLETErE   rz   ÚPRUNEDr   ry   ÚstateÚ_is_compatible_search_spaceÚdistributionsrx   r   rr   rL   r   Úget_warm_start_mgdÚmaxÚ_EPSrG   r   ÚUserWarningÚSepCMArC   rƒ   r„   rF   rH   ÚemptyrD   rº   Ú	enumerateÚvaluesrY   r   r   ÚstepÚlogÚlowÚhighrs   ÚCMArI   )r   rŒ   rh   Úlower_boundsÚupper_boundsÚn_dimensionr¼   r    rÁ   Úexpected_statesÚsignr‘   Úsource_solutionsrÀ   r£   Údists                   rN   rg   zCmaEsSampler._init_optimizerû  s]  € ð
 —|‘|¢A q DÑ)ˆØ—|‘|¢A q DÑ)ˆÜ˜%Ÿ,™,Ó'ˆà×ÑÐ&Ø�x‰xÐØ# |°lÑ'BÀaÑ&GÑG‘ð —‘ t§x¡xÓ0�à�|‰|Ð#ÜŸ™ °Ñ!<ÀÑ AÓB‘àŸ™�à‰Cä)×2Ñ2Ð3ˆOØ×+Ò+Ø×&Ñ&¤z×'8Ñ'8Ô9ð "¤^×%<Ñ%<Ò<‘1À"ˆDð ×,Ñ,ö àØ—7‘7˜oÑ-Ü/°°q·±ÔGð —‘ §¡Ó*¨D´4¸ÀÇÁÓ3IÑ,IÒJð Ðð  ô Ð#Ó$¨Ò)Ü Ð!>Ó?Ð?ô !&× 8Ñ 8Ð9IÓ JÑˆD�&˜#ô �VœTÓ"ˆà×"Ò"Ü�5—<‘<Ó  AÒ%Üð[äõô —|‘|ØØ Ø Ÿ<™<ØŸ™×*Ñ*×2Ñ2°1°iÓ@Ø%'¨+Ñ%5Ø$(§M¡Môð ð ×ÓÜ—H‘HœS ×!4Ñ!4Ó5¼UÔCˆEÜ$ U×%8Ñ%8×%?Ñ%?Ó%AÓBò B‘��4Ü! $¬Ô:KÐ(LÔMÐMÐMà—9‘9Ð$¨¯ªØ"�E˜!’HØ—X‘X §¡Ò*Ø"�E˜!’Hà#Ÿy™y¨D¯I©I¸¿¹Ñ,@ÑA�E˜!’HðBô —;‘;ØØØ—|‘|ØØØ—]‘]×&Ñ&×.Ñ.¨q°)Ó<Ø!# kÑ!1Ø $§¡ô	ð 	ô �y‰yØØØØ—<‘<Ø—‘×"Ñ"×*Ñ*¨1¨iÓ8Ø +Ñ-Ø ŸM™MØ—^‘^ô	
ð 		
ùòo s   ÄAOc                óî   — | j                  |«       | j                  r;| j                  |«      }t        |«      | j                  k\  r| j                  ||«       | j                  j                  ||||«      S rR   )rc   rB   re   rd   rA   Ú_log_independent_samplingr@   Úsample_independent)r   rZ   r[   Ú
param_nameÚparam_distributionÚcomplete_trialss         rN   rÝ   zCmaEsSampler.sample_independentZ  sq   € ð 	×,Ñ,¨UÔ3à×*Ò*Ø"×.Ñ.¨uÓ5ˆOÜ�?Ó# t×'=Ñ'=Ò=Ø×.Ñ.¨u°jÔAà×(Ñ(×;Ñ;Ø�5˜*Ð&8ó
ð 	
rP   c           	     óÖ   — t         j                  t        j                  ||j                  | j
                  j                  j                  | j                  j                  d¬«      «       y )NzVdynamic search space and `CategoricalDistribution` are not supported by `CmaEsSampler`)rÞ   Útrial_numberÚindependent_sampler_nameÚsampler_nameÚfallback_reason)rm   rn   r   r9   r…   r@   rk   rl   )r   r[   rÞ   s      rN   rÜ   z&CmaEsSampler._log_independent_samplingl  sM   € Ü�‰Ü2×9Ñ9Ø%Ø"Ÿ\™\Ø)-×)BÑ)B×)LÑ)L×)UÑ)UØ!Ÿ^™^×4Ñ4ð(ô	õ	
rP   c                óÌ  — g }|j                  dd¬«      D ]Ë  }|j                  t        j                  k(  r|j	                  |«       Œ2|j                  t        j
                  k(  sŒPt        |j                  «      dkD  sŒi| j                  sŒvt        |j                  j                  «       «      \  }}|€ŒŸt        j                  |«      }||_        |j	                  |«       ŒÍ |S )NFT)ÚdeepcopyÚ	use_cacher   )re   rÄ   r   rÂ   rz   rÃ   rd   Úintermediate_valuesrE   rÈ   rW   Úcopyrç   rr   )r   rZ   rà   r‘   Ú_rr   Úcopied_ts          rN   re   zCmaEsSampler._get_trialsz  sÄ   € ØˆØ×"Ñ"¨E¸TÐ"ÓBò 	1ˆAØ�w‰wœ*×-Ñ-Ò-Ø×&Ñ& qÕ)à—‘œ:×,Ñ,Ó,Ü˜×-Ñ-Ó.°Ó2Ø×0Ó0ä˜q×4Ñ4×:Ñ:Ó<Ó=‘��5Ø�=ØäŸ=™=¨Ó+�Ø!&�”Ø×&Ñ& xÕ0ð	1ð ÐrP   c                ó„   — | j                   }|D �cg c]$  }||j                  j                  |d«      k(  sŒ#|‘Œ& c}S c c}w )Nr+   )r‰   rv   Úget)r   Útrialsrp   r—   r‘   s        rN   ro   z!CmaEsSampler._get_solution_trials�  s>   € ð #×7Ñ7ÐØ!Ö_�a Z°1·>±>×3EÑ3EÐFYÐ[]Ó3^Ó%^’Ò_Ð_ùÒ_s   ‘$=¶=c                ó<   — | j                   j                  ||«       y rR   )r@   Úbefore_trial)r   rZ   r[   s      rN   rñ   zCmaEsSampler.before_trial“  s   € Ø×!Ñ!×.Ñ.¨u°eÕ<rP   c                ó@   — | j                   j                  ||||«       y rR   )r@   Úafter_trial)r   rZ   r[   rÄ   rÎ   s        rN   ró   zCmaEsSampler.after_trial–  s   € ð 	×!Ñ!×-Ñ-¨e°U¸EÀ6ÕJrP   )r   zdict[str, Any] | Noner    zfloat | Noner!   Úintr"   zBaseSampler | Noner#   Úboolr$   ú
int | Noner,   rõ   r-   z
str | Noner.   rö   r/   rô   r0   rõ   r1   rõ   r2   rõ   r3   zlist[FrozenTrial] | NoneÚreturnÚNone)r÷   rø   )rZ   ú'optuna.Study'r[   ú'optuna.trial.FrozenTrial'r÷   údict[str, BaseDistribution])rZ   rù   r[   rú   r\   rû   r÷   zdict[str, Any])r÷   Ústr)r•   údict[str, str]r÷   rü   )r”   rü   r÷   rý   )r‹   z 'list[optuna.trial.FrozenTrial]'r÷   z'CmaClass' | None)rŒ   r   rh   r   r÷   z
'CmaClass')
rZ   rù   r[   rú   rÞ   rü   rß   r   r÷   r   )r[   r   rÞ   rü   r÷   rø   )rZ   rù   r÷   úlist[FrozenTrial])rï   rþ   rp   rô   r÷   rþ   )rZ   zoptuna.Studyr[   r   r÷   rø   )
rZ   rù   r[   rú   rÄ   r   rÎ   zSequence[float] | Noner÷   rø   )rl   Ú
__module__Ú__qualname__Ú__doc__r	   rO   rS   r^   r™   Úpropertyr‰   r�   r§   r   rf   rg   rÝ   rÜ   re   ro   rñ   ró   © rP   rN   r   r   2   se  „ ñMñ^ ò'
ð #Øôð  %)Ø#Ø !Ø26Ø*.ØØ',Ø'+Ø"ØØ"'Ø!ØØ26ñ!_ð "ð_ð ð	_ð
 ð_ð 0ð_ð $(ð_ð ð_ð !%ð_ð %ð_ð ð_ð ð_ð  ð_ð ð_ð ð_ð  0ð!_ð" 
ò#_óð_óB/ðØ#ðØ,Fðà	$óð$KàðKð *ðKð 2ð	Kð
 
óKðZ ò0ó ð0ð ò/ó ð/ó
ó
ðà:ðð 
óð$]
à$ð]
ð "ð]
ð 
ó	]
ð~
àð
ð *ð
ð ð	
ð
 -ð
ð 
ó
ó$
óð&`Ø'ð`Ø58ð`à	ó`ó=ðKàðKð *ðKð ð	Kð
 'ðKð 
ôKrP   r   c                óì   — t        t        | j                  j                  «       «      j	                  |j                  «       «      «      }|t        | j                  «      cxk(  xr t        |«      k(  S c S rR   )rd   ÚsetrD   ÚkeysÚintersection)rŒ   r\   Úintersection_sizes      rN   rÅ   rÅ      s]   € ô œC × 3Ñ 3× 8Ñ 8Ó :Ó;×HÑHÈ×IZÑIZÓI\Ó]Ó^ÐØ¤ E×$7Ñ$7Ó 8ÖM¼CÀÓ<MÑMÐMÑMÐMrP   )rŒ   r   r\   rû   r÷   rõ   )9Ú
__future__r   rê   r©   r|   Útypingr   r   r   Únumpyrt   r=   r   r   Úoptuna._convert_positional_argsr	   Úoptuna._experimentalr
   Úoptuna._importsr   Úoptuna._transformr   Úoptuna._warningsr   Úoptuna.distributionsr   r   Úoptuna.samplersr   Úoptuna.samplers._baser   Ú"optuna.samplers._lazy_random_stater   Úoptuna.search_spacer   Úoptuna.study._study_directionr   Úoptuna.trialr   Úcollections.abcr   r   r   r   r   rÓ   rË   rs   r   Ú__annotations__Ú
get_loggerrl   rm   rÉ   r«   r   rÅ   r  rP   rN   ú<module>r     sÚ   ðÞ "ã Û Û Ý Ý Ý  ã ã Ý Ý Ý CÝ ;Ý 'Ý 3Ý (Ý 2Ý 0Ý 'Ý HÝ >Ý 7Ý 8Ý #ñ Ý(Ý ãå5Ý(àŸ)™) e§l¡lÑ2°U·[±[Ñ@€HˆiÔ@á˜Ó €Eà
ˆ'×
Ñ
˜XÓ
&€à€àÐ ôk	K�;ô k	Kð\NØ ðNØ0KðNà	ôNrP   