§
    ß©ºjä‡  ã                  óÊ  — U d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
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Zdd	lmZ dd
lmZ ddlmZmZmZmZm Z m!Z!m"Z"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/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: erddl;Z< ej=        d¦  «        Z>da?de@d<   ed         ZA eBdh¦  «        ZCde@d<   dZDde@d<   dOd!„ZEdPd%„ZFg d&¢ZGddd'd(œdQd1„ZH e
d2¬3¦  «         G d4„ d5¦  «        ¦   «         ZIdRd9„ZJ e
d2d2¬:¦  «         G d;„ d<¦  «        ¦   «         ZKdSdB„ZLdTdE„ZMdUdH„ZNdVdL„ZO e
d2d2¬:¦  «         G dM„ dN¦  «        ¦   «         ZPdS )Wa3  Panoptic-quality (PQ) evaluation surface (ADR-0025).

Per ADR-0029, the panoptic-segmentation evaluation paradigm lives under
``vernier.panoptic``. Sibling to :mod:`vernier.instance` and
:mod:`vernier.semantic`. The Rust kernel ships in the
``vernier-panoptic`` crate; this module is a thin Python wrapper.
é    )ÚannotationsN)ÚIterableÚSequence)Ú	dataclassÚfield)Úcached_property)ÚPath)ÚTYPE_CHECKINGÚFinalÚLiteralÚoverload)ÚNDArray)ÚBackgroundPanopticEvaluator)	Ú	BreakdownÚClassPanopticStatsÚPartialDatasetMismatchÚPartialFormatMismatchÚPartialParamsMismatchÚPartialPartitionOverlapÚPartialRankCollisionÚevaluate_panopticÚ%panoptic_per_class_to_arrow_pycapsule)ÚPanopticDataset)ÚPanopticPredictions)ÚPanopticSummary)Úevaluate_panoptic_to_partial)Úmerge_panoptic_partials)Úarrow_to_dataframe)	ÚCategoryFilterÚCategoryFilterAllÚCategoryFilterByGroupingÚCategoryFilterByIdsÚCategoryFilterFrequencyÚInvalidEvalParamsÚInvalidPanopticParamsÚ
ParityModeÚnormalize_tables_argzvernier.panopticFÚboolÚ_FORCED_LOG_EMITTEDÚ	per_classzfrozenset[TableName]ÚSUPPORTED_TABLESznpanoptic strict + num_threads>1: forcing retain_per_image_deltas=True for cross-thread bit-equality (ADR-0047)z
Final[str]Ú_FORCED_DELTAS_LOG_MSGÚnum_threadsú
int | NoneÚreturnÚintc                óä   — | €R	 t          t          j                             dd¦  «                             ¦   «         ¦  «        } n# t
          $ r Y dS w xY w| dk    rt          j        ¦   «         pdn| S )u?  Project ``num_threads`` onto the integer count actually used at
    runtime, matching the FFI's resolution. ``None`` consults
    ``VERNIER_NUM_THREADS`` (unparsable â†’ ``1``); ``0`` â†’ ``os.cpu_count()``
    (Python-side approximation of Rust's cgroup-aware
    ``available_parallelism``); ``n >= 1`` â†’ ``n``.
    NÚVERNIER_NUM_THREADSÚ1é   r   )r0   ÚosÚenvironÚgetÚstripÚ
