Getting Started¶
Welcome to the PyPOTS developer documentation! This guide helps contributors understand the codebase and integrate new models, algorithms, and features.
If you are new to PyPOTS, do not start from a random model folder. Start from understanding the contracts — the base classes and their responsibilities.
Recommended Reading Route¶
Follow these sections in order:
This page — set up your environment, learn the key concepts
Understanding the Architecture — understand the codebase layout, base class hierarchy, and data flow
Model Integration Guide — follow the step-by-step guide for your model type
Quality Assurance — avoid common mistakes and pass the testing checklist
Setting Up the Development Environment¶
git clone https://github.com/WenjieDu/PyPOTS.git
cd PyPOTS
pip install -e ".[dev]"
Or with conda:
conda create -n pypots python=3.10
conda activate pypots
git clone https://github.com/WenjieDu/PyPOTS.git
cd PyPOTS
pip install -e ".[dev]"
Key Concepts¶
Before diving into the code, understand these three concepts that define how PyPOTS works.
Three-Layer Model Architecture¶
Every model in PyPOTS follows a three-layer architecture:
File |
Layer |
Responsibility |
|---|---|---|
|
Wrapper |
User-facing API, dataloaders, optimizers, training orchestration, input assembly |
|
Core |
Forward computation, result dict creation, loss and metric outputs |
|
Dataset |
Custom dataset class (only when |
Three Integration Paths¶
Before writing any code, decide which integration path your model belongs to. This is the most important decision — changing paths late usually means you started from the wrong contract.
Path |
When to Use |
Reference Model |
|---|---|---|
Standard NN |
One optimizer, default training loop. Most models fall here. |
|
Complex NN |
Multiple optimizers, alternating updates, or pretraining stages. |
|
Non-NN |
Rule-based, statistical, or algorithmic. No gradients. |
|
Six Supported Tasks¶
PyPOTS organizes models by task. Each task has its own base class and result contract:
Task |
NN Base |
Non-NN Base |
Result Key |
|---|---|---|---|
Imputation |
|
|
|
Forecasting |
|
|
|
Classification |
|
|
|
Anomaly Detection |
|
|
|
Clustering |
|
|
|
Representation |
|
|
|
How to Read a Reference Model¶
When reading an example model implementation, follow this order:
Task base class — understand the contract (result keys, helper methods)
model.py— the public wrapper API, dataloaders, optimizers, training orchestrationcore.py— forward computation and result dict contractdata.py— only if it exists; the custom dataset classThe matching test file — under
tests/<task>/
End-to-End Development Journey¶
The shortest safe path from idea to merged PR.
Step 1: Define the Contract¶
Before touching implementation code, decide:
The task:
imputation,forecasting,classification,anomaly_detection,clustering, orrepresentationThe correct base class: e.g.
BaseNNImputerfor an NN imputation modelThe public result key: e.g.
"imputation"for imputation modelsThe integration path: standard NN, complex NN, or non-NN
Step 2: Start From a Scaffold¶
Use the task template as a starting folder:
pypots/imputation/template/
pypots/forecasting/template/
pypots/classification/template/
pypots/clustering/template/
Then compare it with the matching reference model (SAITS, USGAN, or LOCF).
The template gives structure; the reference model gives the actual contract.
Step 3: Implement¶
Follow the detailed guide for your chosen path:
Standard NN Integration Path — for standard NN models
Complex NN Integration Path — for complex NN models
Non-NN Integration Path — for non-NN models
Step 4: Wire the Package¶
Export the model in the task package
__init__.pyAdd the matching test file under
tests/<task>/
Step 5: Validate Locally¶
# Generate test data
python tests/global_test_config.py
# Run your model's targeted test
pytest -rA tests/imputation/your_model.py -n 1
# Lint
flake8 .
Step 6: Submit with Evidence¶
Your PR should state:
The chosen integration path and reason
Exact local commands you ran and their results
Known limitations, if any
See Testing Checklist and CI Guide for the full testing checklist and CI guide.