"""Stub file for eval directory."""
from typing import Any, Callable, List, Optional, Tuple

from .contracts import SplitEvaluatorProtocol
from .eval_model_loader import ModelLoaderCallable, load_model_with_runtime
from .eval_model_loader import load_model_with_runtime
from .evaluator import evaluate_available_splits
from .exceptions import InferenceRunnerError
from .exceptions import InferenceRunnerError, ModelLoadError
from .exceptions import PayloadFormatError
from .exceptions import RuntimeNotSupportedError
from .inference_runners import RunnerCallable, get_inference_runner
from .runtime_registry import RuntimeTaskRegistry
from .schemas import MetricPayload
from .schemas import MetricPayload, validate_payload
from .status_handler import EvaluationStatusReporter

# Constants
RunnerCallable: Any = ...  # From inference_runners
MetricPayload: Any = ...  # From result_formatter
MetricPayload: Any = ...  # From schemas

# Functions
# From classification_runtime_adapters
def allocate_buffers(engine: Any) -> tuple[Any, Any, Any, Any, Any]:
    """
    Create host and device buffers for TensorRT engine input/output.
    
        Args:
            engine: TensorRT engine object exposing tensor shapes.
            cuda: Imported PyCUDA driver module.
            trt: Imported TensorRT module.
    
        Returns:
            Tuple ``(h_input, d_input, h_output, d_output, stream)``.
    """
    ...

# From classification_runtime_adapters
def do_inference(_engine: Any, context: Any, h_input: Any, d_input: Any, h_output: Any, d_output: Any, stream: Any) -> Any:
    """
    Run one TensorRT inference step and return host output buffer.
    
        Args:
            _engine: Unused TensorRT engine placeholder for API compatibility.
            context: TensorRT execution context.
            h_input: Host input buffer.
            d_input: Device input buffer.
            h_output: Host output buffer.
            d_output: Device output buffer.
            stream: CUDA stream used for async copies and execution.
            cuda: Imported PyCUDA driver module.
    
        Returns:
            Host output buffer containing inference results.
    """
    ...