ValueErrorÚ	cpu_count)r-   s    úi/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/vernier/panoptic/__init__.pyÚ_resolve_num_threads_for_policyr<   e   s{   € ð Ðð	Ý�bœjŸnšnÐ-BÀCÑHÔH×NÒNÑPÔPÑQÔQˆKˆKøÝð 	ð 	ð 	Ø�1�1ð	øøøà$/°1Ò$4Ð$4�BŒL‰NŒNÐ˜aø¸+ÐEs   „?A Á
AÁAÚparity_moder&   Úretain_per_image_deltasc                ó�   — | dk    st          |¦  «        dk    r|S |s(t          s!t                               t          ¦  «         dadS )uÓ  ADR-0047 Â§"Panoptic" forced-flag policy: under
    ``parity_mode="strict"`` and resolved ``num_threads > 1``, override
    any caller-supplied ``retain_per_image_deltas=False`` to ``True``
    and emit a one-shot info log via the module-level
    :data:`_FORCED_LOG_EMITTED` sentinel. Without the override,
    strict-mode users would observe a corrected-tier 4-ULP envelope
    across thread counts â€” the per-image ``PqStat`` fold is
    f64-non-associative.
    Ústrictr4   T)r<   r)   Ú_LOGGERÚinfor,   )r=   r-   r>   s      r;   Ú(_force_retain_per_image_deltas_if_strictrC   t   sW   € ð �hÒÐÕ"AÀ+Ñ"NÔ"NÐRSÒ"SÐ"SØ&Ð&Ø"ð #Õ+>ð #Ý�ŠÕ+Ñ,Ô,Ð,Ø"ÐØˆ4ó    )ÚBackgroundEvaluatorr   r   r    r!   r"   r#   r   ÚDatasetÚ
EvalResultÚ	Evaluatorr$   r%   r&   r   r   r   r   r   ÚPredictionsÚStuffThingPartitionÚSummaryÚ	TableNameÚdecode_label_map_pngÚoptimal_lrpÚ	corrected)Útp_thresholdÚtau_gridr=   ÚgtrF   ÚdtrI   rP   úfloat | NonerQ   Úobjectc               ó.   — | ||||f}t          d¦  «        ‚)uÙ  Panoptic LRP / oLRP (ADR-0043 â€” namespace reserved, not yet
    wired).

    Per ADR-0043 panoptic LRP runs a parallel matching pass that does
    not reuse PQ's hard ``IoU > 0.5`` cutoff (the tau sweep needs the
    full unthresholded matched-IoU list). That pass is not yet wired
    in 0.5.x because the panoptic prediction data model
    (``vernier.panoptic.Predictions``) does not carry per-segment
    scores â€” without a confidence value per detection there is no
    tau to sweep, and adding scores requires extending the panoptic
    paradigm's wire format (a separate ADR-level decision).

    The Python entry point is registered here so ``from
    vernier.panoptic import optimal_lrp`` works as advertised by
    ADR-0043; calling it raises :class:`NotImplementedError` with a
    structured remediation pointer to the same ADR. When the
    panoptic prediction shape adds a score field, this stub
    delegates to a sibling Rust kernel pass that mirrors the
    matching logic in :func:`vernier.instance.optimal_lrp` over
    segment-IoU.

    The argument shape is fixed in 0.5.x even though the function
    raises today: callers can write the call site against the final
    surface and the upgrade is purely backend.
    a¢  vernier.panoptic.optimal_lrp is reserved per ADR-0043 but not yet wired: the panoptic prediction data model does not carry per-segment scores, so the tau sweep cannot run. Adding scores to the panoptic Predictions shape is a separate ADR-level decision (the parallel-matching-pass plumbing is ready Rust-side; see crates/vernier-core/src/lrp/). Track the lift in the 0.5.x follow-up that wires panoptic LRP end-to-end.)ÚNotImplementedError)rR   rS   rP   rQ   r=   Ú_s         r;   rN   rN   ¨   s,   € ðB 
ˆR�˜x¨Ð5€AÝ
ð	8ñô ð rD   T)Úfrozenc                  óÚ   — e Zd ZU dZded<    edd¬¦  «        Zded<    edd¬¦  «        Zded	<    ed¬
¦  «        Zded<    ed¬
¦  «        Z	ded<   e
dd„¦   «         Ze
dd„¦   «         ZdS )rG   aº  Opt-in result of :meth:`Evaluator.evaluate` when ``tables=`` is
    passed. Carries :class:`Summary` plus a polars DataFrame view of
    the per-class panoptic-quality breakdown.

    Also returned when ``manifest=`` is passed (ADR-0046 partitioned
    eval): the ``.summary`` field carries the bit-identical-to-
    un-partitioned ``overall`` summary, and the :attr:`slices`
    DataFrame view exposes the per-``(axis, value)`` cell metrics.rK   ÚsummaryNF)ÚdefaultÚreprúobject | NoneÚ_per_class_batchÚ_slices_batch)r\   r.   Úoverall_n_imagesÚoverall_n_detectionsr/   úpl.DataFramec                ó,   — t          | j        d¦  «        S )zzOne row per category. Columns: ``category_id``, ``pq``,
        ``sq``, ``rq``, ``n_tp``, ``n_fp``, ``n_fn``, ``iou_sum``.r*   )r   r_   ©Úselfs    r;   r*   zEvalResult.per_classî   s   € õ " $Ô"7¸ÑEÔEÐErD   c                ó,   — t          | j        d¦  «        S )a2  One row per ``(axis, value)`` partition cell (ADR-0046).
        Columns: ``axis``, ``value``, ``n_images``, ``n_detections``,
        ``pq``, ``sq``, ``rq``. Available only when the originating
        ``evaluate(...)`` call carried a ``manifest=`` keyword; raises
        :class:`RuntimeError` otherwise.Úslices)r   r`   re   s    r;   rh   zEvalResult.slicesô   s   € õ " $Ô"4°hÑ?Ô?Ð?rD   )r/   rc   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r_   r`   ra   rb   r   r*   rh   © rD   r;   rG   rG   Õ   sý   € € € € € € ðFð Fð ÐÐÑØ&+ e°D¸uÐ&EÑ&EÔ&EÐÐEÐEÐEÑEð $) 5°¸EÐ#BÑ#BÔ#B€MÐBÐBÐBÑBð $) 5°Ð#6Ñ#6Ô#6ÐÐ6Ð6Ð6Ñ6ð (- u°TÐ':Ñ':Ô':ÐÐ:Ð:Ð:Ñ:àðFð Fð Fñ „_ðFð
 ð@ð @ð @ñ „_ð@ð @ð @rD   rG   Úpathú
