Ë
   µNtVH¨ÿ÷ã                   ó  — d dl Zd dlmc mZ d dlmZ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mZmZmZ d d	lmZ d d
lmZ  ed«      Zerd dlmZ  G d„ de
«      Z dedede fd„Z! G d„ d«      Z" G d„ d«      Z#y)é    N)ÚCallableÚIterator)ÚEnum)ÚRandom)ÚTYPE_CHECKING)Ú
SortedList)Úchoices_key)ÚConjectureDataÚConjectureResultÚStatusÚ_Overrun)ÚLazySequenceCopy)Úsort_keyz-inf)ÚConjectureRunnerc                   ó   — e Zd ZdZdZdZdZy)ÚDominanceRelationr   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚNO_DOMINANCEÚEQUALÚLEFT_DOMINATESÚRIGHT_DOMINATES© ó    új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/hypothesis/internal/conjecture/pareto.pyr   r   "   s   „ Ø€LØ€EØ€NØ�Or   r   ÚleftÚrightÚreturnc                 ó  — t        | j                  «      }t        |j                  «      }||k(  rt        j                  S ||k  �r/t	        || ¬«      }|t        j
                  k(  rt        j                  S t        j                  }||k(  }|sât        j                  d|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      nddt        j                  «       v st        j                  t        «      rt        j                  t        «      ndt        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚d	x}}|S ||k  }|sÆt        j                  d
|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      nddt        j                  «       v st        j                  |«      rt        j                  |«      nddœz  }	dd|	iz  }t        t        j                  |«      «      ‚d	}| j                   |j                   k  rt        j                  S |j"                  j%                  | j"                  «      st        j                  S | j                   t&        j(                  k(  r5|j*                  �)| j*                  |j*                  k7  rt        j                  S t-        | j.                  «      t-        |j.                  «      z  D ]Y  }
| j.                  j1                  |
t2        «      }|j.                  j1                  |
t2        «      }||kD  sŒIt        j                  c S  t        j
                  S )aa  Returns the dominance relation between ``left`` and ``right``, according
    to the rules that one ConjectureResult dominates another if and only if it
    is better in every way.

    The things we currently consider to be "better" are:

        * Something that is smaller in shrinking order is better.
        * Something that has higher status is better.
        * Each ``interesting_origin`` is treated as its own score, so if two
          interesting test cases have different origins then neither dominates
          the other.
        * For each target observation, a higher score is better.

    In "normal" operation where there are no bugs or target observations, the
    pareto front only has one element (the smallest valid test case), but for
    more structured or failing tests it can be useful to track, and future work
    will depend on it more.)r    r!   )ú==)z4%(py0)s == %(py4)s
{%(py4)s = %(py2)s.NO_DOMINANCE
}Úresultr   ©Úpy0Úpy2Úpy4úassert %(py6)sÚpy6N)ú<)z%(py0)s < %(py2)sÚleft_keyÚ	right_key©r'   r(   úassert %(py4)sr)   )r   Únodesr   r   Ú	dominancer   r   r   Ú
@pytest_arÚ_call_reprcompareÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚ	_safereprÚAssertionErrorÚ_format_explanationÚstatusÚtagsÚissubsetr   ÚINTERESTINGÚinteresting_originÚsetÚtarget_observationsÚgetÚNO_SCORE)r    r!   r-   r.   r%   Ú@py_assert3Ú@py_assert1Ú@py_format5Ú@py_format7Ú@py_format3ÚtargetÚ
left_scoreÚright_scores                r   r2   r2   )   sS  € ô& ˜Ÿ
™
Ó#€HÜ˜Ÿ™Ó%€IØ�9ÒÜ ×&Ñ&Ð&à�8ÓÜ ¨TÔ2ˆØÔ&×5Ñ5Ò5Ü$×4Ñ4Ð4ô
 /×;Ñ;Ð;�6Ð;Ñ;×;×;Õ;�6Ð;×;×;×;×;×;Ñ;�6×;×;Ó;�6×;×;×;×;×;Ò;Ô.×;×;Ó;Ô.×;×;Ô;Ð;×;×;×;×;×;×;Ñ;ØˆMð �iÑ××Õˆ8�i×××××Ñˆ8××Óˆ8×××××Ò�i××Ó�i××××××Ñð ‡{�{�U—\‘\Ò!Ü ×-Ñ-Ð-à�:‰:×Ñ˜tŸy™yÔ)Ü ×-Ñ-Ð-ð
 	�‰”v×)Ñ)Ò)Ø×$Ñ$Ð0Ø×#Ñ# u×'?Ñ'?Ò?ä ×-Ñ-Ð-ä�d×.Ñ.Ó/´#°e×6OÑ6OÓ2PÑPò 2ˆØ×-Ñ-×1Ñ1°&¼(ÓCˆ
