sim_ber#

sionna.phy.utils.sim_ber(mc_fun: Callable, ebno_dbs: torch.Tensor, batch_size: int, max_mc_iter: int, soft_estimates: bool = False, num_target_bit_errors: int | None = None, num_target_block_errors: int | None = None, target_ber: float | None = None, target_bler: float | None = None, early_stop: bool = True, compile_mode: str | None = None, verbose: bool = True, forward_keyboard_interrupt: bool = True, callback: Callable | None = None, precision: Literal['single', 'double'] | None = None, device: str | None = None) Tuple[torch.Tensor, torch.Tensor][source]#

Simulates until target number of errors is reached and returns BER/BLER.

The simulation continues with the next SNR point if either num_target_bit_errors bit errors or num_target_block_errors block errors is achieved. Further, it continues with the next SNR point after max_mc_iter batches of size batch_size have been simulated. Early stopping allows to stop the simulation after the first error-free SNR point or after reaching a certain target_ber or target_bler.

Parameters:
  • mc_fun (Callable) – Callable that yields the transmitted bits b and the receiver’s estimate b_hat for a given batch_size and ebno_db. If soft_estimates is True, b_hat is interpreted as logit.

  • ebno_dbs (torch.Tensor) – A tensor containing SNR points to be evaluated.

  • batch_size (int) – Batch-size for evaluation.

  • max_mc_iter (int) – Maximum number of Monte-Carlo iterations per SNR point.

  • soft_estimates (bool) – If True, b_hat is interpreted as logit and an additional hard-decision is applied internally. Defaults to False.

  • num_target_bit_errors (int | None) – Target number of bit errors per SNR point until the simulation continues to next SNR point. Defaults to None.

  • num_target_block_errors (int | None) – Target number of block errors per SNR point until the simulation continues. Defaults to None.

  • target_ber (float | None) – The simulation stops after the first SNR point which achieves a lower bit error rate as specified by target_ber. This requires early_stop to be True. Defaults to None.

  • target_bler (float | None) – The simulation stops after the first SNR point which achieves a lower block error rate as specified by target_bler. This requires early_stop to be True. Defaults to None.

  • early_stop (bool) – If True, the simulation stops after the first error-free SNR point (i.e., no error occurred after max_mc_iter Monte-Carlo iterations). Defaults to True.

  • compile_mode (str | None) – A string describing the compilation mode of mc_fun. If None, mc_fun is executed as is. Options: None, “default”, “reduce-overhead”, “max-autotune”.

  • verbose (bool) – If True, the current progress will be printed. Defaults to True.

  • forward_keyboard_interrupt (bool) – If False, KeyboardInterrupts will be caught internally and not forwarded (e.g., will not stop outer loops). If True, the simulation ends and returns the intermediate simulation results. Defaults to True.

  • callback (Callable | None) – If specified, callback will be called after each Monte-Carlo step. Can be used for logging or advanced early stopping. Input signature of callback must match callback(mc_iter, snr_idx, ebno_dbs, bit_errors, block_errors, nb_bits, nb_blocks) where mc_iter denotes the number of processed batches for the current SNR point, snr_idx is the index of the current SNR point, ebno_dbs is the vector of all SNR points to be evaluated, bit_errors the vector of number of bit errors for each SNR point, block_errors the vector of number of block errors, nb_bits the vector of number of simulated bits, nb_blocks the vector of number of simulated blocks, respectively. If callback returns sim_ber.CALLBACK_NEXT_SNR, early stopping is detected and the simulation will continue with the next SNR point. If callback returns sim_ber.CALLBACK_STOP, the simulation is stopped immediately. For sim_ber.CALLBACK_CONTINUE continues with the simulation.

  • precision (Literal['single', 'double'] | None) – Precision used for internal calculations and outputs. If set to None, precision is used.

  • device (str | None) – Device for computation. If None, device is used.

Outputs:
  • ber – [n], torch.float. Bit-error rate.

  • bler – [n], torch.float. Block-error rate.

Examples

import torch
from sionna.phy.utils import sim_ber

def mc_fun(batch_size, ebno_db):
    # Simple example: generate random bits and add noise
    b = torch.randint(0, 2, (batch_size, 100))
    b_hat = b.clone()  # Perfect decoding for demo
    return b, b_hat

ebno_dbs = torch.linspace(0, 10, 5)
ber, bler = sim_ber(mc_fun, ebno_dbs, batch_size=100, max_mc_iter=10)