API reference¶
import opendpd gives access to the functions and the trainer class below. They wrap the same training pipeline
as python main.py; keyword arguments that are not listed are forwarded to the command-line configuration
(arguments.py), so every main.py option is also available from Python. The opendpd-cli entry point is
python main.py under another name: run opendpd-cli --help for the options.
OpenDPD API - User-friendly interface for training PA and DPD models
This module provides high-level functions for easy use of OpenDPD functionality.
OpenDPDTrainer ¶
OpenDPDTrainer(dataset_name: Optional[str] = None, dataset_path: Optional[str] = None, **kwargs: Any)
Advanced trainer class for OpenDPD with more control over the training process.
This class provides a more object-oriented interface for advanced users who need fine-grained control over the training process.
Examples:
>>> import opendpd
>>> trainer = opendpd.OpenDPDTrainer(dataset_name='DPA_200MHz')
>>> trainer.train_pa(n_epochs=50)
>>> trainer.train_dpd(n_epochs=50)
>>> trainer.evaluate()
Initialize the OpenDPD trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Optional[str]
|
Name of the dataset |
None
|
dataset_path
|
Optional[str]
|
Path to custom dataset |
None
|
**kwargs
|
Any
|
Additional configuration parameters |
{}
|
train_pa ¶
train_pa(dataset_name: Optional[str] = None, dataset_path: Optional[str] = None, PA_backbone: str = 'gru', PA_hidden_size: int = 23, n_epochs: int = 300, batch_size: int = 64, lr: float = 0.005, accelerator: str = 'cpu', frame_length: int = 200, seed: int = 0, plot: bool = False, plot_every: int = 1, **kwargs: Any) -> Dict[str, Any]
Train a Power Amplifier (PA) behavioral model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Optional[str]
|
Name of the dataset in the |
None
|
dataset_path
|
Optional[str]
|
Deprecated. Specify |
None
|
PA_backbone
|
str
|
Type of neural network backbone ('gru', 'lstm', 'dgru', 'deltagru', etc.) |
'gru'
|
PA_hidden_size
|
int
|
Hidden size of the PA model |
23
|
n_epochs
|
int
|
Number of training epochs |
300
|
batch_size
|
int
|
Batch size for training |
64
|
lr
|
float
|
Learning rate |
0.005
|
accelerator
|
str
|
Device to use ('cpu', 'cuda', or 'mps') |
'cpu'
|
frame_length
|
int
|
Length of signal frames |
200
|
seed
|
int
|
Random seed for reproducibility |
0
|
plot
|
bool
|
Enable plot generation during training |
False
|
plot_every
|
int
|
Generate per-epoch plots every N epochs |
1
|
**kwargs
|
Any
|
Additional arguments passed to the training configuration |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing training results and model path |
Examples:
train_dpd ¶
train_dpd(dataset_name: Optional[str] = None, dataset_path: Optional[str] = None, DPD_backbone: str = 'tres_deltagru', DPD_hidden_size: int = 15, PA_backbone: str = 'gru', PA_hidden_size: int = 23, n_epochs: int = 300, batch_size: int = 64, lr: float = 0.005, accelerator: str = 'cpu', frame_length: int = 200, seed: int = 0, thx: float = 0.0, thh: float = 0.0, plot: bool = False, plot_every: int = 1, collect_delta_stats: bool = False, cuda_graph_training: bool = False, **kwargs: Any) -> Dict[str, Any]
Train a Digital Pre-Distortion (DPD) model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Optional[str]
|
Name of the dataset in the |
None
|
dataset_path
|
Optional[str]
|
Deprecated. Specify |
None
|
DPD_backbone
|
str
|
Type of DPD neural network backbone |
'tres_deltagru'
|
DPD_hidden_size
|
int
|
Hidden size of the DPD model |
15
|
PA_backbone
|
str
|
Type of PA backbone (must match the pre-trained PA model) |
'gru'
|
PA_hidden_size
|
int
|
Hidden size of PA model (must match the pre-trained PA model) |
23
|
n_epochs
|
int
|
Number of training epochs |
300
|
batch_size
|
int
|
Batch size for training |
64
|
lr
|
float
|
Learning rate |
0.005
|
accelerator
|
str
|
Device to use ('cpu', 'cuda', or 'mps') |
'cpu'
|
frame_length
|
int
|
Length of signal frames |
200
|
seed
|
int
|
Random seed for reproducibility |
0
|
thx
|
float
|
Threshold for input deltas (for delta-based models) |
0.0
|
thh
|
float
|
Threshold for hidden state deltas (for delta-based models) |
0.0
|
plot
|
bool
|
Enable plot generation during training |
False
|
plot_every
|
int
|
Generate per-epoch plots every N epochs |
1
|
collect_delta_stats
|
bool
|
Collect temporal sparsity diagnostics during training |
False
|
cuda_graph_training
|
bool
|
Opt in to guarded CUDA-graph DPD training |
False
|
**kwargs
|
Any
|
Additional arguments passed to the training configuration |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing training results and model path |
Examples:
run_dpd ¶
run_dpd(dataset_name: Optional[str] = None, dataset_path: Optional[str] = None, DPD_backbone: str = 'tres_deltagru', DPD_hidden_size: int = 15, accelerator: str = 'cpu', plot: bool = False, **kwargs: Any) -> Dict[str, Any]
Run the trained DPD model to generate pre-distorted signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Optional[str]
|
Name of the dataset in the |
None
|
dataset_path
|
Optional[str]
|
Deprecated. Specify |
None
|
DPD_backbone
|
str
|
Type of DPD backbone (must match trained model) |
'tres_deltagru'
|
DPD_hidden_size
|
int
|
Hidden size of DPD model (must match trained model) |
15
|
accelerator
|
str
|
Device to use ('cpu', 'cuda', or 'mps') |
'cpu'
|
plot
|
bool
|
Enable plot generation |
False
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing output paths and results |
Examples:
plot_dpd ¶
plot_dpd(dataset_name: Optional[str] = None, PA_backbone: str = 'gru', PA_hidden_size: int = 23, DPD_backbone: str = 'tres_deltagru', DPD_hidden_size: int = 15, accelerator: str = 'cpu', **kwargs: Any) -> Dict[str, Any]
Generate comparison plots: PA output without DPD vs with DPD.
This function loads trained PA and DPD models, runs inference on the test set for both scenarios, and generates side-by-side comparison plots including PSD, AM/AM, AM/PM, constellation diagrams, waveforms, and a metrics summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Optional[str]
|
Name of the dataset in the |
None
|
PA_backbone
|
str
|
Type of PA backbone (must match the pre-trained PA model) |
'gru'
|
PA_hidden_size
|
int
|
Hidden size of PA model (must match the pre-trained PA model) |
23
|
DPD_backbone
|
str
|
Type of DPD backbone (must match trained model) |
'tres_deltagru'
|
DPD_hidden_size
|
int
|
Hidden size of DPD model (must match trained model) |
15
|
accelerator
|
str
|
Device to use ('cpu', 'cuda', or 'mps') |
'cpu'
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing plot directory path |
Examples:
load_dataset ¶
Load a dataset from a CSV file or directory.
This function supports both formats: 1. Split CSV files (train_input.csv, train_output.csv, etc.) 2. Single CSV file with all data (I_in, Q_in, I_out, Q_out columns)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
str
|
Path to the dataset directory or single CSV file |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing loaded data arrays |
Examples:
create_dataset ¶
create_dataset(csv_path: str, output_dir: str, dataset_name: str, train_ratio: float = 0.6, val_ratio: float = 0.2, test_ratio: float = 0.2, dataset_format: str = 'single_csv', csv_filename: Optional[str] = None, **spec_kwargs: Any) -> str
Create a dataset in OpenDPD format from a single CSV file.
The input CSV should have 4 columns: I_in, Q_in, I_out, Q_out
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path
|
str
|
Path to the input CSV file |
required |
output_dir
|
str
|
Directory where the dataset will be created |
required |
dataset_name
|
str
|
Name of the dataset |
required |
train_ratio
|
float
|
Ratio of data for training (default: 0.6) |
0.6
|
val_ratio
|
float
|
Ratio of data for validation (default: 0.2) |
0.2
|
test_ratio
|
float
|
Ratio of data for testing (default: 0.2) |
0.2
|
dataset_format
|
str
|
|
'single_csv'
|
csv_filename
|
Optional[str]
|
Optional filename for the generated single CSV (defaults to |
None
|
**spec_kwargs
|
Any
|
Additional fields for spec.json (e.g., input_signal_fs, bw_main_ch) |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the created dataset directory |
Examples: