Ë
    þÍ:j,k  ã                  ó˜  — d dl mZ d dlZd dl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	mZ d dl	mZ d dlmZ d d	lmZ erd d
lmZ edeeeef   ZdZdZ G d„ dej6                  «      Z G d„ de«      Z edde¬«       G d„ de«      «       Z edde¬«       G d„ de«      «       Z edde¬«       G d„ de«      «       Z  G d„ de«      Z! edde¬«       G d„ de!«      «       Z" edde¬«       G d„ de!«      «       Z#	 	 	 	 	 	 d*d „Z$ G d!„ d"e«      Z%e!e#e"eeee e%fZ&d+d#„Z'd,d$„Z(	 	 	 	 	 	 d-d%„Z)d.d&„Z*d/d'„Z+d0d(„Z,	 d1	 	 	 	 	 d2d)„Z-y)3é    )ÚannotationsN)ÚReal)ÚAny)Úcast)ÚTYPE_CHECKING)ÚUnion)Údeprecated_class©Úoptuna_warn)ÚSequencez=Use :class:`~optuna.distributions.FloatDistribution` instead.z;Use :class:`~optuna.distributions.IntDistribution` instead.c                  óª   — e Zd ZdZdd„Zej                  dd„«       Zej                  dd„«       Zej                  dd„«       Z	dd„Z
dd„Zdd„Zdd	„Zy
)ÚBaseDistributionzÒBase class for distributions.

    Note that distribution classes are not supposed to be called by library users.
    They are used by :class:`~optuna.trial.Trial` and :class:`~optuna.samplers` internally.
    c                ó   — |S )a0  Convert internal representation of a parameter value into external representation.

        Args:
            param_value_in_internal_repr:
                Optuna's internal representation of a parameter value.

        Returns:
            Optuna's external representation of a parameter value.
        © ©ÚselfÚparam_value_in_internal_reprs     úi/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/distributions.pyÚto_external_reprz!BaseDistribution.to_external_repr&   s
   € ð ,Ð+ó    c                ó   — t         ‚)a0  Convert external representation of a parameter value into internal representation.

        Args:
            param_value_in_external_repr:
                Optuna's external representation of a parameter value.

        Returns:
            Optuna's internal representation of a parameter value.
        ©ÚNotImplementedError)r   Úparam_value_in_external_reprs     r   Úto_internal_reprz!BaseDistribution.to_internal_repr3   s
   € ô "Ð!r   c                ó   — t         ‚)zàTest whether the range of this distribution contains just a single value.

        Returns:
            :obj:`True` if the range of this distribution contains just a single value,
            otherwise :obj:`False`.
        r   ©r   s    r   ÚsinglezBaseDistribution.singleA   s
   € ô "Ð!r   c                ó   — t         ‚)ag  Test if a parameter value is contained in the range of this distribution.

        Args:
            param_value_in_internal_repr:
                Optuna's internal representation of a parameter value.

        Returns:
            :obj:`True` if the parameter value is contained in the range of this distribution,
            otherwise :obj:`False`.
        r   r   s     r   Ú	_containszBaseDistribution._containsL   s
   € ô "Ð!r   c                ó   — | j                   S ©N)Ú__dict__r   s    r   Ú_asdictzBaseDistribution._asdict[   s   € Ø�}‰}Ðr   c                óŽ   — t        |t        «      st        S t        | «      t        |«      ury| j                  |j                  k(  S )NF)Ú
isinstancer   ÚNotImplementedÚtyper#   )r   Úothers     r   Ú__eq__zBaseDistribution.__eq__^   s9   € Ü˜%Ô!1Ô2Ü!Ð!Ü�‹:œT %›[Ñ(ØØ�}‰} §¡Ñ.Ð.r   c           	     óˆ   — t        | j                  ft        t        | j                  j                  «       «      «      z   «      S r"   )ÚhashÚ	__class__ÚtupleÚsortedr#   Úitemsr   s    r   Ú__hash__zBaseDistribution.__hash__e   s0   € Ü�T—^‘^Ð%¬¬f°T·]±]×5HÑ5HÓ5JÓ.KÓ(LÑLÓMÐMr   c                ó´   — dj                  d„ t        | j                  «       j                  «       «      D «       «      }| j                  j
                  › d|› d�S )Nú, c              3  ó0   K  — | ]  \  }}|› d |› �–— Œ y­w)ú=Nr   )Ú.0ÚkÚvs      r   ú	<genexpr>z,BaseDistribution.__repr__.<locals>.<genexpr>i   s   è ø€ ÒQ©$¨!¨Q˜a˜S  ! œ:ÑQùs   ‚ú(ú))Újoinr/   r$   r0   r-   Ú__name__)r   Úkwargss     r   Ú__repr__zBaseDistribution.__repr__h   sH   € Ø—‘ÑQ´&¸¿¹»×9MÑ9MÓ9OÓ2PÔQÓQˆØ—.‘.×)Ñ)Ð*¨!¨F¨8°1Ð5Ð5r   N)r   ÚfloatÚreturnr   )r   r   rA   r@   ©rA   Úbool©r   r@   rA   rC   ©rA   Údict©r)   r   rA   rC   )rA   Úint)rA   Ústr)r=   Ú