# From classification_runtime_adapters
def get_onnx_inference_results(loader: Any, model: Any, action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference for all batches on ONNX Runtime.
    
        Args:
            loader: Classification dataloader yielding ``(images, target)``.
            model: ONNX Runtime session object.
            action_tracker: Tracker-like object (unused in ONNX path).
    
        Returns:
            Tuple of concatenated ``(predictions, outputs, targets)`` tensors.
    """
    ...

# From classification_runtime_adapters
def get_openvino_inference_results(loader: Any, model: tuple[Any, Any], action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference for all batches on OpenVINO runtime.
    
        Args:
            loader: Classification dataloader yielding ``(images, target)``.
            model: Tuple of ``(compiled_model, output_layer)`` objects.
            action_tracker: Tracker-like object (unused in OpenVINO path).
    
        Returns:
            Tuple of concatenated ``(predictions, outputs, targets)`` tensors.
    """
    ...

# From classification_runtime_adapters
def get_pytorch_inference_results(loader: Any, model: Any, action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference for all batches on PyTorch runtime.
    
        Args:
            loader: Classification dataloader yielding ``(images, target)``.
            model: PyTorch or TorchScript module.
            action_tracker: Tracker-like object for optional inference logging.
    
        Returns:
            Tuple of concatenated ``(predictions, outputs, targets)`` tensors.
    """
    ...

# From classification_runtime_adapters
def get_tensorrt_inference_results(loader: Any, model: tuple[Any, Any], action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference for all batches on TensorRT runtime.
    
        Args:
            loader: Classification dataloader yielding ``(images, target)``.
            model: Tuple of TensorRT ``(engine, context)`` objects.
            action_tracker: Tracker-like object (unused in TensorRT path).
    
        Returns:
            Tuple of concatenated ``(predictions, outputs, targets)`` tensors.
    """
    ...

# From classification_runtime_adapters
def load_classification_model(action_tracker: Any, runtime_framework: str = 'pytorch') -> Any:
    """
    Load classification model artifact for the requested runtime.
    
        Args:
            action_tracker: Tracker-like object with model download methods.
            runtime_framework: Runtime descriptor used to select loader strategy.
    
        Returns:
            Runtime-specific loaded model artifact.
    """
    ...

# From classification_runtime_adapters
def load_engine(trt_filename: str) -> tuple[Any, Any]:
    """
    Deserialize TensorRT engine file and build execution context.
    
        Args:
            trt_filename: Path to serialized TensorRT engine file.
            trt: Imported TensorRT module.
    
        Returns:
            Tuple of deserialized ``(engine, context)`` objects.
    """
    ...

# From classification_runtime_adapters
def setup_tensorrt() -> tuple[Any, Any]:
    """
    Import TensorRT and PyCUDA lazily to keep base runtime lightweight.
    
        Args:
            None.
    
        Returns:
            Tuple of imported ``(cuda, trt)`` modules.
    """
    ...

# From classification_runtime_adapters
def validate_device(loaded_model: Any.Any.Any) -> tuple[Any.Any.Any, Any.Any]:
    """
    Move model to best available device with safe CPU fallback.
    
        Args:
            loaded_model: PyTorch module to validate on target device.
    
        Returns:
            Tuple of ``(model_on_device, resolved_device)``.
    """
    ...

# From common_classification
def build_imagefolder_loaders(data_root: str, batch_size: int, workers: int) -> tuple[Any.Any.Any.Any | None, Any.Any.Any.Any | None, Any.Any.Any.Any | None]:
    """
    Build train/val/test loaders for ImageFolder directory layout.
    
        Args:
            data_root: Root directory that may contain ``train``, ``val``, and ``test``.
            batch_size: Batch size used for created dataloaders.
            workers: Number of worker processes for dataloading.
            image_size: Final crop size for model input.
            resize_size: Resize dimension used before center crop for eval splits.
            include_train_loader: Whether to create a train loader when directory exists.
    
        Returns:
            Tuple of ``(train_loader, val_loader, test_loader)`` where missing splits are ``None``.
    """
    ...

# From compat
def ensure_metric_functions(metric_functions: Any[str, Any]) -> dict[str, Any]:
    """
    Ensure required metric function keys exist with safe defaults.
    
        Args:
            metric_functions: Existing metric function mapping from caller.
    
        Returns:
            Normalized mapping containing all formatter-required keys.
    """
    ...

# From compat
def make_legacy_split_evaluator(legacy_get_metrics: Callable[..., Any], **extra_kwargs: Any) -> Callable[[str, Any], Any]:
    """
    Wrap legacy ``get_metrics`` function into split-callback signature.
    
        Args:
            legacy_get_metrics: Legacy evaluator callable from older projects.
            model: Loaded model object passed through to legacy evaluator.
            index_to_labels: Mapping of class index to label names.
            runtime_framework: Optional runtime name forwarded to legacy evaluator.
            action_tracker: Optional tracker object forwarded to legacy evaluator.
            **extra_kwargs: Additional keyword arguments forwarded to evaluator.
    
        Returns:
            Callable with signature ``fn(split, loader) -> payload``.
    """
    ...

# From dataset_utils
def build_split_loader_map(requested_splits: Any[str], train_loader: Any | None, val_loader: Any | None, test_loader: Any | None) -> dict[str, Any]:
    """
    Create split-to-loader map while skipping unavailable loaders.
    
        Args:
            requested_splits: Ordered split names requested by caller.
            train_loader: Optional loader for ``train`` split.
            val_loader: Optional loader for ``val`` split.
            test_loader: Optional loader for ``test`` split.
    
        Returns:
            Dictionary containing only requested splits that have non-``None`` loaders.
    """
    ...

# From evaluator
def evaluate_available_splits(requested_splits: Any[str], split_to_loader: Any[str, Any], evaluate_split: Callable[[str, Any], list[dict]]) -> list[dict]:
    """
    Run split evaluator for available loaders and concatenate payload.
    
        Args:
            requested_splits: Ordered split names to evaluate.
            split_to_loader: Mapping from split name to loader object.
            evaluate_split: Callable that evaluates one split and returns payload records.
    
        Returns:
            Concatenated list of payload dictionaries from all available splits.
    """
    ...

# From inference_outputs
def coerce_classification_output(raw: Any) -> Any:
    """
    Convert raw runner output to ``ClassificationInferenceOutput``.
    
        Args:
            raw: Runner output object or tuple-like result.
    
        Returns:
            Normalized ``ClassificationInferenceOutput`` instance.
    """
    ...

# From inference_outputs
def coerce_detection_output(raw: Any) -> Any:
    """
    Convert raw runner output to ``DetectionInferenceOutput``.
    
        Args:
            raw: Runner output object or tuple-like result.
    
        Returns:
            Normalized ``DetectionInferenceOutput`` instance.
    """
    ...

# From inference_runners
def get_inference_runner(runtime_framework: str, runners: dict[str, Any], default_key: str = 'pytorch') -> Any:
    """
    Resolve a runtime framework to a registered inference callable.
    
        Args:
            runtime_framework: Runtime descriptor string from caller.
            runners: Mapping of runtime keys to runner callables.
            default_key: Default key used when runtime descriptor is ambiguous.
    
        Returns:
            Resolved inference runner callable.
    """
    ...

# From orchestrator
def build_runtime_split_evaluator(registry: Any) -> Callable[[str, Any], Any]:
    """
    Create split evaluator using runtime registry and optional formatter.
    
        Args:
            registry: Task/runtime registry containing loaders and runners.
            action_tracker: Tracker object passed through for API compatibility.
            context: Evaluation context containing task, runtime, and split metadata.
            runner_kwargs: Extra keyword arguments for runner invocation.
            split_formatter: Optional formatter converting runner output to payload.
    
        Returns:
            Callable with signature ``fn(split, loader) -> MetricPayload``.
    """
    ...

# From orchestrator
def load_model_from_registry(registry: Any) -> Any:
    """
    Load model using task/runtime registry and raise typed errors.
    
        Args:
            registry: Task/runtime registry containing model loaders.
            action_tracker: Tracker-like object passed to loader implementation.
            task_type: Task identifier used to resolve loader namespace.
            runtime_framework: Runtime descriptor used to resolve loader variant.
    
        Returns:
            Loaded model artifact returned by resolved loader.
    """
    ...

# From result_formatter
def format_classification_results(split: str, predictions: Any, output: Any, target: Any, index_to_labels: Any[str, str], metric_functions: Any[str, Any]) -> Any:
    """
    Build standardized single-label classification metric payload.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            predictions: Predicted class ids from inference runner.
            output: Model output tensor or array used for metrics.
            target: Ground-truth target tensor or array.
            index_to_labels: Mapping of class indices to label names.
            metric_functions: Mapping containing required metric callables.
    
        Returns:
            Normalized classification metric payload records.
    """
    ...

# From result_formatter
def format_detection_results(split: str, precision: Any[Any], recall: Any[Any], f1_score: Any[Any], index_to_labels: Any[str, str], mAP50: Any | None = None, mAP50_95: Any | None = None) -> Any:
    """
    Build standardized detection payload from per-class vectors.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            precision: Iterable of per-class precision values.
            recall: Iterable of per-class recall values.
            f1_score: Iterable of per-class F1 values.
            index_to_labels: Mapping of class indices to label names.
            mAP50: Optional mean average precision at IoU 0.50.
            mAP50_95: Optional mean average precision over IoU range.
    
        Returns:
            Normalized detection metric payload records.
    """
    ...

# From result_formatter
def format_keypoint_results(split: str, keypoint_names: Any[str] | None = None, mAP: Any | None = None, mAP50: Any | None = None, oks_mAP: Any | None = None, pck: Any | None = None, per_keypoint_pck: Any[Any] | None = None) -> Any:
    """
    Build normalized payload for keypoint or pose estimation metrics.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            keypoint_names: Optional names for each keypoint index.
            mAP: Optional mean average precision value.
            mAP50: Optional mean average precision at IoU 0.50.
            oks_mAP: Optional OKS-based mean average precision.
            pck: Optional overall PCK value.
            per_keypoint_pck: Optional iterable of per-keypoint PCK values.
    
        Returns:
            Normalized keypoint metric payload records.
    """
    ...

# From result_formatter
def format_multilabel_results(split: str, per_class_precision: Any[Any], per_class_recall: Any[Any], per_class_f1: Any[Any], macro_f1: Any | None, micro_f1: Any | None, mAP: Any | None, index_to_labels: Any[str, str]) -> Any:
    """
    Build normalized payload for multi-label classification metrics.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            per_class_precision: Iterable of per-class precision values.
            per_class_recall: Iterable of per-class recall values.
            per_class_f1: Iterable of per-class F1 values.
            macro_f1: Optional macro-averaged F1 value.
            micro_f1: Optional micro-averaged F1 value.
            mAP: Optional mean average precision value.
            index_to_labels: Mapping of class indices to label names.
    
        Returns:
            Normalized multi-label metric payload records.
    """
    ...

# From result_formatter
def format_ocr_results(split: str, cer: Any | None = None, wer: Any | None = None, precision: Any | None = None, recall: Any | None = None, f1_score: Any | None = None) -> Any:
    """
    Build normalized payload for OCR or text pipeline metrics.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            cer: Optional character error rate.
            wer: Optional word error rate.
            precision: Optional precision value.
            recall: Optional recall value.
            f1_score: Optional F1 score value.
    
        Returns:
            Normalized OCR metric payload records.
    """
    ...

# From result_formatter
def format_tracking_results(split: str, mota: Any | None = None, motp: Any | None = None, idf1: Any | None = None, hota: Any | None = None, fp: Any | None = None, fn: Any | None = None, ids: Any | None = None) -> Any:
    """
    Build normalized payload for MOT-style tracking metrics.
    
        Args:
            split: Split name such as ``train`` or ``val``.
            mota: Optional MOTA value.
            motp: Optional MOTP value.
            idf1: Optional IDF1 value.
            hota: Optional HOTA value.
            fp: Optional false-positive count.
            fn: Optional false-negative count.
            ids: Optional identity-switch count.
    
        Returns:
            Normalized tracking metric payload records.
    """
    ...

# From result_formatter
def format_yolo_results(yolo_result: Any, split: str) -> Any:
    """
    Build detection payload from Ultralytics YOLO validation result object.
    
        Args:
            yolo_result: Ultralytics validation result object with metrics and per-class stats.
            split: Split name such as ``train`` or ``val``.
    
        Returns:
            Normalized detection payload records derived from YOLO result.
    """
    ...

# From schemas
def validate_metric_record(item: dict[str, Any], index: int = 0) -> Any:
    """
    Validate and normalize a metric record with Pydantic.
    
        Args:
            item: Raw metric record dictionary to validate.
            index: Item index used for contextual error messages.
    
        Returns:
            Normalized metric record that conforms to payload schema.
    """
    ...

# From schemas
def validate_payload(payload: Any[dict[str, Any]]) -> Any:
    """
    Validate and normalize a full metric payload list with Pydantic.
    
        Args:
            payload: Iterable of raw metric record dictionaries.
    
        Returns:
            List of normalized metric records.
    """
    ...

# From status_handler
def safe_update_status(action_tracker: Any, step_code: str, status: str, description: str) -> None:
    """
    Submit status updates without propagating tracker exceptions.
    
        Args:
            action_tracker: Tracker-like object implementing ``update_status``.
            step_code: Evaluation lifecycle step identifier.
            status: Status level such as ``OK`` or ``ERROR``.
            description: Human-readable status description.
    
        Returns:
            None.
    """
    ...

# Classes
# From contracts
class ActionTrackerProtocol:
    # Minimal tracker interface used by eval flows.

    def log_error(self: Any, file_path: str, module: str, message: str) -> Any:
        """
        Persist an evaluation error entry for observability.
        
                Args:
                    file_path: Source file associated with the error.
                    module: Logical module or location string.
                    message: Error details to persist.
        
                Returns:
                    Tracker-specific result, if any.
        """
        ...

    def save_evaluation_results(self: Any, payload: Any) -> Any:
        """
        Persist normalized evaluation payload records.
        
                Args:
                    payload: Normalized metric payload records to persist.
        
                Returns:
                    Tracker-specific result, if any.
        """
        ...

    def update_status(self: Any, step_code: str, status: str, description: str) -> None:
        """
        Persist lifecycle status for a specific evaluation step.
        
                Args:
                    step_code: Evaluation lifecycle step identifier.
                    status: Status level such as ``OK`` or ``ERROR``.
                    description: Human-readable status description.
        
                Returns:
                    Tracker-specific result, if any.
        """
        ...


# From contracts
class InferenceRunnerProtocol:
    # Inference runner callable contract.
    #
    #     Runners usually return tuples like:
    #     - (predictions, outputs, targets) for classification
    #     - (outputs, targets) for detection/segmentation

    ...

# From contracts
class ModelLoaderProtocol:
    # Runtime model loader callable contract.

    ...

# From contracts
class ResultFormatterProtocol:
    # Result formatter callable contract.

    ...

# From contracts
class SplitEvaluatorProtocol:
    # Single split evaluator callable contract.

    ...

# From exceptions
class DatasetSplitError:
    # Raised when expected dataset split directories/loaders are missing.

    ...

# From exceptions
class EvaluationError(Exception):
    # Base class for evaluation-related failures.

    ...

# From exceptions
class InferenceRunnerError:
    # Raised when runner execution or output coercion fails.

    ...

# From exceptions
class ModelLoadError:
    # Raised when model artifact loading fails.

    ...

# From exceptions
class PayloadFormatError:
    # Raised when metric payload does not satisfy schema.

    ...

# From exceptions
class RuntimeNotSupportedError:
    # Raised when task/runtime mapping is not configured.

    ...

# From inference_outputs
class ClassificationInferenceOutput:
    # Standard output container for classification-style runners.

    ...

# From inference_outputs
class DetectionInferenceOutput:
    # Standard output container for detection/segmentation-style runners.

    ...

# From inference_runners
class InferenceRunnerRegistry:
    # Registry used by evaluators to select framework-specific runners.

    def get(self: Any, runtime_key: str) -> Any | None:
        """
        Fetch a runner by exact runtime key when present.
        
                Args:
                    runtime_key: Exact runtime key to look up.
        
                Returns:
                    Registered runner callable, or ``None`` when key is missing.
        """
        ...

    def register(self: Any, runtime_key: str, runner: Any) -> None:
        """
        Register an inference runner under a runtime key.
        
                Args:
                    runtime_key: Runtime key used during runner resolution.
                    runner: Runner callable to register.
        
                Returns:
                    None.
        """
        ...

    def resolve(self: Any, runtime_framework: str) -> Any:
        """
        Resolve the best runner for a runtime descriptor string.
        
                Args:
                    runtime_framework: Runtime descriptor requested by caller.
        
                Returns:
                    Resolved inference runner callable.
        """
        ...


# From orchestrator
class EvalContext:
    # Runtime context consumed by orchestrators.

    ...

# From orchestrator
class EvaluationOrchestrator:
    # Execute split evaluation and payload normalization.

    def fail(self: Any, error: Any) -> None:
        """
        Report evaluation failure details to tracking facilities.
        
                Args:
                    error: Exception raised during evaluation flow.
        
                Returns:
                    None.
        """
        ...

    def persist(self: Any, payload: Any) -> None:
        """
        Persist successful payload and emit completion status.
        
                Args:
                    payload: Normalized metric payload to persist through tracker.
        
                Returns:
                    None.
        """
        ...

    def run(self: Any) -> Any:
        """
        Execute evaluation over available splits and normalize payload.
        
                Args:
                    None.
        
                Returns:
                    Normalized metric payload aggregated across requested splits.
        """
        ...


# From runtime_registry
class RuntimeTaskRegistry:
    # Registry keyed by task type and runtime framework.

    def register_loader(self: Any, task_type: str, runtime_key: str, loader: Any) -> None:
        """
        Register a model loader for a task/runtime pair.
        
                Args:
                    task_type: Task namespace to register loader under.
                    runtime_key: Runtime key associated with the loader.
                    loader: Model loader callable for the task/runtime pair.
        
                Returns:
                    None.
        """
        ...

    def register_runner(self: Any, task_type: str, runtime_key: str, runner: Any) -> None:
        """
        Register an inference runner for a task/runtime pair.
        
                Args:
                    task_type: Task namespace to register runner under.
                    runtime_key: Runtime key associated with the runner.
                    runner: Inference runner callable for the task/runtime pair.
        
                Returns:
                    None.
        """
        ...

    def resolve_loader(self: Any, task_type: str, runtime_framework: str) -> Any:
        """
        Resolve a model loader callable for a task/runtime descriptor.
        
                Args:
                    task_type: Task namespace used for loader lookup.
                    runtime_framework: Runtime descriptor used for runtime matching.
        
                Returns:
                    Loader callable configured for resolved task/runtime pair.
        """
        ...

    def resolve_runner(self: Any, task_type: str, runtime_framework: str) -> Any:
        """
        Resolve an inference runner callable for a task/runtime descriptor.
        
                Args:
                    task_type: Task namespace used for runner lookup.
                    runtime_framework: Runtime descriptor used for runtime matching.
        
                Returns:
                    Runner callable configured for resolved task/runtime pair.
        """
        ...


# From schemas
class MetricRecord:
    # Metric record including optional contextual attributes.

    ...

# From schemas
class MetricRecordModel:
    # Pydantic schema used for metric payload validation.

    model_config: Any


# From status_handler
class EvaluationStatusCodes:
    # Canonical evaluation status step codes.

    ...

# From status_handler
class EvaluationStatusReporter:
    # Semantic status reporter for eval lifecycle transitions.

    def __init__(self: Any, action_tracker: Any, codes: Any | None = None) -> None:
        """
        Initialize status reporter with tracker and optional code overrides.
        
                Args:
                    action_tracker: Tracker-like object used for status updates.
                    codes: Optional status code overrides for evaluation lifecycle.
        
                Returns:
                    None.
        """
        ...

    def acknowledged(self: Any, msg: str = 'Model Evaluation has acknowledged') -> None:
        """
        Publish acknowledgement status.
        
                Args:
                    msg: Optional status description override.
        
                Returns:
                    None.
        """
        ...

    def completed(self: Any, msg: str = 'Model Evaluation is completed') -> None:
        """
        Publish evaluation-completed status.
        
                Args:
                    msg: Optional status description override.
        
                Returns:
                    None.
        """
        ...

    def dataset_loaded(self: Any, msg: str = 'Evaluation dataset is loaded') -> None:
        """
        Publish dataset-ready status.
        
                Args:
                    msg: Optional status description override.
        
                Returns:
                    None.
        """
        ...

    def failed(self: Any, msg: str) -> None:
        """
        Publish evaluation-failed status.
        
                Args:
                    msg: Failure description for status tracking.
        
                Returns:
                    None.
        """
        ...

    def model_loaded(self: Any, msg: str = 'Model loaded for evaluation') -> None:
        """
        Publish model-loaded status.
        
                Args:
                    msg: Optional status description override.
        
                Returns:
                    None.
        """
        ...

    def started(self: Any, msg: str = 'Model Evaluation has started') -> None:
        """
        Publish evaluation-started status.
        
                Args:
                    msg: Optional status description override.
        
                Returns:
                    None.
        """
        ...


from . import classification_runtime_adapters, common_classification, compat, contracts, dataset_utils, eval_model_loader, evaluator, exceptions, inference_outputs, inference_runners, orchestrator, result_formatter, runtime_registry, schemas, status_handler