Adapter API

Adapter API

Overview

The Adapter layer is a key component in the PETsARD architecture, responsible for wrapping each module into a unified execution interface for Executor invocation. Each Adapter provides standardized lifecycle methods and data flow management for its corresponding module.

Adapter Overall Architecture

classDiagram

    class BaseAdapter {
        <<abstract>>
        +config: dict
        +module_name: str
        +__init__(config)
        +run(input)
        +set_input(status) dict
        +get_result()
        +get_metadata() Schema
    }

    class LoaderAdapter {
        +loader: Loader
        +benchmarker: Benchmarker
        +run() tuple~DataFrame, Schema~
    }

    class SplitterAdapter {
        +splitter: Splitter
        +run() dict~str, DataFrame~
    }

    class PreprocessorAdapter {
        +processor: Processor
        +run() DataFrame
    }

    class SynthesizerAdapter {
        +synthesizer: Synthesizer
        +run() DataFrame
    }

    class PostprocessorAdapter {
        +processor: Processor
        +run() DataFrame
    }

    class ConstrainerAdapter {
        +constrainer: Constrainer
        +run() DataFrame
    }

    class EvaluatorAdapter {
        +evaluator: Evaluator
        +run() dict~str, DataFrame~
    }

    class DescriberAdapter {
        +describer: Describer
        +run() dict~str, DataFrame~
    }

    class ReporterAdapter {
        +reporter: Reporter
        +run() dict
    }

    BaseAdapter <|-- LoaderAdapter
    BaseAdapter <|-- SplitterAdapter
    BaseAdapter <|-- PreprocessorAdapter
    BaseAdapter <|-- SynthesizerAdapter
    BaseAdapter <|-- PostprocessorAdapter
    BaseAdapter <|-- ConstrainerAdapter
    BaseAdapter <|-- EvaluatorAdapter
    BaseAdapter <|-- DescriberAdapter
    BaseAdapter <|-- ReporterAdapter

    %% Style definitions
    style BaseAdapter fill:#F0F0F0
    style LoaderAdapter fill:#E6E6FA
    style SplitterAdapter fill:#E6E6FA
    style PreprocessorAdapter fill:#E6E6FA
    style SynthesizerAdapter fill:#E6E6FA
    style PostprocessorAdapter fill:#E6E6FA
    style ConstrainerAdapter fill:#E6E6FA
    style EvaluatorAdapter fill:#E6E6FA
    style DescriberAdapter fill:#E6E6FA
    style ReporterAdapter fill:#E6E6FA

Legend:

  • Gray box: Abstract base class
  • Light purple box: Concrete Adapter implementation classes
  • <|--: Inheritance relationship

Architecture

All Adapter classes inherit from BaseAdapter and implement the following core interface:

Core Methods

Utility Methods

BaseAdapter provides several utility methods for common operations:

Adapter Classes

AdapterCorresponding ModuleKey Features
LoaderAdapterLoaderData loading with benchmark:// protocol support
SplitterAdapterSplitterData splitting with custom_data method support
PreprocessorAdapterProcessorPreprocessing with global outlier config expansion
SynthesizerAdapterSynthesizerData synthesis with custom_data method support
PostprocessorAdapterProcessorPostprocessing with dtype restoration
ConstrainerAdapterConstrainerConstraint application with resample/validate modes
EvaluatorAdapterEvaluatorEvaluation with auto dtype alignment
DescriberAdapterDescriberDescriptive statistics with describe/compare modes
ReporterAdapterReporterReport generation with timing and validation support

Basic Usage Pattern

from petsard.adapter import LoaderAdapter

# Create adapter
adapter = LoaderAdapter(config)

# Set input from Status
input_data = adapter.set_input(status)

# Execute with timing
adapter.run(input_data)

# Get results
result = adapter.get_result()
metadata = adapter.get_metadata()  # If applicable

Error Handling

All Adapters use decorator pattern for error handling:

Data Flow

Adapters manage data flow between modules through the Status object:

  1. Input Phase: set_input() retrieves data from previous modules via Status
  2. Execution Phase: run() executes the wrapped module with timing
  3. Output Phase: get_result() and get_metadata() provide results to Status

Important Notes

  • Adapter layer is internal architecture - direct use is not recommended
  • Prefer using YAML configuration files with Executor
  • All data modifications respect Schema precision and statistics settings
  • Benchmark downloads are handled transparently via benchmark:// protocol
  • See individual Adapter pages for detailed configuration options