Kaira API Reference
Note
Kaira version 0.2.1 documentation. For older versions, please refer to the version selector above.
This documentation provides a comprehensive reference of Kaira’s components organized by functional category. Each component is documented with its parameters, methods, and usage examples.
Overview
Kaira is a modular toolkit for communication systems built on PyTorch. The library is organized into several key modules that handle different aspects of communication systems:
Channels: Model transmission mediums with various noise and distortion characteristics
Constraints: Enforce practical limitations on transmitted signals
Metrics: Evaluate quality and performance of communication systems
Models: Implement neural network architectures for encoding/decoding and end-to-end communication systems
Modulations: Implement digital modulation schemes for wireless transmission
Losses: Provide objective functions for training neural networks
Utilities: Helper functions and tools for common operations
Base Components
Base classes define the fundamental interfaces that all implementations must adhere to. These abstract classes establish the contract that derived classes must fulfill.
Base abstract class for communication channel models. |
|
Abstract foundation for implementing signal constraints in PyTorch-compatible format. |
|
Base Metric Module. |
|
Abstract base class for all models in the Kaira framework. |
|
Abstract base class for all modulators. |
|
Abstract base class for all demodulators. |
|
Base class for all Kaira loss functions. |
Channels
Channel models for communication systems.
This package provides various channel models for simulating communication systems, including analog and digital channels, with support for various noise models, distortions, and fading patterns.
Additive white Gaussian noise (AWGN) channel for signal transmission. |
|
Base abstract class for communication channel models. |
|
Binary Erasure Channel (BEC) with symbol erasure probability. |
|
Binary Symmetric Channel (BSC) with symmetric bit flip probability. |
|
Z Channel (asymmetric binary channel) with one-sided error probability. |
|
A registry for channels in Kaira. |
|
Flat fading channel with configurable distribution and coherence time. |
|
alias of |
|
alias of |
|
alias of |
|
Customizable channel that applies user-defined functions to signals. |
|
Channel with additive Laplacian (double-exponential) noise. |
|
Log-normal fading channel with configurable shadowing standard deviation. |
|
General nonlinear channel with configurable transfer function. |
|
Identity channel that passes signals through unchanged. |
|
Channel that introduces random phase noise. |
|
Channel with signal-dependent Poisson noise. |
|
Specialized channel for Rayleigh fading in wireless communications. |
|
Rician fading channel with configurable K-factor and coherence time. |
|
Uplink Multiple Access Channel (MAC) for modeling multi-user uplink communications. |
Constraints
Constraints module for Kaira.
This module contains various constraints that can be applied to transmitted signals in wireless communication systems. These constraints ensure signals meet practical requirements such as power limitations, hardware capabilities, and regulatory specifications.
Available constraint categories: - Base constraint definitions: Abstract base classes for all constraints - Power constraints: Control total power, average power, and PAPR - Antenna constraints: Manage power distribution across multiple antennas - Signal constraints: Handle amplitude limitations and spectral properties - Constraint composition: Combine multiple constraints sequentially
The module also provides factory functions for creating common constraint combinations and utilities for testing and validating constraint effectiveness.
- Example:
>>> from kaira.constraints import TotalPowerConstraint, PAPRConstraint >>> from kaira.constraints.utils import combine_constraints >>> >>> # Create individual constraints >>> power_constr = TotalPowerConstraint(total_power=1.0) >>> papr_constr = PAPRConstraint(max_papr=4.0) >>> >>> # Combine constraints into a single operation >>> combined = combine_constraints([power_constr, papr_constr]) >>> >>> # Apply to a signal >>> constrained_signal = combined(input_signal)
Scales signal to achieve specified average power per sample. |
|
Abstract foundation for implementing signal constraints in PyTorch-compatible format. |
|
Applies multiple constraints in sequence. |
|
A registry for constraints in Kaira. |
|
Identity constraint that returns the input signal unchanged. |
|
Constraint that applies a user-defined function to the signal. |
|
Reduces peak-to-average power ratio using soft clipping to minimize signal distortion. |
|
Enforces maximum signal amplitude by clipping values that exceed threshold. |
|
Distributes power budget across multiple antennas to ensure per-antenna power limits. |
|
Restricts signal frequency components to comply with regulatory spectral masks. |
|
Normalizes signal to achieve exact total power regardless of input signal power. |
Utils
Utility functions for constraints.
This module provides helper functions for creating, testing, validating, and working with constraints in wireless communication systems. These utilities streamline the process of configuring common constraint combinations and verifying constraint effectiveness.
Apply a list of constraints in sequence and optionally print debug info. |
|
Combine multiple constraints into a single constraint. |
|
Create constraints commonly used in MIMO systems. |
|
Create constraints commonly used in OFDM systems. |
|
Measure common signal properties for a given tensor. |
|
Verify that a constraint produces the expected property in the output. |
Metrics
Metrics module for Kaira.
This module contains various metrics for evaluating the performance of communication systems.
Base Metric Module. |
|
A metric that combines multiple metrics with optional weighting. |
|
A registry for metrics in Kaira. |
Image
Image metrics module.
This module contains metrics for evaluating image quality.
Learned Perceptual Image Patch Similarity (LPIPS) Module. |
|
Multi-Scale Structural Similarity Index Measure (MS-SSIM) Module. |
|
alias of |
|
Peak Signal-to-Noise Ratio (PSNR) Module. |
|
alias of |
|
Structural Similarity Index Measure (SSIM) Module. |
Signal
Signal metrics module.
This module contains metrics for evaluating signal processing performance.
alias of |
|
alias of |
|
Bit Error Rate (BER) metric. |
|
Block Error Rate (BLER) metric. |
|
alias of |
|
Error Vector Magnitude (EVM) metric. |
|
alias of |
|
alias of |
|
alias of |
|
alias of |
|
Signal-to-Noise Ratio (SNR) metric. |
|
alias of |
Models
Models module for Kaira.
Abstract base class for all models in the Kaira framework. |
|
A specialized model for Channel Code. |
|
Model that supports dynamically adding and removing steps. |
|
Deep Joint Source-Channel Coding model. |
|
A model that models communication with a feedback channel. |
|
Base configuration class for Kaira models. |
|
A registry for models in Kaira. |
|
A model simulating a Multiple Access Channel (MAC). |
|
A model for Wyner-Ziv coding with decoder side information. |
Forward Error Correction (FEC)
Forward Error Correction module for Kaira models.
This module provides comprehensive implementations for forward error correction, including both encoders and decoders for various coding schemes. The encoders and decoders are designed to work seamlessly together to provide robust error correction capabilities for communication systems.
Decoders
Forward Error Correction (FEC) decoders for Kaira.
This module provides various decoder implementations for forward error correction codes. The decoders in this module are designed to work seamlessly with the corresponding encoders from the kaira.models.fec.encoders module.
Example Usage
>>> from kaira.models.fec.encoders import BCHCodeEncoder
>>> from kaira.models.fec.decoders import BerlekampMasseyDecoder
>>> encoder = BCHCodeEncoder(15, 7)
>>> decoder = BerlekampMasseyDecoder(encoder)
>>> # Example decoding
>>> received = torch.tensor([1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1])
>>> decoded = decoder(received)
Base class for block code decoders. |
|
Belief propagation decoder for linear block codes and LDPC codes. |
|
Decoder for Polar code using Belief Propagation (BP) method. |
|
Berlekamp-Massey decoder for BCH and Reed-Solomon codes. |
|
Brute Force Maximum Likelihood decoder for block codes. |
|
Min-Sum decoder for LDPC codes [Chen et al., 2005]. |
|
Reed-Muller decoder using majority-logic decoding. |
|
Decoder for Polar code using Successive Cancellation (SC) method [Arıkan, 2009]. |
|
Syndrome lookup decoder for linear block codes. |
|
Wagner soft-decision decoder for single parity-check codes. |
Encoders
Forward Error Correction encoders for Kaira.
This module provides various encoder implementations for forward error correction.These encoders can be used to add redundancy to data for enabling error detection and correction in communication systems, storage devices, and other applications requiring reliable data transmission over noisy channels.
Encoder for BCH (Bose–Chaudhuri–Hocquenghem) codes. |
|
Base class for block code encoders. |
|
Encoder for cyclic codes. |
|
Encoder for binary Golay codes. |
|
Encoder for Hamming codes. |
|
Encoder for LDPC code [Gallager, 1962], [Gallager, 1963]. |
|
Encoder for linear block coding. |
|
Encoder for Polar code [Arıkan, 2008]. |
|
Encoder for Reed-Muller codes. |
|
Encoder for Reed-Solomon (RS) codes. |
|
Encoder for repetition coding that extends LinearBlockCodeEncoder. |
|
Encoder for single parity-check codes. |
|
Encoder for systematic linear block coding. |
Soft Bit Thresholding
Soft bit thresholding module for binary data processing.
This module provides various thresholding techniques for converting soft bit representations (probabilities, LLRs, etc.) to hard decisions. These thresholders can be used with soft decoders or as standalone components in signal processing pipelines.
Soft bit processing is crucial in modern communication systems to extract maximum information from the received signals. The techniques implemented here are based on established methods in communication theory.
Adaptive thresholder for soft bit values. |
|
Thresholder with dynamically adjusting threshold for non-stationary signals. |
|
Simple fixed threshold for soft bit values. |
|
Thresholder with hysteresis for robust decision making in noisy environments. |
|
Enumeration of supported input types for soft bit thresholders. |
|
Specialized thresholder for Log-Likelihood Ratio (LLR) values. |
|
Thresholder based on minimum distance calculations. |
|
Enumeration of supported output types for soft bit thresholders. |
|
Enhanced decoder for repetition coding with flexible soft bit processing. |
|
Ensemble thresholder that combines decisions from multiple thresholders. |
|
Base class for soft bit thresholding techniques. |
|
Thresholder that applies weights to input values before thresholding. |
Components
Components module for Kaira models.
AFModule: Attention-Feature Module [Xu et al., 2021]. |
|
Convolutional Neural Network (CNN) Decoder for image transmission systems. |
|
Convolutional Neural Network (CNN) Encoder for image transmission systems. |
|
Multi-Layer Perceptron (MLP) Decoder for communication systems. |
|
Multi-Layer Perceptron (MLP) Encoder for communication systems. |
|
Projection layer for dimensionality reduction in communication systems [Yilmaz et al., 2025, Yilmaz et al., 2025]. |
|
Enum for different types of projections. |
Generic
Generic model implementations for Kaira.
This module provides generic model implementations that can be used as building blocks for more complex models, such as sequential, parallel, and branching models.
Model that routes inputs through different paths based on conditions. |
|
Identity Model. |
|
Lambda Model. |
|
A model that processes steps in parallel. |
|
A model that processes steps sequentially. |
Image
Image model implementations for Kaira.
This module provides models specifically designed for image data transmission.
DeepJSCC decoder model from [Bourtsoulatze et al., 2019]. |
|
DeepJSCC encoder model from [Bourtsoulatze et al., 2019]. |
|
Decoder network for DeepJSCC with Feedback [Kurka and Gündüz, 2020]. |
|
Encoder network for DeepJSCC with Feedback [Kurka and Gündüz, 2020]. |
|
Deep Joint Source-Channel Coding with Feedback implementation [Kurka and Gündüz, 2020]. |
|
DeepJSCCQ2 Decoder Module [Tung et al., 2022]. |
|
DeepJSCCQ2 Encoder Module [Tung et al., 2022]. |
|
DeepJSCCQ Decoder Module [Tung et al., 2022]. |
|
DeepJSCCQ Encoder Module [Tung et al., 2022]. |
|
Discrete Task-Oriented Deep JSCC decoder [Xie et al., 2023]. |
|
Discrete Task-Oriented Deep JSCC encoder [Xie et al., 2023]. |
|
DeepJSCC-NOMA Decoder Module [Yilmaz et al., 2023]. |
|
DeepJSCC-NOMA Encoder Module [Yilmaz et al., 2023]. |
|
Distributed Deep Joint Source-Channel Coding over a Multiple Access Channel [Yilmaz et al., 2023]. |
|
DeepJSCC-WZ Conditional Decoder Module [Yilmaz et al., 2024]. |
|
DeepJSCC-WZ Conditional Encoder Module [Yilmaz et al., 2024]. |
|
DeepJSCC-WZ Decoder Module [Yilmaz et al., 2024]. |
|
DeepJSCC-WZ Encoder Module [Yilmaz et al., 2024]. |
|
A specialized Wyner-Ziv model for neural joint source-channel coding with side information. |
|
DeepJSCC-WZ-sm Decoder Module [Yilmaz et al., 2024]. |
|
DeepJSCC-WZ-sm Encoder Module [Yilmaz et al., 2024]. |
Compressors
Image compressor models, including standard and neural network-based methods.
BPG (Better Portable Graphics) image compression based on bpgenc and bpgdec. |
|
Abstract base class for image compression methods. |
|
JPEG 2000 image compressor using JPEG 2000 via PIL/Pillow. |
|
JPEG image compressor using libjpeg via PIL/Pillow. |
|
JPEG XL image compressor using JPEG XL via PIL/Pillow. |
|
Neural network-based image compression model. |
|
PNG image compressor using libpng via PIL/Pillow. |
|
WebP image compressor using WebP via PIL/Pillow. |
Modulations
Digital modulation schemes for wireless communications.
This package provides implementations of common digital modulation and demodulation techniques used in modern communication systems, including PSK, QAM, PAM, and differential modulation schemes.
Binary Phase-Shift Keying (BPSK) demodulator. |
|
Binary Phase-Shift Keying (BPSK) modulator. |
|
Abstract base class for all demodulators. |
|
Abstract base class for all modulators. |
|
Differential Binary Phase-Shift Keying (DBPSK) demodulator. |
|
Differential Binary Phase-Shift Keying (DBPSK) modulator. |
|
Differential Phase-Shift Keying (DPSK) demodulator. |
|
Differential Phase-Shift Keying (DPSK) modulator. |
|
Differential Quadrature Phase-Shift Keying (DQPSK) demodulator. |
|
Differential Quadrature Phase-Shift Keying (DQPSK) modulator. |
|
Identity demodulator that passes input data through unchanged. |
|
Identity modulator that passes input data through unchanged. |
|
A registry for modulations in Kaira. |
|
Offset Quadrature Phase-Shift Keying (OQPSK) demodulator. |
|
Offset Quadrature Phase-Shift Keying (OQPSK) modulator. |
|
Pulse Amplitude Modulation (PAM) demodulator. |
|
Pulse Amplitude Modulation (PAM) modulator. |
|
General M-ary Phase-Shift Keying (PSK) demodulator. |
|
General M-ary Phase-Shift Keying (PSK) modulator. |
|
Π/4-QPSK demodulator. |
|
Π/4-QPSK (π/4 shifted QPSK) modulator. |
|
Quadrature Amplitude Modulation (QAM) demodulator. |
|
Quadrature Amplitude Modulation (QAM) modulator. |
|
Quadrature Phase-Shift Keying (QPSK) demodulator. |
|
Quadrature Phase-Shift Keying (QPSK) modulator. |
Utils
Utility functions for digital modulation schemes.
Convert binary array to Gray code. |
|
Convert binary number to Gray code. |
|
Calculate spectral efficiency of a modulation scheme in bits/s/Hz. |
|
Calculate theoretical Bit Error Rate (BER) for common modulations. |
|
Convert Gray-coded array to binary. |
|
Convert Gray code to binary number. |
|
Plot a constellation diagram. |
Losses
Kaira Losses Package.
This package provides various loss functions for different modalities.
Base class for all Kaira loss functions. |
|
A loss that combines multiple loss functions with optional weighting. |
|
A registry for loss functions in Kaira. |
Image
Losses module for Kaira.
This module contains various loss functions for training communication systems, including MSE loss, LPIPS loss, and SSIM loss. These loss functions are widely used in image processing and computer vision tasks [Wang and Bovik, 2009] [Zhang et al., 2018].
Combined Loss Module. |
|
Focal Loss Module for dealing with class imbalance. |
|
Gradient Loss Module. |
|
L1 (Mean Absolute Error) Loss Module. |
|
Learned Perceptual Image Patch Similarity (LPIPS) Loss Module. |
|
MSELPIPSLoss Module. |
|
Mean Squared Error (MSE) Loss Module. |
|
Multi-Scale Structural Similarity Index Measure (MS-SSIM) Loss Module. |
|
Peak Signal-to-Noise Ratio (PSNR) Loss Module. |
|
Structural Similarity Index Measure (SSIM) Loss Module. |
|
Style Loss Module based on Gram matrices. |
|
Total Variation Loss Module. |
|
VGG Perceptual Loss Module. |
Data
Data utilities for Kaira.
This module provides simple and efficient dataset classes for communication systems and information theory experiments. All datasets are memory-efficient and generate data on-demand.
Dataset for binary tensor data with configurable probability. |
|
Dataset for correlated data pairs. |
|
Dataset that applies a custom function to generate data. |
|
Dataset for Gaussian distributed tensor data. |
|
Simple wrapper for common image datasets. |
|
Dataset for uniformly distributed tensor data. |
Datasets
Simple and efficient dataset implementations for Kaira.
This module provides dataset classes for communication systems and information theory experiments. All datasets generate data on-demand for memory efficiency and support PyTorch DataLoader.
Dataset for binary tensor data with configurable probability. |
|
Dataset for correlated data pairs. |
|
Dataset that applies a custom function to generate data. |
|
Dataset for Gaussian distributed tensor data. |
|
Dataset for uniformly distributed tensor data. |
Sample Data
Simple image dataset utilities for Kaira.
This module provides basic image dataset functionality for testing and examples.
Simple wrapper for common image datasets. |
Utils
General utility functions for the Kaira library.
A comprehensive plotting utility class with static methods for visualization. |
Add Gaussian noise to achieve a target Signal-to-Noise Ratio. |
|
Calculate the number of filters in an image based on the number of strided layers and bandwidth ratio. |
|
Calculate the SNR between original and noisy signals. |
|
Estimate the power of a signal. |
|
Calculate SNR in dB given signal and noise power. |
|
Seed all random number generators to make runs reproducible. |
|
Convert Signal-to-Noise Ratio from decibel to linear scale. |
|
Convert Signal-to-Noise Ratio from linear scale to decibels. |
|
Convert SNR in dB to noise power given a signal power. |
|
Convert an input data into a torch.Tensor, with an option to move it to a specific device. |
Snr
Utility functions for Signal-to-Noise Ratio (SNR) calculations and conversions.
Add Gaussian noise to achieve a target Signal-to-Noise Ratio. |
|
Calculate the SNR between original and noisy signals. |
|
Estimate the power of a signal. |
|
Calculate SNR in dB given signal and noise power. |
|
Convert Signal-to-Noise Ratio from decibel to linear scale. |
|
Convert Signal-to-Noise Ratio from linear scale to decibels. |
|
Convert SNR in dB to noise power given a signal power. |
Training
Kaira training module.
This module provides training infrastructure for communication models, including: - TrainingArguments: Flexible training arguments supporting multiple config systems - Trainer: Unified trainer for all communication models
- Examples:
Basic usage with TrainingArguments: >>> from kaira.training import TrainingArguments, Trainer >>> args = TrainingArguments(output_dir=”./results”, num_train_epochs=10) >>> trainer = Trainer(model, args)
Using Hydra configurations: >>> args = TrainingArguments.from_hydra(hydra_config) >>> trainer = Trainer.from_hydra_config(hydra_config, model)
Direct dict configurations: >>> args = TrainingArguments.from_dict({“output_dir”: “./results”}) >>> trainer = Trainer(model, args)
Unified trainer for all communication models. |
|
Training arguments that support Hydra configuration management. |