str | PathúNDArray[np.uint32]c                ó”  — 	 ddl m} n"# t          $ r}t          d¦  «        |‚d}~ww xY wt          j        |                     | ¦  «        t          j        ¬¦  «        }|j        dk    s|j        d         dk     rt          d| ›d	|j        ›d
�¦  «        ‚|dd…dd…df         d|dd…dd…df         z  z   d|dd…dd…df         z  z   S )u   Decode a panoptic RGB PNG into a `(H, W)` ``uint32`` segment-id
    label map via the ``rgb2id`` convention (panopticapi/evaluation.py
    rgb2id: ``r + 256*g + 256Â²*b``).

    Lazy-imports Pillow; raises a structured :class:`ImportError` if it
    isn't installed. Three channels are required â€” a non-RGB PNG is
    rejected with :class:`ValueError`. Single-channel class-id label
    maps (semantic-segmentation) belong in
    :func:`vernier.semantic.Dataset.from_files`, which has its own
    decoder.
    r   )ÚImagez‰Pillow is required for `vernier.panoptic.decode_label_map_png`; install via `pip install Pillow` (or include it in your dev environment).N)Údtypeé   é   zpanoptic PNG z% must be RGB (3 channels); got shape zB. Single-channel semantic label maps belong in `vernier.semantic`.é   r4   i   )
ÚPILrs   ÚImportErrorÚnpÚarrayÚopenÚuint32ÚndimÚshaper9   )ro   rs   ÚeÚrgbs       r;   rM   rM   þ   s$  € ðØÐÐÐÐÐÐøÝð ð ð Ýðñ
ô 
ð ð		øøøøðøøøõ Œ(�5—:’:˜dÑ#Ô#­2¬9Ð
5Ñ
5Ô
5€CØ
„x�1‚}€}˜œ	 !œ qÒ(Ð(ÝðP˜Dð Pð PÈÌð Pð Pð Pñ
ô 
ð 	
ð ˆqˆqˆq�!�!�!�QˆwŒ<˜#  A A A q q q¨! G¤Ñ,Ñ,¨y¸3¸q¸q¸qÀ!À!À!ÀQ¸w¼<Ñ/GÑGÐGs   ‚	 ‰
(“#£()rY   Úslotsc                  ó0   — e Zd ZU dZded<   ded<   d	d„ZdS )
rJ   aÎ  User-supplied override of the GT-derived stuff/thing split
    (ADR-0042).

    Setting this on :class:`Evaluator.stuff_thing_partition` overrides
    the dataset's `isthing` flag per category for the purpose of the
    `PQ_St` / `PQ_Th` rollup. ``stuff`` and ``things`` must be disjoint
    and both non-empty (validated at construction). Membership against
    the dataset's category set is checked at ``evaluate()`` time once
    the Dataset is in scope.
    zfrozenset[int]ÚstuffÚthingsr/   ÚNonec                óæ   — | j         st          d| j         d¬¦  «        ‚| j        st          d| j        d¬¦  «        ‚| j         | j        z  }|r#t          d| dt          |¦  «        ›d�¬¦  «        ‚d S )Nzstuff_thing_partition.stuffz0must contain at least one category id (ADR-0042)©r   ÚvalueÚremediationzstuff_thing_partition.thingsÚstuff_thing_partitionz+stuff and things must be disjoint; overlap=z (ADR-0042))r„   r%   r…   Úsorted)rf   Úoverlaps     r;   Ú__post_init__z!StuffThingPartition.__post_init__+  s¯   € ØŒzð 	Ý'Ø3Ø”jØNðñ ô ð ð
 Œ{ð 	Ý'Ø4Ø”kØNðñ ô ð ð
 ”*˜tœ{Ñ*ˆØð 	Ý'Ø-Øà`Å&ÈÁ/Ä/Ð`Ð`Ð`ð	ñ ô ð ð	ð 	rD   N©r/   r†   )ri   rj   rk   rl   rm   rŽ   rn   rD   r;   rJ   rJ     sN   € € € € € € ð	ð 	ð ÐÐÑØÐÐÑðð ð ð ð ð rD   rJ   Úcfr   Úclass_groupingúBreakdown | Noner†   c           
     ó²  — t          | t          ¦  «        rt          d| d¬¦  «        ‚t          | t          ¦  «        r*t	          | j        ¦  «        dk    rt          d| d¬¦  «        ‚t          | t          ¦  «        rY|€t          d| d¬¦  «        ‚d„ |j        D ¦   «         }| j        |vr-t          d| d	| j        ›d
t          |¦  «        ›d�¬¦  «        ‚dS dS )a•  Validate a ``category_filter`` for the panoptic paradigm
    (ADR-0042).

    ``Frequency`` is rejected (panoptic has no per-class frequency tag
    analogous to LVIS r/c/f). ``ByIds`` requires non-empty unique ids;
    bounds against the dataset's category set are checked at evaluate
    time. ``ByGrouping`` requires that ``class_grouping`` is configured
    and that the named label exists in it.
    Úcategory_filterz—Frequency is LVIS-only - panoptic has no per-class frequency tag analogous to r/c/f. Use ByIds or ByGrouping instead (ADR-0026 lines 178-182, ADR-0042)rˆ   r   z6ByIds must contain at least one category id (ADR-0042)NzqByGrouping requires class_grouping to also be set; the label is resolved against the grouping's labels (ADR-0042)c                ó   — h | ]\  }}|’ŒS rn   rn   )Ú.0ÚlabelrX   s      r;   ú	<setcomp>z2_validate_panoptic_class_filter.<locals>.<setcomp>g  s   € ÐDÐDÐD™H˜E 1�%ÐDÐDÐDrD   zByGrouping label z1 is not a label of class_grouping (known labels: z); ADR-0042)
Ú
isinstancer#   r%   r"   ÚlenÚidsr!   Úclass_groupsr—   rŒ   )r�   r‘   Úlabelss      r;   Ú_validate_panoptic_class_filterrž   C  sD  € õ �"Õ-Ñ.Ô.ð 	
Ý#Ø#Øð5ð	
ñ 
ô 
ð 	
õ �"Õ)Ñ*Ô*ð 
­s°2´6©{¬{¸aÒ/?Ð/?Ý#Ø#ØØPð
ñ 
ô 
ð 	
õ
 �"Õ.Ñ/Ô/ð ØÐ!Ý'Ø'ØðUð	ñ ô ð ð EÐD¨Ô(CÐDÑDÔDˆØŒ8˜6Ð!Ð!Ý'Ø'ØðD¨¬ð Dð DÝ&,¨V¡n¤nðDð Dð Dð	ñ ô ð ðð ð "Ð!rD   úCategoryFilter | Noneúlist[int] | Nonec                ód  — | �t          | t          ¦  «        rdS t          | t          ¦  «        rt          | j        ¦  «        S t          | t
          ¦  «        rH|€J ‚|j        D ]!\  }}|| j        k    rt          |¦  «        c S Œ"t          d| d| j        ›d�¬¦  «        ‚t          d| d¬¦  «        ‚)z²Resolve an ADR-0042 ``category_filter`` to the kernel's id-list
    form. Mirrors the semantic resolver shape; ``ByGrouping`` looks up
    the label against the active partition.Nr”   zlabel z  disappeared from class_groupingrˆ   z"unsupported CategoryFilter variant)
r™   r    r"   rŒ   r›   r!   rœ   r—   Úlistr%   )r�   r‘   r—   r›   s       r;   Ú_resolve_category_filterr£   s  sæ   € ð 
€z•Z Õ$5Ñ6Ô6€zØˆtÝ�"Õ)Ñ*Ô*ð Ý�b”f‰~Œ~ÐÝ�"Õ.Ñ/Ô/ð 	
ØÐ)Ð)Ð)Ø(Ô5ð 	!ð 	!‰JˆE�3Ø˜œÒ Ð Ý˜C‘y”yÐ Ð Ð ð !å#Ø#ØØM ¤ÐMÐMÐMð
ñ 
ô 
ð 	
õ
  ØØØ8ðñ ô ð rD   Úbdú"list[tuple[str, list[int]]] | Nonec                ó,   — | €dS d„ | j         D ¦   «         S )zWResolve a ``class_grouping`` :class:`Breakdown` to the kernel's
    list-of-pairs form.Nc                ó6   — g | ]\  }}|t          |¦  «        f‘ŒS rn   )r¢   )r–   r—   r›   s      r;   ú