Ø×/Ñ/×3Ñ3°F¼HÓEˆØ˜Ó#Ü$×1Ñ1Ò1ð	2ô ×+Ñ+Ð+r   c                   ó¦   — e Zd ZdZdeddfd„Zdeez  ez  de	fd„Z
deegdf   ddfd	„Zdede	fd
„Zdee   fd„Zdedefd„Zdefd„Zdeddfd„Zy)ÚParetoFrontaV  Maintains an approximate pareto front of ConjectureData objects. That
    is, we try to maintain a collection of objects such that no element of the
    collection is pareto dominated by any other. In practice we don't quite
    manage that, because doing so is computationally very expensive. Instead
    we maintain a random sample of data objects that are "rarely" dominated by
    any other element of the collection (roughly, no more than about 10%).

    Only valid test cases are considered to belong to the pareto front - any
    test case with a status less than valid is discarded.

    Note that the pareto front is potentially quite large, and currently this
    will store the entire front in memory. This is bounded by the number of
    valid test cases we run, which is max_examples in normal execution, and
    currently we do not support workflows with large max_examples which have
    large values of max_examples very well anyway, so this isn't a major issue.
    In future we may weish to implement some sort of paging out to disk so that
    we can work with larger fronts.

    Additionally, because this is only an approximate pareto front, there are
    scenarios where it can be much larger than the actual pareto front. There
    isn't a huge amount we can do about this - checking an exact pareto front
    is intrinsically quadratic.

    "Most" of the time we should be relatively close to the true pareto front,
    say within an order of magnitude, but it's not hard to construct scenarios
    where this is not the case. e.g. suppose we enumerate all valid test cases
    in increasing shortlex order as s_1, ..., s_n, ... and have scores f and
    g such that f(s_i) = min(i, N) and g(s_i) = 1 if i >= N, then the pareto
    front is the set {s_1, ..., S_N}, but the only element of the front that
    will dominate s_i when i > N is S_N, which we select with probability
    1 / N. A better data structure could solve this, but at the cost of more
    expensive operations and higher per element memory use, so we'll wait to
    see how much of a problem this is in practice before we try that.
    Úrandomr"   Nc                 óR   — || _         g | _        t        d„ ¬«      | _        d | _        y )Nc                 ó,   — t        | j                  «      S ©N)r   r1   )Úds    r   ú<lambda>z&ParetoFront.__init__.<locals>.<lambda>‘   s   € œ( 1§7¡7Ó+€ r   )Úkey)Ú_ParetoFront__randomÚ _ParetoFront__eviction_listenersr   ÚfrontÚ_ParetoFront__pending)ÚselfrN   s     r   Ú__init__zParetoFront.__init__Œ   s)   € ØˆŒØNPˆÔ!ä3=Ù+ô4
ˆŒ
ð 37ˆ�r   Údatac                 ó¼  — |j                   t        j                  k  ryt        |t        «      }| }|�sddt        j                  «       v st        j                  t        «      rt        j                  t        «      nddt        j                  «       v st        j                  |«      rt        j                  |«      nddt        j                  «       v st        j                  t        «      rt        j                  t        «      ndt        j                  |«      dœz  }t        t        j                  |«      «      ‚dx}}|j                  «       }t        |t        «      }| }|�sddt        j                  «       v st        j                  t        «      rt        j                  t        «      nddt        j                  «       v st        j                  |«      rt        j                  |«      nddt        j                  «       v st        j                  t        «      rt        j                  t        «      ndt        j                  |«      dœz  }t        t        j                  |«      «      ‚dx}}| j                  s| j                  j                  |«       y|| j                  v ry| j                  j                  |«       | j                  }d}||u }|s­t        j                   d	|fd
||f«      dt        j                  «       v st        j                  | «      rt        j                  | «      ndt        j                  |«      t        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚dx}x}}	 || _        t#        | j                  «      }g }	| j                  j%                  |«      }
d}|
dz   t'        |«      k  �rŒ|dk  �r†| j(                  j+                  |
dz   t'        |«      «      }|j-                  |«      }t/        ||«      }t0        j2                  }||k7  }|sât        j                   d|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      nddt        j                  «       v st        j                  t0        «      rt        j                  t0        «      ndt        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚dx}}|t0        j4                  k(  r|	j7                  |«       d}n|dz  }|
dz   t'        |«      k  r|dk  r�Œ†|g}|
dk\  �r0t'        |«      dk  �r!|j9                  |
| j(                  j;                  d|
«      «       ||
   }d}d}|t'        |«      k  r³||   }t/        ||«      }|t0        j4                  k(  rB|sd}|||<   |dz  }n!|d   ||   c||<   |d<   |j-                  «        |	j7                  |«       n>|t0        j2                  k(  r|	j7                  |«       n9|t0        j<                  k(  rn%|dz  }|t'        |«      k  rŒ³|j7                  |«       |
