PlotBER#

class sionna.phy.utils.PlotBER(title: str = 'Bit/Block Error Rate')[source]#

Bases: object

Provides a plotting object to simulate and store BER/BLER curves.

Parameters:

title (str) – Figure title.

Inputs:
  • snr_dbnumpy.ndarray or list of numpy.ndarray. SNR values.

  • bernumpy.ndarray or list of numpy.ndarray. BER values corresponding to snr_db.

  • legendstr or list of str. Legend entries.

  • is_blerbool or list of bool. If True, ber will be interpreted as BLER.

  • show_berbool. If True, BER curves will be plotted.

  • show_blerbool. If True, BLER curves will be plotted.

  • xlimNone | (float, float). x-axis limits.

  • ylimNone | (float, float). y-axis limits.

  • save_figbool. If True, the figure is saved as .png.

  • pathstr. Path to save the figure if save_fig is True.

Examples

import numpy as np
from sionna.phy.utils import PlotBER

ber_plot = PlotBER(title="My BER Plot")
snr = np.array([0, 2, 4, 6, 8])
ber = np.array([0.1, 0.05, 0.01, 0.001, 0.0001])
ber_plot.add(snr, ber, legend="Curve 1")
ber_plot()  # Display the plot

Attributes

property title: str#

Get/set title of the plot.

property ber: List[numpy.ndarray]#

Stored BER/BLER values.

property snr: List[numpy.ndarray]#

Stored SNR values.

property legend: List[str]#

Legend entries.

property is_bler: List[bool]#

Indicates if a curve shall be interpreted as BLER.

Methods

simulate(mc_fun: Callable, ebno_dbs: torch.Tensor, batch_size: int, max_mc_iter: int, legend: str = '', add_ber: bool = True, add_bler: bool = False, 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, add_results: bool = True, forward_keyboard_interrupt: bool = True, show_fig: bool = True, verbose: bool = True) Tuple[torch.Tensor, torch.Tensor][source]#

Simulate BER/BLER curves for a given model and saves the results.

Internally calls sionna.phy.utils.sim_ber().

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) – SNR points to be evaluated.

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

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

  • legend (str) – Name to appear in legend.

  • add_ber (bool) – If True, BER will be added to plot.

  • add_bler (bool) – If True, BLER will be added to plot.

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

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

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

  • 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.

  • 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.

  • 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).

  • compile_mode (str | None) – Compilation mode for mc_fun. If None, mc_fun is executed as is. Options: None, "default", "reduce-overhead", "max-autotune".

  • add_results (bool) – If True, the simulation results will be appended to the internal list of results.

  • 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.

  • show_fig (bool) – If True, a BER figure will be plotted.

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

Outputs:
  • bertorch.float. Simulated bit-error rates.

  • blertorch.float. Simulated block-error rates.

add(ebno_db: numpy.ndarray, ber: numpy.ndarray, is_bler: bool = False, legend: str = '') None[source]#

Add static reference curves.

Parameters:
  • ebno_db (numpy.ndarray) – SNR points.

  • ber (numpy.ndarray) – BER corresponding to each SNR point.

  • is_bler (bool) – If True, ber is interpreted as BLER.

  • legend (str) – Legend entry.

reset() None[source]#

Remove all internal data.

remove(idx: int = -1) None[source]#

Remove curve with index idx.

Parameters:

idx (int) – Index of the dataset that should be removed. Negative indexing is possible.