<listcomp>z+_resolve_class_grouping.<locals>.<listcomp>–  s'   € ÐAÐAÐA¡: 5¨#ˆU•D˜‘I”IÐÐAÐAÐArD   )rœ   )r¤   s    r;   Ú_resolve_class_groupingr©   �  s$   € ð
 
€zØˆtØAÐA°´ÐAÑAÔAÐArD   ÚpúStuffThingPartition | Noneú"tuple[list[int], list[int]] | Nonec                óZ   — | €dS t          | j        ¦  «        t          | j        ¦  «        fS )z«Resolve a :class:`StuffThingPartition` to the FFI's
    ``(stuff_ids, things_ids)`` tuple; ``None`` passes through and the
    kernel uses the dataset's ``isthing`` flags.N)rŒ   r„   r…   )rª   s    r;   Ú_resolve_stuff_thing_partitionr®   ™  s+   € ð 	€yØˆtÝ�1”7‰OŒO�V A¤HÑ-Ô-Ð.Ð.rD   c                  óh  — e Zd ZU dZdZded<   dZded<   dZded	<   d
Zded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dId„ZdJd„ZeddddddœdKd&„¦   «         Zeddddd'œdLd*„¦   «         Zeddddd+œdMd.„¦   «         ZddddddœdNd2„Zddd3œdOd:„Zeddddd
d;œdPd>„¦   «         Zddd?dd@dAddBœdQdH„ZdS )RrH   uœ  Panoptic-quality (PQ) evaluator (ADR-0025, ADR-0042).

    Sibling to :class:`vernier.instance.Evaluator`. Per category,
    ``PQ_c`` is computed directly as
    ``iou_c / (TP_c + 0.5*FP_c + 0.5*FN_c)`` (panopticapi form, quirk
    **W1**) â€” algebraically equal to ``SQ_c * RQ_c`` but f64
    non-associative, so the direct form is what holds bit-equality.
    Global ``PQ`` / ``SQ`` / ``RQ`` are unweighted means over the
    present-categories subset (W2, W3, W7); things / stuff buckets are
    independent unweighted means over their subsets (W4).

    Defaults match panopticapi's ``pq_compute`` shape, except for
    ``parity_mode``, which defaults to ``"corrected"`` (the ADR-0002
    recommendation for net-new users); migrating users wanting
    bit-exact panopticapi behavior should set ``parity_mode="strict"``.

    ``boundary=True`` enables Boundary Panoptic Quality (ADR-0025 Z1/Z2
    amendment). The per-image matching IoU is composed as
    ``min(mask_iou, boundary_iou)`` â€” identical to the instance
    Boundary case â€” over a boundary panoptic map built by eroding each
    segment's mask by ``dilation_ratio * sqrt(hÂ² + wÂ²)`` Chebyshev
    pixels and painting the resulting band back as the segment id.
    ``dilation_ratio`` defaults to ``0.02`` (Cheng et al. 2021).
    FN/FP attribution is unchanged: it consults the mask confusion
    matrix and mask per-segment areas only.

    The four ADR-0042 fields parameterize the evaluation scope and
    rollup: ``pq_iou_threshold`` overrides the canonical 0.5 PQ match
    threshold (single float, not a ladder); ``category_filter`` and
    ``class_grouping`` mirror the semantic surface (ADR-0041);
    ``stuff_thing_partition`` overrides the dataset-derived
    stuff/thing split for the ``PQ_St`` / ``PQ_Th`` rollup.

    **PR scope cut:** kernel-side plumbing for honoring the four
    custom fields (per_group rollups, threshold-aware matching,
    partition override) lands alongside the ADR-0039 distributed-eval
    phase. Until then, ``evaluate()`` raises
    :class:`NotImplementedError` when any custom field is set; the
    surface â€” fields, validation, ``StuffThingPartition`` value type â€”
    is in place.
    rO   r&   r=   Tr(   Úthings_stuff_splitFÚboundaryg{®Gáz”?ÚfloatÚdilation_ratioNrT   Úpq_iou_thresholdrŸ   r”   r’   r‘   r«   r‹   r/   r†   c                ó  — | j         rRt          j        | j        ¦  «        st	          d| j        d¬¦  «        ‚| j        dk    rt	          d| j        d¬¦  «        ‚| j        �N| j        }t          j        |¦  «        st	          d|d¬¦  «        ‚d|cxk     rdk    sn t	          d|d	¬¦  «        ‚| j        �'| j        j        d
k    rt	          d| j        d¬¦  «        ‚| j        �t          | j        | j        ¦  «         d S d S )Nr³   z9must be finite when boundary=True (ADR-0025 Z1 amendment)rˆ   g        zvmust be > 0.0 when boundary=True; the Chebyshev erosion radius clamps to >= 1 pixel regardless (ADR-0025 Z1 amendment)r´   zmust be finite (ADR-0042)g      ð?zGmust lie in (0.0, 1.0]; strict-zero is rejected as a footgun (ADR-0042)rœ   r‘   z‰must be a class-groups Breakdown (Breakdown.from_class_groups(...)); range Breakdowns belong on instance.Evaluator.area_ranges (ADR-0042))
r±   ÚmathÚisfiniter³   r%   r´   r‘   Úkindr”   rž   )rf   Úts     r;   rŽ   zEvaluator.__post_init__Ü  sg  € ØŒ=ð 	Ý”= Ô!4Ñ5Ô5ð Ý+Ø*ØÔ-Ø [ðñ ô ð ð
 Ô" cÒ)Ð)Ý+Ø*ØÔ-ð2ð	ñ ô ð ð Ô Ð,ØÔ%ˆAÝ”= Ñ#Ô#ð Ý+Ø,ØØ ;ðñ ô ð ð
 ˜�>�>’>�>˜c’>�>�>�>Ý+Ø,Øàað	ñ ô ð ð ÔÐ*¨tÔ/BÔ/GÈ>Ò/YÐ/YÝ'Ø&ØÔ)ðJð	ñ ô ð ð ÔÐ+Ý+¨DÔ,@À$ÔBUÑVÔVÐVÐVÐVð ,Ð+rD   c                óJ   — | j         dup| j        dup| j        dup| j        duS )z/``True`` when any ADR-0042 custom field is set.N)r´   r”   r‘   r‹   re   s    r;   Ú_has_custom_class_paramsz"Evaluator._has_custom_class_params  sF   € ð Ô!¨Ð-ð 6ØÔ#¨4Ð/ð6àÔ"¨$Ð.ð6ð Ô)°Ð5ð		
rD   )ÚtablesÚmanifestÚ
cross_axesr-   r>   rR   rF   rS   rI   r¼   r½   r¾   r-   r.   r>   rK   c               ó   — d S ©Nrn   ©rf   rR   rS   r¼   r½   r¾   r-   r>   s           r;   ÚevaluatezEvaluator.evaluate  s	   € ð �#rD   )r½   r¾   r-   r>   ú&Literal['all'] | tuple[TableName, ...]rG   c               ó   — d S rÀ   rn   rÁ   s           r;   rÂ   zEvaluator.evaluate!  ó	   € ð �SrD   )r¼   r¾   r-   r>   rU   úSequence[Sequence[str]] | Nonec               ó   — d S rÀ   rn   rÁ   s           r;   rÂ   zEvaluator.evaluate.  rÅ   rD   ú-Literal['all'] | tuple[TableName, ...] | Noner^   úSummary | EvalResultc               ó¶  — t          | j        ||¦  «         |�}ddlm} |�t	          d¦  «        ‚|                      ¦   «         rt          d|d¬¦  «        ‚ |||| j        | j        | j        | j	        |||¬¦	  «	        \  }	}
}}t          |	|
||¬	¦  «        S |�t	          d
¦  «        ‚t          | j        | j        ¦  «        }t          | j        ¦  «        }t          | j        ¦  «        }t#          ||| j        | j        | j        |||| j        | j	        |¬¦  «        }|€|S t'          |t(          ¦  «        }d|v rt+          |¦  «        nd}t          ||¬¦  «        S )uî  Run the panoptic-quality evaluation.

        ``gt`` and ``dt`` must have been built via
        :meth:`Dataset.from_arrays` / :meth:`Predictions.from_arrays`
        (file-loading helpers ship in a follow-up).

        ``tables=`` is the opt-in keyword for result tables (ADR-0038).
        Defaults to ``None``, returning :class:`Summary` (existing
        behavior, bit-identical to the pre-tables release). Pass
        ``"all"`` or a tuple of :data:`TableName` values to opt into
        the wider :class:`EvalResult` return type.

        ``manifest=`` opts into ADR-0046 partitioned eval. Accepts a
        dict (the canonical JSON-records shape), a file path
        (``.json``), or any object exposing the Arrow PyCapsule
        Interface (a polars / pandas / pyarrow DataFrame of per-image
        metadata). Returns an :class:`EvalResult` whose ``.summary``
        is bit-identical to the un-partitioned call and whose
        ``.slices`` property is a polars DataFrame with one row per
        ``(axis, value)`` cell. ``cross_axes=`` opts joint cells in
        (per ADR-0046 Â§E2; marginals are the default).

        Per ADR-0046's C3 axiom, the matching + attribution pass
        runs exactly once regardless of slice count: the panoptic
        kernel emits per-image per-category accumulator deltas, and
        the partition orchestrator folds + summarizes those deltas
        under (a) no filter for ``overall`` and (b) each slice's
        image-id set for the per-slice rows â€” the image-axis analogue
        of ADR-0026's K-axis subset-at-summarize-time. The
        ``overall`` summary is bit-identical to the un-partitioned
        call by construction (the un-filtered fold reproduces the
        canonical aggregation step verbatim).
        Nr   )Úevaluate_partitionedu  tables= and manifest= cannot be combined. The partitioned eval returns headline metrics per slice on `result.slices`; for the per-class by per-slice cross product, run per_class evaluate once per slice with a filtered prediction set â€” see docs/how-to/per-class-by-slice.md.r½   zñpanoptic partitioned eval does not yet propagate the ADR-0042 custom fields (pq_iou_threshold / category_filter / class_grouping / stuff_thing_partition). Re-run with a default-config evaluator, or run manifest= and custom params separately.rˆ   )r=   r°   r±   r³   r½   r¾   r-   )r[   r`   ra   rb   z•cross_axes= is only meaningful alongside manifest= (it opts joint cells into the manifest partition spec; with no manifest there is nothing to cross))r´   r”   r‘   r‹   r±   r³   r-   r*   )r[   r_   )rC   r=   Úvernier.panoptic._partitionrË   r9   r»   r%   r°   r±   r³   rG   r£   r”   r‘   r©   r®   r‹   r   r´   r'   r+   r   )rf   rR   rS   r¼   r½   r¾   r-   r>   Ú_evaluate_partitionedÚoverallÚslices_batchÚn_imagesÚ
n_segmentsÚresolved_filterÚresolved_groupsÚresolved_partitionr[   Ú	requestedÚper_class_batchs                      r;   rÂ   zEvaluator.evaluate;  sú  € õ` 	1ØÔ˜kÐ+Bñ	
ô 	
ð 	
ð Ððð ð ð ð ð ð Ð!Ý ð9ñô ð ð ×,Ò,Ñ.Ô.ð Ý+Ø$Ø"ðBð	
ñ 
ô 
ð 
ð ;PÐ:OØØØ Ô,Ø#'Ô#:ØœØ#Ô2Ø!Ø%Ø'ð
;ñ 
;ô 
;Ñ7ˆG�\ 8¨Zõ ØØ*Ø!)Ø%/ð	ñ ô ð ð Ð!Ýð6ñô ð õ 3°4Ô3GÈÔI\Ñ]Ô]ˆÝ1°$Ô2EÑFÔFˆÝ;¸DÔ<VÑWÔWÐÝ#ØØØÔØÔ#Ø!Ô2Ø+Ø*Ø"4Ø”]ØÔ.Ø#ð
ñ 
ô 
ˆð ˆ>ØˆNÝ(¨Õ1AÑBÔBˆ	à>IÈYÐ>VÐ>VÕ1°'Ñ:Ô:Ð:Ð\`ð 	õ  '¸OÐLÑLÔLÐLrD   )r>   r-   ÚimagesúJIterable[tuple[int, NDArray[np.uint32], bytes, NDArray[np.uint32], bytes]]Ú
categoriesÚbytesÚrank_idr0   c               óì   — |                       ¦   «         rt          d| d¬¦  «        ‚t          | j        ||¦  «        }t	          t          |¦  «        || j        || j        || j        | j        |¬¦	  «	        S )uß  Run the panoptic evaluation as a per-rank streaming submit
        and return the serialized partial bytes (ADR-0032, ADR-0035).

        ``images`` is an iterable of per-image tuples of the form
        ``(image_id, gt_label_map, gt_segments_info, dt_label_map,
        dt_segments_info)`` â€” the same shape the streaming substrate's
        ``update`` consumes. The asymmetry with :meth:`evaluate`
        (which takes pre-built :class:`Dataset` / :class:`Predictions`)
        is intentional: ``PanopticDataset`` does not yet expose
        per-image accessors, so the streaming path consumes per-image
        records directly. A future ADR may close the gap by adding
        :class:`Dataset` accessors.

        ``rank_id`` identifies this evaluator's rank in a multi-process
        eval. ``retain_per_image_deltas=True`` is required on every
        rank for strict-mode bit-equality across the merge (ADR-0032
        Â§"Determinism") at ~2x streaming memory cost.

        The partial bytes can be gathered across ranks and merged on
        the head rank with :meth:`from_partials` to produce a global
        :class:`Summary`.

        Per ADR-0042, raises :class:`InvalidPanopticParams` when any
        of ``pq_iou_threshold`` / ``category_filter`` / ``class_grouping``
        / ``stuff_thing_partition`` is set: extending the ADR-0032
        wire format to carry the resolved custom axes is a follow-up.
        Single-rank custom-params eval works today via :meth:`evaluate`.
        Úcustom_panoptic_paramsaD  evaluate_to_partial() with a custom pq_iou_threshold / category_filter / class_grouping / stuff_thing_partition is deferred to a follow-up to ADR-0042 (extends the ADR-0032 wire format to carry the resolved axes). Use evaluate(...) for single-rank custom panoptic eval today; multi-rank custom params land in the next phase.rˆ   )r°   r>   r±   r³   r-   )	r»   r%   rC   r=   Ú_evaluate_panoptic_to_partialr¢   r°   r±   r³   )rf   r×   rÙ   rÛ   r>   r-   s         r;   Úevaluate_to_partialzEvaluator.evaluate_to_partial¸  sŸ   € ðJ ×(Ò(Ñ*Ô*ð 	Ý'Ø.ØðNð	ñ ô ð õ #KØÔ˜kÐ+Bñ#
ô #
Ðõ -Ý�‰LŒLØØÔØØ#Ô6Ø$;Ø”]ØÔ.Ø#ð

ñ 

ô 

ð 
	
rD   )r=   r°   r>   r±   r³   ÚpartialsúSequence[bytes]c         	     óH   — t          |t          |¦  «        |||||¬¦  «        S )u2  Merge ``partials`` (one per rank) into a global :class:`Summary`
        (ADR-0032, ADR-0035).

        ``categories``, ``parity_mode``, ``things_stuff_split``,
        ``retain_per_image_deltas``, ``boundary``, and ``dilation_ratio``
        must match what each rank used to produce its partial.
        Mismatches raise the structured ``Partial*`` errors re-exported
        on this module â€” boundary-PQ partials carry the dilation ratio
        in ``params_hash`` so silent boundary/instance mixing is
        rejected at envelope-validation time.
        )r°   r>   r±   r³   )Ú_merge_panoptic_partialsr¢   )ÚclsrÙ   rà   r=   r°   r>   r±   r³   s           r;   Úfrom_partialszEvaluator.from_partialsù  s6   € õ0 (ØÝ�‰NŒNØØ1Ø$;ØØ)ð
