How nics-tw/petsard works
Purpose and entry points
PETsARD is a Python 3.10/3.11 library for configurable tabular synthetic-data generation, constraint handling, and fidelity/utility/privacy evaluation. Primary entry points are the programmatic workflow API in petsard/executor.py and YAML-driven executions illustrated by demo/getting-started/default-synthesis-default-evaluation.yaml. Public package exports begin at petsard/__init__.py.
Workflow orchestration and configuration
Executor coordinates configured stages, tracks completion, results, inferred schema, and timing. Configuration parsing and object construction are centralized in petsard/config.py and petsard/config_base.py; YAML represents the pipeline boundary, while Python APIs provide direct composition. The documented execution model is depth-first, allowing multiple experiments/stages from one configuration.
Paths: petsard/executor.py, petsard/config.py, demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml.
Data ingestion, splitting, and schema
Loaders turn local/tabular or benchmark inputs into the internal data flow; benchmark support includes a catalog and downloader. Splitters create controlled or non-overlapping subsets for synthesis/evaluation. The metadater layer infers, stores, aligns, and compares schema/statistical metadata, forming the contract between raw data, transforms, synthesizers, and evaluators.
Paths: petsard/loader/loader.py, petsard/loader/benchmarker.py, petsard/metadater/metadater.py, petsard/metadater/schema_inferencer.py.
Transformation pipeline
The processor subsystem provides fit/transform/inverse-transform stages for missing values, outliers, discretization, encoding, scaling, and schema transformation. mediator.py and registry.py indicate a composable processor/registration boundary: preprocessors adapt source data for model training, and postprocessors restore generated data to the expected schema/domain.
Paths: petsard/processor/base.py, petsard/processor/mediator.py, petsard/processor/schema_transform.py.
Synthesis and extensibility
The synthesizer abstraction separates common create/fit/sample lifecycle from implementations. Included engines are PETsARD Gaussian Copula and SDV-backed synthesis; custom synthesis is supported. Adapters provide a higher-level integration boundary across pipeline roles, and external Python modules can be referenced by YAML demos.
Paths: petsard/synthesizer/synthesizer_base.py, petsard/synthesizer/petsard_gaussian_copula.py, petsard/synthesizer/sdv.py, petsard/adapter.py.
Constraints, evaluation, and outputs
Constrainers validate generated records or resample until field, field-combination, proportion, and NaN-group rules are satisfied. Evaluators produce diagnostic/fidelity metrics, ML utility measurements, and privacy-risk metrics via integrations named for SDMetrics, Anonymeter, and MPUCCS. Reporters persist generated data, schemas, timing, validation results, and reports.
Paths: petsard/constrainer/constrainer.py, petsard/evaluator/evaluator.py, petsard/evaluator/anonymeter.py, petsard/reporter/reporter.py.
Runtime and delivery boundaries
The core runtime is a Python package distributed through PyPI and runnable in Docker/Compose. CI publishes images and PyPI releases and performs vulnerability/SBOM workflows. Documentation is a separate Hugo/Go site, published through GitHub Pages. External services/material dependencies include PyPI, Docker, GitHub Actions/Pages, benchmark-data retrieval, SDV, SDMetrics, Anonymeter, and MPUCCS.
Paths: pyproject.toml, Dockerfile, compose.yml, .github/workflows/semantic-release-pypi.yml.
Main entry points: synthesizer_base.py Synthesizer abstraction · mediator.py Processor mediator · executor.py Executor · loader.py Loaders
Components 22
Workflow
Configured execution and pipeline composition.
- Public package API
petsard/__init__.py - YAML workflow · Supports multiple configured experiments.
demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml - Executor · Coordinates depth-first stages, results, schema, and timing.
petsard/executor.py - Configuration builder · Parses configuration and constructs pipeline objects.
petsard/config.py
Data & Schema
Input preparation and metadata contract.
- Loaders · Loads local/tabular and benchmark inputs.
petsard/loader/loader.py - Benchmark catalog · Catalogs and downloads benchmark datasets.
petsard/loader/benchmarker.py - Metadata contract · Stores, aligns, and compares schema and statistics.
petsard/metadater/metadater.py - Schema inference
petsard/metadater/schema_inferencer.py
Generation
Transformation, synthesis, and constraints.
- Processor pipeline · Fit, transform, and inverse-transform contract.
petsard/processor/base.py - Processor mediator · Composes registered pre- and post-processing stages.
petsard/processor/mediator.py - Schema transform · Adapts data to the model-facing schema.
petsard/processor/schema_transform.py - Synthesizer abstraction · Common create, fit, and sample contract.
petsard/synthesizer/synthesizer_base.py - Gaussian Copula
petsard/synthesizer/petsard_gaussian_copula.py - SDV synthesizer · SDV-backed synthesis implementation.
petsard/synthesizer/sdv.py - Pipeline adapters · Integrates custom roles and external Python modules.
petsard/adapter.py - Constrainer · Validates or resamples generated records against rules.
petsard/constrainer/constrainer.py
Assessment & Output
Evaluation and persisted artifacts.
- Evaluator · Runs fidelity, utility, and privacy assessments.
petsard/evaluator/evaluator.py - Anonymeter metrics
petsard/evaluator/anonymeter.py - Reporter · Writes data, schemas, timing, validation, and reports.
petsard/reporter/reporter.py
Delivery
Packaging, containers, and release automation.
- PyPI release · Python distribution and release workflow.
pyproject.toml - Docker runtime · Containerized package execution.
Dockerfile - Release CI · Publishes PyPI releases and images.
.github/workflows/semantic-release-pypi.yml
Connections 23
- Public package API → Executor: starts
- YAML workflow → Configuration builder: defines
- Configuration builder → Executor: constructs stages for
- Executor → Loaders: loads source data
- Loaders → Benchmark catalog: retrieves benchmarks via
- Loaders → Schema inference: provides data
- Schema inference → Metadata contract: creates metadata
- Metadata contract → Processor mediator: guides transforms
- Processor mediator → Processor pipeline: orchestrates
- Processor mediator → Schema transform: applies
- Processor mediator → Synthesizer abstraction: preprocessed training data
- Synthesizer abstraction → Gaussian Copula: implemented by
- Synthesizer abstraction → SDV synthesizer: implemented by
- Pipeline adapters → Synthesizer abstraction: extends
- Synthesizer abstraction → Constrainer: generated samples
- Constrainer → Evaluator: validated synthetic data
- Evaluator → Anonymeter metrics: privacy metrics
- Evaluator → Reporter: evaluation reports
- Constrainer → Reporter: validation results
- Executor → Reporter: data, schema, and timing
- PyPI release → Docker runtime: packages runtime
- Release CI → PyPI release: publishes
- Release CI → Docker runtime: publishes image