__module__Ú__qualname__Ú__doc__r   ÚabcÚabstractmethodr   r   r    r$   r*   r1   r?   r   r   r   r   r      so   „ ñó,ð 	×Ñò"ó ð"ð 	×Ñò"ó ð"ð 	×Ñò"ó ð"óó/óNô6r   r   c                  óF   — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 dd„Zd	d„Zd
d„Zdd„Zy)ÚFloatDistributionaa  A distribution on floats.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_float`, and passed to
    :mod:`~optuna.samplers` in general.

    .. note::
        When ``step`` is not :obj:`None`, if the range :math:`[\mathsf{low}, \mathsf{high}]`
        is not divisible by :math:`\mathsf{step}`, :math:`\mathsf{high}` will be replaced
        with the maximum of :math:`k \times \mathsf{step} + \mathsf{low} < \mathsf{high}`,
        where :math:`k` is an integer.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be less than or equal to ``high``. If ``log`` is :obj:`True`,
            ``low`` must be larger than 0.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.
        log:
            If ``log`` is :obj:`True`, this distribution is in log-scaled domain.
            In this case, all parameters enqueued to the distribution must be positive values.
            This parameter must be :obj:`False` when the parameter ``step`` is not :obj:`None`.
        step:
            A discretization step. ``step`` must be larger than 0.
            This parameter must be :obj:`None` when the parameter ``log`` is :obj:`True`.

    Nc                óH  — |r|�t        d«      ‚||kD  rt        d|›d|›d�«      ‚|r|dk  rt        d|›d|›d�«      ‚|�|dk  rt        d|›d	�«      ‚d | _        |�t        |||«      }t        |«      | _        t        |«      | _        t        |«      | _        || _        y )
Nz9The parameter `step` is not supported when `log` is true.ú&`low <= high` must hold, but got (low=ú, high=ú).ç        z1`low > 0` must hold for `log=True`, but got (low=r   ú#`step > 0` must hold, but got step=ú.)Ú
ValueErrorÚstepÚ_adjust_discrete_uniform_highr@   ÚlowÚhighÚlog©r   r[   r\   r]   rY   s        r   Ú__init__zFloatDistribution.__init__‹   sÇ   € ñ �4Ð#ÜÐXÓYÐYà�Š:ÜÐFÀ#ÀÀxÈ$ÈÐPRÐSÓTÐTá�3˜#’:ÜÐQÈSÈFÐRZÐUYÐT[Ð[]Ð^Ó_Ð_àÐ ¨¢	ÜÐC¸d¸WÀAÐFÓGÐGàˆŒ	ØÐÜ0°°d¸DÓAˆDÜ˜d›ˆDŒIä˜“:ˆŒÜ˜$“KˆŒ	Øˆ�r   c                ó€  — | j                   €| j                  | j                  k(  S | j                  | j                  k(  ryt        j                  t        | j                  «      «      }t        j                  t        | j                  «      «      }t        j                  t        | j                   «      «      }||z
  |k  S ©NT)rY   r[   r\   ÚdecimalÚDecimalrI   )r   r\   r[   rY   s       r   r   zFloatDistribution.single£   sƒ   € Ø�9‰9ÐØ—8‘8˜tŸy™yÑ(Ð(à�x‰x˜4Ÿ9™9Ò$ØÜ—?‘?¤3 t§y¡y£>Ó2ˆDÜ—/‘/¤# d§h¡h£-Ó0ˆCÜ—?‘?¤3 t§y¡y£>Ó2ˆDØ˜3‘J $Ñ&Ð&r   c                ó  — |}| j                   €$| j                  |cxk  xr | j                  k  S c S || j                  z
  | j                   z  }| j                  |cxk  xr | j                  k  nc xr t        |t	        |«      z
  «      dk  S )Ng:Œ0âŽyE>)rY   r[   r\   ÚabsÚround)r   r   Úvaluer7   s       r   r    zFloatDistribution._contains®   su   € Ø,ˆØ�9‰9ÐØ—8‘8˜uÖ1¨¯	©	Ñ1Ð1Ñ1Ð1à˜Ÿ™Ñ! T§Y¡YÑ.ˆAØ—8‘8˜uÖ1¨¯	©	Ô1ÒP´c¸!¼eÀA»h¹,Ó6GÈ&Ñ6PÐPr   c                óô   — 	 t        |«      }t        j                  |«      rt        d|› d�«      ‚| j
                  r|dk  rt        d|› d�«      ‚|S # t        t        f$ r}t        d|› d�«      |‚d }~ww xY w©Nú'z8' is not a valid type. float-castable value is expected.ú`z` is invalid value.rU   z)` is invalid value for the case log=True.©r@   rX   Ú	TypeErrorÚmathÚisnanr]   ©r   r   Úinternal_reprÚes       r   r   z"FloatDistribution.to_internal_repr¶   ó¥   € ð	Ü!Ð">Ó?ˆMô �:‰:�mÔ$Ü˜qÐ!=Ð >Ð>QÐRÓSÐSØ�8Š8˜¨Ò,ÜØÐ0Ð1Ð1ZÐ[óð ð Ðøô œIÐ&ò 	ÜØÐ0Ð1ð 24ð 4óð ðûð	úó   ‚A ÁA7Á"A2Á2A7)FN)
r[   r@   r\   r@   r]   rC   rY   zNone | floatrA   ÚNonerB   rD   )r   r@   rA   r@   )r=   rJ   rK   rL   r_   r   r    r   r   r   r   rP   rP   m   sK   „ ñð< PTðØðØ %ðØ,0ðØ@Lðà	óó0	'óQôr   rP   z3.0.0z6.0.0)Útextc                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )ÚUniformDistributiona  A uniform distribution in the linear domain.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_float`, and passed to
    :mod:`~optuna.samplers` in general.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be less than or equal to ``high``.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.

    c                ó,   •— t         ‰| �  ||dd ¬«       y ©NF©r[   r\   r]   rY   ©Úsuperr_   ©r   r[   r\   r-   s      €r   r_   zUniformDistribution.__init__Ù   ó   ø€ Ü‰Ñ˜S t°¸TÐÕBr   c                óˆ   — t        j                  | j                  «      }|j                  d«       |j                  d«       |S ©Nr]   rY   ©ÚcopyÚdeepcopyr#   Úpop©r   Úds     r   r$   zUniformDistribution._asdictÜ   ó/   € Ü�M‰M˜$Ÿ-™-Ó(ˆØ	�‰ˆeŒØ	�‰ˆfŒØˆr   ©r[   r@   r\   r@   rA   ru   rE   ©r=   rJ   rK   rL   r_   r$   Ú__classcell__©r-   s   @r   rx   rx   È   s   ø„ ñõC÷r   rx   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )ÚLogUniformDistributionaK  A uniform distribution in the log domain.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_float` with ``log=True``,
    and passed to :mod:`~optuna.samplers` in general.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be larger than 0. ``low`` must be less than or equal to ``high``.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.

    c                ó,   •— t         ‰| �  ||dd ¬«       y ©NTr{   r|   r~   s      €r   r_   zLogUniformDistribution.__init__ô   ó   ø€ Ü‰Ñ˜S t°¸DÐÕAr   c                óˆ   — t        j                  | j                  «      }|j                  d«       |j                  d«       |S r�   r‚   r†   s     r   r$   zLogUniformDistribution._asdict÷   rˆ   r   r‰   rE   rŠ   rŒ   s   @r   rŽ   rŽ   ã   s   ø„ ñõB÷r   rŽ   c                  ód   ‡ — e Zd ZdZdˆ fd„Zdd„Zedd„«       Zej                  d	d„«       Zˆ xZ	S )