dz  }
|
dk\  rt'        |«      dk  r�Œ!|	D ]  }| j?                  |«       Œ || j                  v d| _        S # d| _        w xY w)z¯Attempts to add ``data`` to the pareto front. Returns True if
        ``data`` is now in the front, including if data is already in the
        collection, and False otherwiseFz9assert not %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}Ú
isinstancer[   r   )r'   Úpy1r(   r)   NT)Úis)z1%(py2)s
{%(py2)s = %(py0)s.__pending
} is %(py5)srY   )r'   r(   Úpy5zassert %(py7)sÚpy7r   r   é
   )ú!=)z7%(py0)s != %(py4)s
{%(py4)s = %(py2)s.RIGHT_DOMINATES
}Údomr   r&   r*   r+   éÿÿÿÿ) r;   r   ÚVALIDr]   r   r5   r6   r3   r7   r8   r9   r:   Ú	as_resultrW   ÚaddrX   r4   r   ÚindexÚlenrU   Ú	randrangeÚpopr2   r   r   r   ÚappendÚswapÚrandintr   Ú_remove)rY   r[   rD   Ú@py_assert5Ú@py_format6rE   Ú@py_assert4Ú@py_format8rW   Ú	to_removeÚiÚfailuresÚjÚ	candidaterd   rF   rG   Ú
dominatorsÚalready_replacedÚvs                       r   rh   zParetoFront.add•   sÄ  € ð �;‰;œŸ™Ò%Øä˜d¤HÓ-Ð-Ð-Ð-Ð-Ò-×-×-×-×-Õ-”:×-×-Ó-”:×-×-×-×-×-Ò-˜d×-×-Ó-˜d×-×-×-×-×-Ò-¤H×-×-Ó-¤H×-×-Ô-Ð-×-×-×-×-×-Ò-Ø�~‰~ÓˆÜ˜d¤HÓ-Ð-Ð-Ð-Ð-Ò-×-×-×-×-Õ-”:×-×-Ó-”:×-×-×-×-×-Ò-˜d×-×-Ó-˜d×-×-×-×-×-Ò-¤H×-×-Ó-¤H×-×-Ô-Ð-×-×-×-×-×-Ò-à�zŠzØ�J‰J�N‰N˜4Ô Øà�4—:‘:ÑØð 	�
‰
�‰�tÔØ�~‰~Ð% Ð%ˆ~ Ð%×%×%Õ%ˆ~ ×%×%×%×%×%Ñ%ˆt×%×%Ó%ˆt×%×%Ô%ˆ~×%×%Ò% ×%×%×%×%×%×%Ó%ðR	"Ø!ˆDŒNô % T§Z¡ZÓ0ˆEð
 13ˆIð —
‘
× Ñ  Ó&ˆAð ˆHØ�a‘%œ#˜e›*Ó$¨°B«Ø—M‘M×+Ñ+¨A°©E´3°u³:Ó>�Ø!ŸI™I a›L�	Ü  iÓ0�Ü/×?Ñ?Ð?�sÐ?Ñ?×?×?Õ?�sÐ?×?×?×?×?×?Ñ?�s×?×?Ó?�s×?×?×?×?×?Ò?Ô/×?×?Ó?Ô/×?×?Ô?Ð?×?×?×?×?×?×?Ñ?ØÔ+×:Ñ:Ò:Ø×$Ñ$ YÔ/Ø ‘Hà ‘M�Hð �a‘%œ#˜e›*Ò$¨°B¬ð  ˜ˆJà�q“&œS ›_¨rÓ1Ø—
‘
˜1˜dŸm™m×3Ñ3°A°qÓ9Ô:à! !™H�	à#(Ð Ø�Øœ#˜j›/Ò)Ø" 1™�Aä# I¨qÓ1�CØÔ/×>Ñ>Ò>Ù/Ø/3Ð,Ø,5˜J q™MØ ™F™Að !+¨2¡Ø *¨1¡ð :˜J q™M¨:°b©>ð 'ŸN™NÔ,Ø!×(Ñ(¨Õ+ØÔ 1× AÑ AÒAØ!×(Ñ(¨Ô3ØØÔ 1× 7Ñ 7Ò7Øà˜Q™˜ð- œ#˜j›/Ó)ð0 ×%Ñ% iÔ0Ø�Q‘�ðA �q’&œS ›_¨rÔ1ðD ò  �Ø—‘˜Q•ð à˜4Ÿ:™:Ð%à!ˆD�Nø˜TˆD�Nús    ÎG[ Õ,D[ Ù:)[ Ú%%[ Û	[Úfc                 ó:   — | j                   j                  |«       y)z‹Register a listener function that will be called with data when it
        gets removed from the front because something else dominates it.N)rV   rm   )rY   r}   s     r   Úon_evictzParetoFront.on_evict  s   € ð 	×!Ñ!×(Ñ(¨Õ+r   c                 óŽ   — t        |t        t        f«      sy|j                  «       }t        |t        «      ry|| j
                  v S )NF)r]   r
   r   rg   r   rW   )rY   r[   r%   s      r   Ú__contains__zParetoFront.__contains__  s=   € Ü˜$¤Ô1AÐ BÔCØà—‘Ó!ˆÜ�fœhÔ'Øà˜Ÿ™Ð#Ð#r   c                 ó,   — t        | j                  «      S rQ   )ÚiterrW   ©rY   s    r   Ú__iter__zParetoFront.__iter__  s   € Ü�D—J‘JÓÐr   rv   c                 ó    — | j                   |   S rQ   )rW   )rY   rv   s     r   Ú__getitem__zParetoFront.__getitem__  s   € Ø�z‰z˜!‰}Ðr   c                 ó,   — t        | j                  «      S rQ   )rj   rW   r„   s    r   Ú__len__zParetoFront.__len__  s   € Ü�4—:‘:‹Ðr   c                 óª   — 	 | j                   j                  |«       || j                  ur| j                  D ]
  } ||«       Œ y y # t        $ r Y y w xY wrQ   )rW   ÚremoveÚ