ñ 
ô 
ð 	
rD   é   é   g      @)r>   rÛ   Úqueue_capacityÚworker_affinityÚworker_niceÚshutdown_timeout_secondsr-   rè   ré   rê   rë   rE   c               óŒ   — t          | j        ||¦  «        }t          || j        | j        ||||||| j        | j        |¬¦  «        S )uæ  Build a :class:`BackgroundEvaluator` (ADR-0014 + ADR-0032)
        that shares this evaluator's ``parity_mode`` and
        ``things_stuff_split``.

        The returned wrapper owns a single dedicated worker thread
        running a :class:`StreamingEvaluator` of the same shape;
        :meth:`BackgroundEvaluator.submit` enqueues per-image
        ``(gt_label_map, gt_segments_info, dt_label_map,
        dt_segments_info)`` tuples and returns immediately. Use this
        when the panoptic-quality kernel measurably stalls the
        training loop â€” the per-image attribute pass is the dominant
        cost at COCO-panoptic scale.

        ``retain_per_image_deltas=True`` enables strict-mode bit-
        equality across distributed-eval ranks (ADR-0032
        Â§"Determinism") at ~2x streaming memory cost. The five
        queueing / scheduling knobs mirror
        :class:`vernier.instance.Evaluator.background`.

        ``num_threads`` (ADR-0047) is forwarded into the per-worker
        rayon pool. The worker drain-batches pending submissions and
        applies them via the parallel kernel; single-threaded callers
        (``num_threads=None`` or ``1``) hit the unchanged single-image
        path with no batching overhead.
        )
