Adapter API (WIP)
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.
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 methods:
__init__(config: dict)
- Initialize configurationrun(input: dict)
- Execute main logicset_input(status)
- Set input parametersget_result()
- Get execution resultsget_metadata()
- Get metadata (if applicable)
Adapter Classes
Adapter | Corresponding Module | Description |
---|---|---|
LoaderAdapter | Loader | Data loading, supports benchmark:// protocol |
SplitterAdapter | Splitter | Data splitting |
PreprocessorAdapter | Processor | Preprocessing |
SynthesizerAdapter | Synthesizer | Data synthesis |
PostprocessorAdapter | Processor | Postprocessing |
ConstrainerAdapter | Constrainer | Constraint processing |
EvaluatorAdapter | Evaluator | Evaluation |
DescriberAdapter | Describer | Descriptive statistics |
ReporterAdapter | Reporter | Report generation |
Basic Usage Pattern
from petsard.adapter import LoaderAdapter
# Create adapter
adapter = LoaderAdapter(config)
# Set input
input_data = adapter.set_input(status)
# Execute
adapter.run(input_data)
# Get results
result = adapter.get_result()
Error Handling
All Adapters use decorator pattern for error handling:
@log_and_raise_config_error
- Configuration error handling@log_and_raise_not_implemented
- Not implemented method handling
Important Notes
- Adapter layer is internal architecture, direct use is not recommended
- Prefer using YAML configuration files and Executor execution
- See sub-page documentation for specific parameters of each Adapter