ValueErrorrX   rV   )rY   r[   r}   s      r   rp   zParetoFront._remove  s\   € ð	Ø�J‰J×Ñ˜dÔ#ð �t—~‘~Ñ%Ø×.Ñ.ò �Ù�$•ñð &øô ò 	Ùð	ús   ‚A Á	AÁA)r   r   r   Ú__doc__r   rZ   r
   r   r   Úboolrh   r   r   Úobjectr�   r   r…   Úintr‡   r‰   rp   r   r   r   rM   rM   h   s·   „ ñ!ðF7˜vð 7¨$ó 7ðj"˜Ð)9Ñ9¸HÑDð j"Èó j"ðX,˜(Ð$4Ð#5°tÐ#;Ñ<ð ,Àó ,ð
$ ð $¨Dó $ð ˜(Ð#3Ñ4ó  ð˜Sð Ð%5ó ð˜ó ðÐ,ð °ô r   rM   c                   ó    — e Zd ZdZdd„Zdd„Zy)ÚParetoOptimisera—  Class for managing optimisation of the pareto front. That is, given the
    current best known pareto front, this class runs an optimisation process
    that attempts to bring it closer to the actual pareto front.

    Currently this is fairly basic and only handles pareto optimisation that
    works by reducing the test case in the shortlex order. We expect it will
    grow more powerful over time.
    Nc                 ó  — || _         | j                   }|j                  }d }||u}|sÁt        j                  d|fd||f«      dt	        j
                  «       v st        j                  | «      rt        j                  | «      ndt        j                  |«      t        j                  |«      t        j                  |«      dœz  }dd|iz  }t        t        j                  |«      «      ‚d x}x}x}}| j                   j                  | _
        y )N©úis not)zV%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.__engine
}.pareto_front
} is not %(py7)srY   )r'   r(   r)   ra   zassert %(py9)sÚpy9)Ú_ParetoOptimiser__engineÚpareto_frontr3   r4   r5   r6   r7   r8   r9   r:   rW   )rY   ÚenginerE   rD   Ú@py_assert6rq   rt   Ú@py_format10s           r   rZ   zParetoOptimiser.__init__-  s    € ØˆŒØ�}‰}Ð5ˆ}×)Ñ)Ð5°Ð5Ð)°Ð5×5×5Õ5Ð)°×5×5×5×5×5Ñ5ˆt×5×5Ó5ˆt×5×5Ô5ˆ}×5×5Ò5Ð)×5×5Ò5°×5×5×5×5×5×5Õ5Ø"&§-¡-×"<Ñ"<ˆ�
r   c                 óì  ‡ — t        «       }t        ‰ j                  «      dz
  }d }|dk\  �rI‰ j                  j                  �s1‰ j                  }|syddt        j                  «       v st        j                  ‰ «      rt        j                  ‰ «      ndt        j                  |«      dœz  }t        t        j                  |«      «      ‚d }t        |t        ‰ j                  «      dz
  «      }‰ j                  |   }t        |j                  «      |v r|dz  }Œô||u}|sÆt        j                  d|fd||f«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndd	t        j                  «       v st        j                  |«      rt        j                  |«      nd	dœz  }d