r°   r>   rÛ   rè   ré   rê   rë   r±   r³   r-   )rC   r=   rE   r°   r±   r³   )	rf   rÙ   r>   rÛ   rè   ré   rê   rë   r-   s	            r;   Ú
backgroundzEvaluator.background  si   € õJ #KØÔ˜kÐ+Bñ#
ô #
Ðõ #ØØÔØ#Ô6Ø$;ØØ)Ø+Ø#Ø%=Ø”]ØÔ.Ø#ð
ñ 
ô 
ð 	
rD   r�   )r/   r(   )rR   rF   rS   rI   r¼   r†   r½   r†   r¾   r†   r-   r.   r>   r(   r/   rK   )rR   rF   rS   rI   r¼   rÃ   r½   r†   r¾   r†   r-   r.   r>   r(   r/   rG   )rR   rF   rS   rI   r¼   r†   r½   rU   r¾   rÆ   r-   r.   r>   r(   r/   rG   )rR   rF   rS   rI   r¼   rÈ   r½   r^   r¾   rÆ   r-   r.   r>   r(   r/   rÉ   )r×   rØ   rÙ   rÚ   rÛ   r0   r>   r(   r-   r.   r/   rÚ   )rÙ   rÚ   rà   rá   r=   r&   r°   r(   r>   r(   r±   r(   r³   r²   r/   rK   )rÙ   rÚ   r>   r(   rÛ   r.   rè   r0   ré   r.   rê   r0   rë   r²   r-   r.   r/   rE   )ri   rj   rk   rl   r=   rm   r°   r±   r³   r´   r”   r‘   r‹   rŽ   r»   r   rÂ   rß   Úclassmethodrå   rí   rn   rD   r;   rH   rH   ¤  s^  € € € € € € ð(ð (ðT *€KÐ)Ð)Ð)Ñ)Ø#ÐÐ#Ð#Ð#Ñ#Ø€HÐÐÐÑð !€NÐ Ð Ð Ñ Ø%)ÐÐ)Ð)Ð)Ñ)Ø-1€OÐ1Ð1Ð1Ñ1Ø'+€NÐ+Ð+Ð+Ñ+Ø8<ÐÐ<Ð<Ð<Ñ<ð-Wð -Wð -Wð -Wð^
ð 
ð 
ð 
ð ð ØØØ"&Ø(-ð
ð 
ð 
ð 
ð 
ñ „Xð
ð ð ØØ"&Ø(-ð
ð 
ð 
ð 
ð 
ñ „Xð
ð ð à59Ø"&Ø(-ð
ð 
ð 
ð 
ð 
ñ „Xð
ð" AEØ"&Ø59Ø"&Ø(-ð{Mð {Mð {Mð {Mð {Mð {MðF ).Ø"&ð?
ð ?
ð ?
ð ?
ð ?
ð ?
ðB ð #.Ø#'Ø(-ØØ $ð
ð 
ð 
ð 
ð 
ñ „[ð
ðJ ).Ø"ØØ&*ØØ*-Ø"&ð5
ð 5
ð 5
ð 5
ð 5
ð 5
ð 5
ð 5
rD   rH   )r-   r.   r/   r0   )r=   r&   r-   r.   r>   r(   r/   r(   )rR   rF   rS   rI   rP   rT   rQ   rU   r=   r&   r/   rU   )ro   rp   r/   rq   )r�   r   r‘   r’   r/   r†   )r�   rŸ   r‘   r’   r/   r    )r¤   r’   r/   r¥   )rª   r«   r/   r¬   )Qrl   Ú
__future__r   Úloggingr¶   r5   Úcollections.abcr   r   Údataclassesr   r   Ú	functoolsr   Úpathlibr	   Útypingr
   r   r   r   Únumpyrz   Únumpy.typingr   Úvernier._corer   rE   r   r   r   r   r   r   r   r   r   r   rF   r   rI   r   rK   r   rÞ   r   rã   Úvernier._tablesr   Úvernier._typesr   r    r!   r"   r#   r$   r%   r&   r'   ÚpolarsÚplÚ	getLoggerrA   r)   rm   rL   Ú	frozensetr+   r,   r<   rC   Ú__all__rN   rG   rM   rJ   rž   r£   r©   r®   rH   rn   rD   r;   ú<module>r      s¿  ððð ð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø 	€	€	€	Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  ðð ð ð ð ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ð /Ð .Ð .Ð .Ð .Ð .ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð ð ØÐÐÐà
ˆ'Ô
Ð.Ñ
/Ô
/€ð "Ð Ð !Ð !Ð !Ñ !ð
 �KÔ €	Ø)2¨°K°=Ñ)AÔ)AÐ Ð AÐ AÐ AÑ Að/ð ð ð ð ñ ðFð Fð Fð Fðð ð ð ð.ð ð €ðB "&ØØ)ð*ð *ð *ð *ð *ð *ðZ €�$ÐÑÔð%@ð %@ð %@ð %@ð %@ñ %@ô %@ñ Ôð%@ðPHð Hð Hð Hð: €�$˜dÐ#Ñ#Ô#ð$ð $ð $ð $ð $ñ $ô $ñ $Ô#ð$ðN-ð -ð -ð -ð`ð ð ð ð8Bð Bð Bð Bð/ð /ð /ð /ð €�$˜dÐ#Ñ#Ô#ðk
ð k
ð k
ð k
ð k
ñ k
ô k
ñ $Ô#ðk
ð k
ð k
rD   