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. |
|
A registry for models in Kaira. |
|
A model simulating a Multiple Access Channel (MAC). |
|
A model for Wyner-Ziv coding with decoder side information. |
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. |
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.
Decoders
BlockDecoder: Base class for all block code decoders
SyndromeLookupDecoder: Decoder using syndrome lookup tables for efficient error correction
BerlekampMasseyDecoder: Implementation of Berlekamp-Massey algorithm for decoding BCH and Reed-Solomon codes
ReedMullerDecoder: Implementation of Reed-Muller decoding algorithm for Reed-Muller codes
WagnerSoftDecisionDecoder: Implementation of Wagner’s soft-decision decoder for single-parity check codes
BruteForceMLDecoder: Maximum likelihood decoder that searches through all possible codewords
BeliefPropagationDecoder: Implementation of belief propagation algorithm [Kschischang et al., 2002] for decoding LDPC codes
MinSumLDPCDecoder: Min-Sum decoder [Chen et al., 2005] for LDPC codes with reduced computational complexity
These decoders can be used to recover original messages from possibly corrupted codewords that have been transmitted over noisy channels. Each decoder has specific strengths and is optimized for particular types of codes or error patterns.
Examples
>>> 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, including: - Block codes: Fundamental error correction codes that operate on fixed-size blocks - Linear block codes: Codes with linear algebraic structure allowing matrix operations - LDPC codes: Low-Density Parity-Check codes with sparse parity-check matrices - Cyclic codes: Special class of linear codes with cyclic shift properties - BCH codes: Powerful algebraic codes with precise error-correction capabilities - Reed-Solomon codes: Widely-used subset of BCH codes for burst error correction - Hamming codes: Simple single-error-correcting codes with efficient implementation - Repetition codes: Basic codes that repeat each bit multiple times - Golay codes: Perfect codes with specific error correction properties - Single parity-check codes: Simple error detection through parity bit addition
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 [Lin and Costello, 2004, Moon, 2005].
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. |
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. |
|
Discrete Task-Oriented Deep JSCC encoder. |
|
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. |
|
Neural network-based image compression model. |
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. |
Adversarial
Adversarial Losses module for Kaira.
This module contains various adversarial loss functions for GAN-based training.
Feature Matching Loss Module for GANs. |
|
Hinge Loss Module for GANs. |
|
Least Squares GAN Loss Module. |
|
R1 Gradient Penalty Module for GANs. |
|
Vanilla GAN Loss Module. |
|
Wasserstein GAN Loss Module. |
Audio
Audio Losses module for Kaira.
This module contains various loss functions for training audio-based communication systems.
Audio Contrastive Loss Module. |
|
Feature Matching Loss Module. |
|
L1 Audio Loss Module. |
|
Log STFT Magnitude Loss Module. |
|
Mel-Spectrogram Loss Module. |
|
Multi-Resolution STFT Loss Module. |
|
STFT Loss Module. |
|
Spectral Convergence Loss Module. |
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. |
Multimodal
Multimodal Losses module for Kaira.
This module contains various loss functions for training multimodal systems.
Alignment Loss for multimodal embeddings. |
|
Cross-Modal Consistency Loss Module. |
|
Contrastive Loss Module. |
|
InfoNCE Loss Module for multimodal contrastive learning. |
|
Triplet Loss Module for multimodal data. |
Text
Text Losses module for Kaira.
This module contains various loss functions for training text-based systems.
Cosine Similarity Loss Module. |
|
Cross Entropy Loss Module. |
|
Label Smoothing Loss Module. |
|
Word2Vec Loss Module. |
Data
Data utilities for Kaira, including data generation and correlation models.
Dataset of randomly generated binary tensors. |
|
Dataset of uniformly distributed random tensors. |
|
Dataset for Wyner-Ziv coding scenarios with correlated sources. |
Create a random binary tensor with specified probability of 1s. |
|
Create a tensor with uniformly distributed random values. |
|
Load sample images from popular datasets for demonstrations. |
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. |
|
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. |
Benchmarks
Kaira Benchmarking System.
This module provides standardized benchmarks for evaluating communication system components and deep learning models in Kaira.
Base class for all benchmarks. |
|
Configuration for benchmark execution. |
|
Registry for managing benchmark classes and instances. |
|
Container for benchmark results. |
|
Manages benchmark results with improved directory structure and organization. |
|
Collection of benchmarks that can be run together. |
|
Visualizer for benchmark results. |
|
Runner for comparing multiple benchmarks on the same task. |
|
Parallel benchmark runner using thread pool. |
|
Runner for sweeping parameters across benchmarks. |
|
Collection of standard metrics for communication system evaluation. |
|
Standard sequential benchmark runner. |
Create an instance of a registered benchmark. |
|
Get a registered benchmark class. |
|
Get a predefined configuration. |
|
List all available benchmark names. |
|
List available predefined configurations. |
|
Decorator to register a benchmark class. |