d|iz  }t        t        j                  |«      «      ‚d }|}ˆ fd„}‰ j                  j!                  ||¬«      }	|j#                  t        |	j                  «      «       ‰ j                  j                  j%                  |«      }|dk\  r‰ j                  j                  s�Œ/y y y y )Nr   r   z)assert %(py2)s
{%(py2)s = %(py0)s.front
}rY   r/   r”   )z%(py0)s is not %(py2)srI   Úprevr0   r)   c                 óx   •— t        || «      t        j                  k(  r‰j                  j	                  | «       yy)a±  Shrink to data that strictly pareto dominates the current
                best value we've seen, which is the current target of the
                shrinker.

                Note that during shrinking we may discover other smaller
                test cases that this function will reject and will get added to
                the front. This is fine, because they will be processed on
                later iterations of this loop.TF)r2   r   r   rW   rp   )ÚsourceÚdestinationrY   s     €r   Úallow_transitionz-ParetoOptimiser.run.<locals>.allow_transitionL  s5   ø€ ô ˜[¨&Ó1Ô5F×5UÑ5UÒUð
 —J‘J×&Ñ& vÔ.ØØr   )r¡   )r@   rj   rW   r—   Úinteresting_test_casesr5   r6   r3   r7   r8   r9   r:   Úminr	   Úchoicesr4   Úshrinkrh   Úbisect_left)
rY   Úseenrv   r�   rE   rH   rI   rF   r¡   Úshrunks
   `         r   ÚrunzParetoOptimiser.run2  sš  ø€ Ü‹uˆô �—
‘
‹O˜aÑˆØˆØ�1‹f˜TŸ]™]×AÓAØ—:‘:Ð‘:××××Õ�4××Ó�4××Ô�:×××××ÐÜ�A”s˜4Ÿ:™:“¨Ñ*Ó+ˆAØ—Z‘Z ‘]ˆFÜ˜6Ÿ>™>Ó*¨dÑ2Ø�Q‘�ØØ Ð%×%×%Õ%�6 ×%×%×%×%×%Ñ%�6×%×%Ó%�6×%×%×%×%×%Ò% ×%×%Ó% ×%×%×%×%×%×%Ñ%ØˆDôð$ —]‘]×)Ñ)¨&ÐCSÐ)ÓTˆFØ�H‰H”[ §¡Ó0Ô1ð —
‘
× Ñ ×,Ñ,¨VÓ4ˆAðO �1Šf˜TŸ]™]×AÕAˆfÐAˆfr   )r™   r   r"   N)r"   N)r   r   r   r�   rZ   r©   r   r   r   r’   r’   #  s   „ ñó=ô
75r   r’   )$Úbuiltinsr5   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter3   Úcollections.abcr   r   Úenumr   rN   r   Útypingr   Úsortedcontainersr   Ú%hypothesis.internal.conjecture.choicer	   Ú#hypothesis.internal.conjecture.datar
   r   r   r   Ú)hypothesis.internal.conjecture.junkdrawerr   Ú'hypothesis.internal.conjecture.shrinkerr   ÚfloatrC   Ú%hypothesis.internal.conjecture.enginer   r   r2   rM   r’   r   r   r   ú<module>r¸      sƒ   ð÷ „ × .Ý Ý Ý  å 'å =÷ó õ GÝ <á�‹=€áÝFô˜ô ð<,Ð$ð <,Ð-=ð <,ÐBSó <,÷~xñ x÷vF5ò F5r   