Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/sionna/sys/effective_sinr.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ def call(
# [..., num_ut, num_streams_per_ut]
# If per_stream is False: n. used subcarriers and layers per rx
# [..., num_ut]
num_used_res = (sinr > 0).to(self.dtype).sum(dim=axis)
used_res = sinr > 0
num_used_res = used_res.to(self.dtype).sum(dim=axis)

# Ensure MCS is non-negative (for non-scheduled UTs)
mcs_index = torch.maximum(mcs_index, torch.tensor(0, device=self.device))
Expand All @@ -415,16 +416,15 @@ def call(
# [..., num_ut, 1, 1, 1]
beta_expand1 = expand_to_rank(beta, sinr.dim(), axis=-1)

# Exponentiate SINR
# [..., num_ut, num_streams_per_ut, num_ofdm_symbols, num_subcarriers]
sinr_exp = torch.where(sinr > 0, torch.exp(-sinr / beta_expand1), torch.tensor(0.0, device=self.device))

# Log + average across resources
sinr_eff = torch.log(sinr_exp.sum(dim=axis) / num_used_res)
beta_expand2 = expand_to_rank(beta, sinr_eff.dim(), axis=-1)
# Average in log space to avoid underflow at high SINR.
scaled_sinr = torch.where(used_res, -sinr / beta_expand1, -torch.inf)
log_mean_exp = torch.logsumexp(scaled_sinr, dim=axis) - torch.log(
num_used_res.clamp_min(1)
)
beta_expand2 = expand_to_rank(beta, log_mean_exp.dim(), axis=-1)
# If per_stream is True: [..., num_ut, num_streams_per_ut]
# If per_stream is False: [..., num_ut]
sinr_eff = -beta_expand2 * sinr_eff
sinr_eff = -beta_expand2 * log_mean_exp

# Project sinr_eff within [self._sinr_eff_min, self._sinr_eff_max]
sinr_eff = torch.clamp(sinr_eff, self._sinr_eff_min, self._sinr_eff_max)
Expand Down
16 changes: 16 additions & 0 deletions test/unit/sys/test_effective_sinr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ def get_sinr_eff_numpy(
class TestEffectiveSINR:
"""Tests for the EESM effective SINR computation."""

@pytest.mark.parametrize("precision", ["single", "double"])
@pytest.mark.parametrize("per_stream", [False, True])
def test_high_sinr_does_not_underflow(self, device, precision, per_stream):
"""Equal high SINRs should survive aggregation and resource masking."""
eesm = EESM(sinr_eff_max_db=50.0, precision=precision, device=device)
high_sinr = 10_000.0 # 40 dB
sinr = torch.full((1, 2, 3, 2, 2), high_sinr, dtype=eesm.dtype, device=device)
sinr[..., 1, :] = 0.0 # The second user has no allocated resources.
sinr[:, 0, :, 0, 1] = 0.0 # The first user's second stream is partly allocated.

actual = eesm(sinr, mcs_index=2, mcs_table_index=2, per_stream=per_stream)
expected = sinr.new_tensor(
[[[high_sinr, high_sinr], [0.0, 0.0]]] if per_stream else [[high_sinr, 0.0]]
)
torch.testing.assert_close(actual, expected)

def test_unused_resources_return_zero(self, device):
"""Unused users and streams remain zero below the clamp floor."""
eff_sinr_obj = EESM(device=device)
Expand Down