"""LintQ detector stub -- auto-scaffolded from research note.

Generated by detector_stub_cron.py for cluster 40
(label: PennyLane:probability).

Source note (#25): PATTERN: Probability marginalization bugs -- probability(wires=k) silently returns the full distribution instead of the requested marginal. 1 issue(s) across: PennyLane. Sample: Open GitHub issue #9653 in PennyLaneAI/pennylane reported by…
"""

from __future__ import annotations

from typing import Dict, List


class DetectorProbability:
    """Detect the 'probability' anti-pattern reported against PennyLane.

    STATUS: STUB. This class was scaffolded automatically from a real issue
    cluster in lintq_research.db. Fill in ``detect`` with the logic below and
    add it to the engine rule set.

    TODO -- implement the detection:
        PATTERN: Probability marginalization bugs -- probability(wires=k) silently returns the full distribution instead of the requested marginal. 1 issue(s) across: PennyLane. Sample: Open GitHub issue #9653 in PennyLaneAI/pennylane reported by @Timeless-hep: [BUG] `QubitDevice`/`QutritDevice` `probability(wires=0)` silently returns the full 

        DETECTION LOGIC: Add a LintQ detector 'probability-marginal-misuse' that flags calls to device.probability(wires=...) and asserts the returned tensor shape matches len(wires); warn when the returned distribution dimensionality equals the full register (a sign the marginal was ignored). Prevents silent wrong-margin bugs in VQE/QAOA.
    """

    id = "probability"
    theme = "probability"
    software = "PennyLane"
    cluster_id = 40
    note_id = 25

    def detect(self, facts: Dict) -> List[Dict]:
        """Return a list of warning dicts for the given extracted facts.

        Args:
            facts: the 7-relation EDB fact dict produced by the extractor
                (Stmt, CFGEdge, Assign, CircuitAlloc, GateOp, MeasureOp,
                CircuitCall).

        Returns:
            A list of warning dicts, e.g.
            {"kind": "probability", "stmt": <id>, "qubit": <q>, "detail": <str>}.
        """
        raise NotImplementedError(
            "Detector stub -- implement 'probability' detection for PennyLane. "
            "See the TODO block in this class for the source note's logic."
        )