ÚDiscreteUniformDistributionao  A discretized uniform distribution in the linear domain.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_float` with ``step``
    argument, and passed to :mod:`~optuna.samplers` in general.

    .. note::
        If the range :math:`[\mathsf{low}, \mathsf{high}]` is not divisible by :math:`q`,
        :math:`\mathsf{high}` will be replaced with the maximum of :math:`k q + \mathsf{low}
        < \mathsf{high}`, where :math:`k` is an integer.

    Args:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be less than or equal to ``high``.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.
        q:
            A discretization step. ``q`` must be larger than 0.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.

    c                ó*   •— t         ‰| �  |||¬«       y )N©r[   r\   rY   r|   )r   r[   r\   Úqr-   s       €r   r_   z$DiscreteUniformDistribution.__init__  s   ø€ Ü‰Ñ˜S t°!ÐÕ4r   c                ó’   — t        j                  | j                  «      }|j                  d«       |j                  d«      }||d<   |S )Nr]   rY   r—   r‚   )r   r‡   rY   s      r   r$   z#DiscreteUniformDistribution._asdict  s:   € Ü�M‰M˜$Ÿ-™-Ó(ˆØ	�‰ˆeŒà�u‰u�V‹}ˆØˆˆ#‰Øˆr   c                ó.   — t        d| j                  «      S )zèDiscretization step.

        :class:`~optuna.distributions.DiscreteUniformDistribution` is a subtype of
        :class:`~optuna.distributions.FloatDistribution`.
        This property is a proxy for its ``step`` attribute.
        r@   )r   rY   r   s    r   r—   zDiscreteUniformDistribution.q'  s   € ô �G˜TŸY™YÓ'Ð'r   c                ó   — || _         y r"   )rY   )r   r8   s     r   r—   zDiscreteUniformDistribution.q1  s	   € àˆ�	r   )r[   r@   r\   r@   r—   r@   rA   ru   rE   )rA   r@   )r8   r@   rA   ru   )
r=   rJ   rK   rL   r_   r$   Úpropertyr—   Úsetterr‹   rŒ   s   @r   r”   r”   þ   s>   ø„ ñõ85óð ò(ó ð(ð ‡X�Xòó ôr   r”   c                  ó:   — e Zd ZdZdd	d„Zd
d„Zdd„Zdd„Zdd„Zy)ÚIntDistributiona^  A distribution on integers.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_int`, and passed to
    :mod:`~optuna.samplers` in general.

    .. note::
        When ``step`` is not :obj:`None`, if the range :math:`[\mathsf{low}, \mathsf{high}]`
        is not divisible by :math:`\mathsf{step}`, :math:`\mathsf{high}` will be replaced
        with the maximum of :math:`k \times \mathsf{step} + \mathsf{low} < \mathsf{high}`,
        where :math:`k` is an integer.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be less than or equal to ``high``. If ``log`` is :obj:`True`,
            ``low`` must be larger than or equal to 1.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.
        log:
            If ``log`` is :obj:`True`, this distribution is in log-scaled domain.
            In this case, all parameters enqueued to the distribution must be positive values.
            This parameter must be :obj:`False` when the parameter ``step`` is not 1.
        step:
            A discretization step. ``step`` must be a positive integer. This parameter must be 1
            when the parameter ``log`` is :obj:`True`.

    c                ó`  — |r|dk7  rt        d«      ‚||kD  rt        d|›d|›d�«      ‚|r|dk  rt        d|›d|›d�«      ‚|dk  rt        d|›d	�«      ‚|| _        t        |«      | _        t        |«      | _        t        |«      }t        | j                  || j                  «      | _        y )
Né   zZSamplers and other components in Optuna only accept step is 1 when `log` argument is True.rR   rS   rT   z2`low >= 1` must hold for `log=True`, but got (low=r   rV   rW   )rX   r]   rH   rY   r[   Ú_adjust_int_uniform_highr\   r^   s        r   r_   zIntDistribution.__init__T  sÄ   € Ù�4˜1’9Üð/óð ð
 �Š:ÜÐFÀ#ÀÀxÈ$ÈÐPRÐSÓTÐTá�3˜’7ÜÐRÈcÈVÐS[ÐVZÐU\Ð\^Ð_Ó`Ð`à�1Š9ÜÐC¸d¸WÀAÐFÓGÐGàˆŒÜ˜“IˆŒ	Ü�s“8ˆŒÜ�4‹yˆÜ,¨T¯X©X°t¸T¿Y¹YÓGˆ�	r   c                ó   — t        |«      S r"   )rH   r   s     r   r   z IntDistribution.to_external_reprj  s   € ÜÐ/Ó0Ð0r   c                óô   — 	 t        |«      }t        j                  |«      rt        d|› d�«      ‚| j
                  r|dk  rt        d|› d�«      ‚|S # t        t        f$ r}t        d|› d�«      |‚d }~ww xY wri   rl   rp   s       r   r   z IntDistribution.to_internal_reprm  rs   rt   c                óÌ   — | j                   r| j                  | j                  k(  S | j                  | j                  k(  ry| j                  | j                  z
  | j                  k  S ra   )r]   r[   r\   rY   r   s    r   r   zIntDistribution.single~  sK   € Ø�8Š8Ø—8‘8˜tŸy™yÑ(Ð(à�8‰8�t—y‘yÒ ØØ—	‘	˜DŸH™HÑ$¨¯	©	Ñ1Ð1r   c                ó�   — |}| j                   |cxk  xr | j                  k  nc xr || j                   z
  | j                  z  dk(  S ©Nr   r–   )r   r   rg   s      r   r    zIntDistribution._contains†  s<   € Ø,ˆØ�x‰x˜5Ö- D§I¡IÔ-ÒU°5¸4¿8¹8Ñ3CÀtÇyÁyÑ2PÐTUÑ2UÐUr   N)Fr    )
r[   rH   r\   rH   r]   rC   rY   rH   rA   ru   )r   r@   rA   rH   )r   rH   rA   r@   rB   rD   )	r=   rJ   rK   rL   r_   r   r   r   r    r   r   r   rž   rž   6  s"   „ ñô:Hó,1óó"2ôVr   rž   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )ÚIntUniformDistributionaŽ  A uniform distribution on integers.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_int`, and passed to
    :mod:`~optuna.samplers` in general.

    .. note::
        If the range :math:`[\mathsf{low}, \mathsf{high}]` is not divisible by
        :math:`\mathsf{step}`, :math:`\mathsf{high}` will be replaced with the maximum of
        :math:`k \times \mathsf{step} + \mathsf{low} < \mathsf{high}`, where :math:`k` is
        an integer.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range.
            ``low`` must be less than or equal to ``high``.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.
        step:
            A discretization step. ``step`` must be a positive integer.

    c                ó,   •— t         ‰| �  ||d|¬«       y rz   r|   ©r   r[   r\   rY   r-   s       €r   r_   zIntUniformDistribution.__init__¤  r   r   c                óf   — t        j                  | j                  «      }|j                  d«       |S ©Nr]   r‚   r†   s     r   r$   zIntUniformDistribution._asdict§  ó$   € Ü�M‰M˜$Ÿ-™-Ó(ˆØ	�‰ˆeŒØˆr   ©r    ©r[   rH   r\   rH   rY   rH   rA   ru   rE   rŠ   rŒ   s   @r   r¨   r¨   ‹  s   ø„ ñö.C÷r   r¨   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )ÚIntLogUniformDistributiona   A uniform distribution on integers in the log domain.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_int`, and passed to
    :mod:`~optuna.samplers` in general.

    Attributes:
        low:
            Lower endpoint of the range of the distribution. ``low`` is included in the range
            and must be larger than or equal to 1. ``low`` must be less than or equal to ``high``.
        high:
            Upper endpoint of the range of the distribution. ``high`` is included in the range.
            ``high`` must be greater than or equal to ``low``.
        step:
            A discretization step. ``step`` must be a positive integer.

    c                ó,   •— t         ‰| �  ||d|¬«       y r�   r|   rª   s       €r   r_   z"IntLogUniformDistribution.__init__À  r‘   r   c                óf   — t        j                  | j                  «      }|j                  d«       |S r¬   r‚   r†   s     r   r$   z!IntLogUniformDistribution._asdictÃ  r­   r   r®   r¯   rE   rŠ   rŒ   s   @r   r±   r±   ­  s   ø„ ñö"B÷r   r±   c                óÜ   — t        | t        «      xr t        j                  t	        | «      «      }t        |t        «      xr t        j                  t	        |«      «      }| |k(  xs |xr |S )z‡A function to check two choices equal considering NaN.

    This function can handle NaNs like np.float32("nan") other than float.
    )r&   r   rn   ro   r@   )Úvalue1Úvalue2Úvalue1_is_nanÚvalue2_is_nans       r   Ú_categorical_choice_equalr¹   É  sU   € ô ˜v¤tÓ,ÒJ´·±¼EÀ&»MÓ1J€MÜ˜v¤tÓ,ÒJ´·±¼EÀ&»MÓ1J€MØ�fÑÒB -Ò"A°MÐBr   c                  óX   — e Zd ZdZd	d„Zd
d„Zdd„Zdd„Zdd„Zdd„Z	e
j                  Zy)ÚCategoricalDistributionaT  A categorical distribution.

    This object is instantiated by :func:`~optuna.trial.Trial.suggest_categorical`, and
    passed to :mod:`~optuna.samplers` in general.

    Args:
        choices:
            Parameter value candidates. ``choices`` must have one element at least.

    .. note::

        Not all types are guaranteed to be compatible with all storages. It is recommended to
        restrict the types of the choices to :obj:`None`, :class:`bool`, :class:`int`,
        :class:`float` and :class:`str`.

    Attributes:
        choices:
            Parameter value candidates.

    c                óú   — t        |«      dk(  rt        d«      ‚|D ]M  }|€Œt        |t        t        t
        t        f«      rŒ'd|› dt        |«      j                  › d�}t        |«       ŒO t        |«      | _        y )Nr   z0The `choices` must contain one or more elements.zChoices for a categorical distribution should be a tuple of None, bool, int, float and str for persistent storage but contains z which is of type rW   )ÚlenrX   r&   rC   rH   r@   rI   r(   r=   r   r.   Úchoices)r   r¾   ÚchoiceÚmessages       r   r_   z CategoricalDistribution.__init__ì  sƒ   € Üˆw‹<˜1ÒÜÐOÓPÐPØò 	%ˆFØÑ!¬*°V¼dÄCÌÔPSÐ=TÕ*UðIà�hÐ0´°f³×1FÑ1FÐ0GÀqðJð ô
 ˜GÕ$ð	%ô ˜W“~ˆ�r   c                ó2   — | j                   t        |«         S r"   )r¾   rH   r   s     r   r   z(CategoricalDistribution.to_external_reprú  s   € Ø�|‰|œCÐ <Ó=Ñ>Ð>r   c                óî   — 	 | j                   j                  |«      S # t        $ r2 t        | j                   «      D ]  \  }}t	        ||«      sŒ|c cY S  Y nw xY wt        d|› d| j                   › d�«      ‚)Nrj   z	' not in rW   )r¾   ÚindexrX   Ú	enumerater¹   )r   r   rÃ   r¿   s       r   r   z(CategoricalDistribution.to_internal_reprý  s}   € ð
	!ð
 —<‘<×%Ñ%Ð&BÓCÐCøÜò 	!ä!*¨4¯<©<Ó!8ò !‘��vÜ,Ð-IÈ6ÕRØ ”Lò!ð	!úô ˜1Ð9Ð:¸)ÀDÇLÁLÀ>ÐQRÐSÓTÐTs   ‚ �0AÁAÁAÁAc                ó2   — t        | j                  «      dk(  S )Nr    )r½   r¾   r   s    r   r   zCategoricalDistribution.single  s   € Ü�4—<‘<Ó  AÑ%Ð%r   c                ó^   — t        |«      }d|cxk  xr t        | j                  «      k  S c S r¦   )rH   r½   r¾   )r   r   rÃ   s      r   r    z!CategoricalDistribution._contains  s,   € ÜÐ0Ó1ˆØ�EÖ-œC §¡Ó-Ñ-Ð-Ñ-Ð-r   c                óÜ  — t        |t        «      st        S t        || j                  «      sy| j                  j                  «       |j                  j                  «       k7  ry| j                  j                  «       D ]l  \  }}|dk(  rQt        |«      t        t        ||«      «      k7  r yt        |t        ||«      «      D ]  \  }}t        ||«      rŒ  y Œ\|t        ||«      k7  sŒl y y)NFr¾   T)r&   r   r'   r-   r#   Úkeysr0   r½   ÚgetattrÚzipr¹   )r   r)   Úkeyrg   r¿   Úother_choices         r   r*   zCategoricalDistribution.__eq__  sÔ   € Ü˜%Ô!1Ô2Ü!Ð!Ü˜% §¡Ô0ØØ�=‰=×ÑÓ 5§>¡>×#6Ñ#6Ó#8Ò8ØØŸ-™-×-Ñ-Ó/ò 		!‰JˆC�Ø�iÒÜ�u“:¤¤W¨U°CÓ%8Ó!9Ò9Ù Ü,/°´w¸uÀcÓ7JÓ,Kò %Ñ(�F˜LÜ4°V¸\ÕJÚ$ñ%ð œG E¨3Ó/Ó/Ù ð		!ð r   N)r¾   zSequence[CategoricalChoiceType]rA   ru   )r   r@   rA   ÚCategoricalChoiceType)r   rÍ   rA   r@   rB   rD   rG   )r=   rJ   rK   rL   r_   r   r   r   r    r*   r   r1   r   r   r   r»   r»   Ö  s3   „ ñó*&ó?óUó&ó.óð&  ×(Ñ(�Hr   r»   c                ó  — t        j                  | «      }d|v rh|d   t        j                  k(  rt	        |d   d   «      |d   d<   t
        D ]!  }|d   |j                  k(  sŒ |di |d   ¤Žc S  t        d|d   › �«      ‚|d   dk(  rt        |d   «      S |d   dv rW|d   }|d	   }|j                  d
«      }|j                  dd«      }|d   dk(  rt        ||||¬«      S |€d}t        ||||¬«      S t        d|d   › �«      ‚)z Deserialize a distribution in JSON format.

    Args:
        json_str: A JSON-serialized distribution.

    Returns:
        A deserialized distribution.

    ÚnameÚ
attributesr¾   zUnknown distribution class: r(   Úcategorical)r@   rH   r[   r\   rY   r]   Fr@   )r]   rY   r    r{   zUnknown distribution type: r   )
ÚjsonÚloadsr»   r=   r.   ÚDISTRIBUTION_CLASSESrX   ÚgetrP   rž   )Újson_strÚ	json_dictÚclsr[   r\   rY   r]   s          r   Újson_to_distributionrÙ   5  sM  € ô —
‘
˜8Ó$€Ià�ÑØ�VÑÔ 7× @Ñ @Ò@Ü16°yÀÑ7NÈyÑ7YÓ1ZˆI�lÑ# IÑ.ä'ò 	6ˆCØ˜Ñ  C§L¡LÓ0ÙÑ5˜Y |Ñ4Ñ5Ò5ð	6ô Ð7¸	À&Ñ8IÐ7JÐKÓLÐLð �VÑ Ò-Ü*¨9°YÑ+?Ó@Ð@Ø�vÑÐ"2Ñ2Ø˜EÑ"ˆCØ˜VÑ$ˆDØ—=‘= Ó(ˆDØ—-‘-  uÓ-ˆCà˜Ñ  GÒ+Ü(¨¨d¸À$ÔGÐGð �<Ø�DÜ&¨3°T¸sÈÔNÐNäÐ6°yÀÑ7HÐ6IÐJÓKÐKr   c                óv   — t        j                  | j                  j                  | j	                  «       dœ«      S )z¥Serialize a distribution to JSON format.

    Args:
        dist: A distribution to be serialized.

    Returns:
        A JSON string of a given distribution.

    )rÏ   rÐ   )rÒ   Údumpsr-   r=   r$   )Údists    r   Údistribution_to_jsonrÝ   a  s(   € ô �:‰:˜tŸ~™~×6Ñ6ÀdÇlÁlÃnÑUÓVÐVr   c                óv  — | j                   |j                   k7  rt        d«      ‚t        | t        t        f«      r<t        |t        t        f«      sJ ‚| j
                  |j
                  k7  rt        d«      ‚t        | t        «      syt        |t        «      sy| |k7  rt        t        j                  dz   «      ‚y)a!  A function to check compatibility of two distributions.

    It checks whether ``dist_old`` and ``dist_new`` are the same kind of distributions.
    If ``dist_old`` is :class:`~optuna.distributions.CategoricalDistribution`,
    it further checks ``choices`` are the same between ``dist_old`` and ``dist_new``.
    Note that this method is not supposed to be called by library users.

    Args:
        dist_old:
            A distribution previously recorded in storage.
        dist_new:
            A distribution newly added to storage.

    zBCannot set different distribution kind to the same parameter name.zBCannot set different log configuration to the same parameter name.Nz& does not support dynamic value space.)r-   rX   r&   rP   rž   r]   r»   r=   )Údist_oldÚdist_news     r   Ú check_distribution_compatibilityrá   o  s«   € ð$ ×Ñ˜X×/Ñ/Ò/ÜÐ]Ó^Ð^ä�(Ô.´Ð@ÔAä˜(Ô%6¼Ð$HÔIÐIÐIà�<‰<˜8Ÿ<™<Ò'ÜÐaÓbÐbä�hÔ 7Ô8ØÜ�hÔ 7Ô8ØØ�8ÒÜÜ#×,Ñ,Ð/WÑWó
ð 	
ð r   c                ó\  — t        j                  t        |«      «      }t        j                  t        | «      «      }t        j                  t        |«      «      }||z
  }||z  t        j                  d«      k7  r1|}t        ||z  |z  |z   «      }t	        d| › d|› d|›d| › d|› d�«       |S )NÚ0ú"The distribution is specified by [r3   ú] and step=úF, but the range is not divisible by `step`. It will be replaced with [ú].)rb   rc   rI   r@   r   )r[   r\   rY   Úd_highÚd_lowÚd_stepÚd_rÚold_highs           r   rZ   rZ   •  s¯   € Ü�_‰_œS ›YÓ'€FÜ�O‰OœC ›HÓ%€EÜ�_‰_œS ›YÓ'€Fà
�5‰.€Cà
ˆV�|”w—‘ sÓ+Ò+ØˆÜ�c˜V‘m vÑ-°Ñ5Ó6ˆÜØ0°°°R¸°zÀÈÀwð OBØBEÀÀbÈÈÈbðRô	
ð
 €Kr   c                óp   — || z
  }||z  dk7  r(|}||z  |z  | z   }t        d| › d|› d|›d| › d|› d�«       |S )Nr   rä   r3   rå   ræ   rç   r
   )r[   r\   rY   Úrrì   s        r   r¡   r¡   §  sj   € Øˆs‰
€AØˆ4�x�1‚}ØˆØ�D‰y˜4Ñ #Ñ%ˆÜØ0°°°R¸°zÀÈÀwð OBØBEÀÀbÈÈÈbðRô	
ð €Kr   c                ó¬   — | j                  «       sJ ‚t        | t        t        f«      r| j                  S t        | t
        «      r| j                  d   S J ‚r¦   )r   r&   rP   rž   r[   r»   r¾   )Údistributions    r   Ú_get_single_valuerñ   ³  sY   € Ø×ÑÔ Ð Ð äØäÜð	
ôð ×ÑÐÜ	�LÔ"9Ô	:Ø×#Ñ# AÑ&Ð&Øˆ5r   c                óŒ  — t        | t        «      r$t        | j                  | j                  dd ¬«      }nðt        | t
        «      r$t        | j                  | j                  dd ¬«      }n¼t        | t        «      r.t        | j                  | j                  d| j                  ¬«      }n~t        | t        «      r.t        | j                  | j                  d| j                  ¬«      }n@t        | t        «      r.t        | j                  | j                  d| j                  ¬«      }n| }|| k7  r|s| › d|› d�}t        |t        «       |S )NFr{   Tz+ is deprecated and internally converted to z3. See https://github.com/optuna/optuna/issues/2941.)r&   rx   rP   r[   r\   rŽ   r”   r—   r¨   rž   rY   r±   r   ÚFutureWarning)rð   Úsuppress_warningÚnew_distributionrÀ   s       r   Ú-_convert_old_distribution_to_new_distributionrö   Å  sE  € ô �,Ô 3Ô4Ü,Ø× Ñ Ø×"Ñ"ØØô	
Ñô 
�LÔ"8Ô	9Ü,Ø× Ñ Ø×"Ñ"ØØô	
Ñô 
�LÔ"=Ô	>Ü,Ø× Ñ Ø×"Ñ"ØØ—‘ô	
Ñô 
�LÔ"8Ô	9Ü*Ø× Ñ Ø×"Ñ"ØØ×"Ñ"ô	
Ñô 
�LÔ";Ô	<Ü*Ø× Ñ Ø×"Ñ"ØØ×"Ñ"ô	
Ñð (Ðà˜<Ò'Ñ0@àˆnð Ø Ð!Ð!TðVð 	ô 	�Gœ]Ô+àÐr   )rµ   rÍ   r¶   rÍ   rA   rC   )rÖ   rI   rA   r   )rÜ   r   rA   rI   )rß   r   rà   r   rA   ru   )r[   r@   r\   r@   rY   r@   rA   r@   )r[   rH   r\   rH   rY   rH   rA   rH   )rð   r   rA   z#int | float | CategoricalChoiceType)F)rð   r   rô   rC   rA   r   ).Ú
__future__r   rM   rƒ   rb   rÒ   rn   Únumbersr   Útypingr   r   r   r   Úoptuna._deprecatedr	   Úoptuna._warningsr   Úcollections.abcr   rC   rH   r@   rI   rÍ   Ú"_float_distribution_deprecated_msgÚ _int_distribution_deprecated_msgÚABCr   rP   rx   rŽ   r”   rž   r¨   r±   r¹   r»   rÔ   rÙ   rÝ   rá   rZ   r¡   rñ   rö   r   r   r   ú<module>r      s	  ðÝ "ã 
Û Û Û Û Ý Ý Ý Ý  Ý å /Ý (ñ Ý(ð ˜d D¨#¨u°cÐ9Ñ:Ð ð Dð #ð $aÐ  ôK6�s—w‘wô K6ô\XÐ(ô Xñv �'˜7Ð)KÔLôÐ+ó ó Mðñ4 �'˜7Ð)KÔLôÐ.ó ó Mðñ4 �'˜7Ð)KÔLô4Ð"3ó 4ó Mð4ônRVÐ&ô RVñj �'˜7Ð)IÔJô˜_ó ó KðñB �'˜7Ð)IÔJô ó ó Kðð6
CØ!ð
CØ+@ð
Cà	ó
CôP)Ð.ô P)ðh ØØØØØØØð	Ð ó)LóXWð#
Øð#
Ø*:ð#
à	ó#
óLó$	óð( #ð8Ø"ð8àð8ð ô8r   