NVlabs / sionna

Sionna: An Open-Source Library for Next-Generation Physical Layer Research
https://nvlabs.github.io/sionna
Other
787 stars 224 forks source link

Error when using LMMSE Equalizer function #123

Closed neilb22 closed 1 year ago

neilb22 commented 1 year ago

Hi All,

I was attempting to run the Sionna Tutorial on "Part 3: Advanced Link-Level Simulations" when I encountered this error in the LMMSE Equalizer. The notebook was taken directly from the site. The Sionna version I am using is 0.14.0.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [13], in <cell line: 25>()
     23 print("Shape of h_hat: ", h_hat.shape)
     24 print("Shape of err_var: ", err_var.shape)
---> 25 x_hat, no_eff = lmmse_equ([y, h_hat, err_var, no])
     26 print("Shape of x_hat: ", x_hat.shape)
     27 print("Shape of no_eff: ", no_eff.shape)

File ~\Anaconda3\envs\Sionna\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\ofdm\equalization.py:227, in OFDMEqualizer.call(self, inputs)
    220 s = tf.cast(s, self._dtype)
    222 ############################################################
    223 ### Compute symbol estimate and effective noise variance ###
    224 ############################################################
    225 # [batch_size, num_rx, num_ofdm_symbols, num_effective_subcarriers,...
    226 #  ..., num_stream_per_rx]
--> 227 x_hat, no_eff = self._equalizer(y_dt, h_dt_desired, s)
    229 ################################################
    230 ### Extract data symbols for all detected TX ###
    231 ################################################
    232 # Transpose tensor to shape
    233 # [num_rx, num_streams_per_rx, num_ofdm_symbols,...
    234 #  ..., num_effective_subcarriers, batch_size]
    235 x_hat = tf.transpose(x_hat, [1, 4, 2, 3, 0])

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\ofdm\equalization.py:352, in LMMSEEqualizer.__init__.<locals>.equalizer(y, h, s)
    351 def equalizer(y, h, s):
--> 352     return lmmse_equalizer(y, h, s, whiten_interference)

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\mimo\equalization.py:119, in lmmse_equalizer(y, h, s, whiten_interference)
    115     g = tf.matmul(h, matrix_inv(g), adjoint_a=True)
    117 else:
    118     # Whiten channel
--> 119     y, h  = whiten_channel(y, h, s, return_s=False) # pylint: disable=unbalanced-tuple-unpacking
    121     # Compute G
    122     i = expand_to_rank(tf.eye(h.shape[-1], dtype=s.dtype), tf.rank(s), 0)

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\mimo\utils.py:343, in whiten_channel(y, h, s, return_s)
    296 r"""Whitens a canonical MIMO channel.
    297 
    298 Assume the canonical MIMO channel model
   (...)
    340     Only returned if ``return_s`` is `True`.
    341 """
    342 # Compute whitening matrix
--> 343 s_inv_1_2 = matrix_sqrt_inv(s)
    344 s_inv_1_2 = expand_to_rank(s_inv_1_2, tf.rank(h), 0)
    346 # Whiten obervation and channel matrix

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\utils\tensors.py:242, in matrix_sqrt_inv(tensor)
    216 def matrix_sqrt_inv(tensor):
    217     r""" Computes the inverse square root of a Hermitian matrix.
    218 
    219     Given a batch of Hermitian positive definite matrices
   (...)
    240         See :py:attr:`~sionna.Config.xla_compat`.
    241     """
--> 242     if sn.config.xla_compat and not tf.executing_eagerly():
    243         s, u = tf.linalg.eigh(tensor)
    245         # Compute 1/sqrt of eigenvalues

AttributeError: Exception encountered when calling layer 'lmmse_equalizer' (type LMMSEEqualizer).

module 'sionna' has no attribute 'config'

Call arguments received by layer 'lmmse_equalizer' (type LMMSEEqualizer):
  • inputs=['tf.Tensor(shape=(1, 1, 4, 14, 76), dtype=complex64)', 'tf.Tensor(shape=(1, 1, 4, 1, 1, 14, 76), dtype=complex64)', 'tf.Tensor(shape=(1, 1, 1, 1, 1, 14, 76), dtype=float32)', 'tf.Tensor(shape=(), dtype=float32)']

Any suggestions on what I should do so that I can use this equalizer?

jhoydis commented 1 year ago

Hi,

It seems that your Sionna installation does not have the config module which is strange as it is included in v0.14.

Could you run the following code and post the output?

import sionna
print(sionna.__version__)
dir(sionna)
neilb22 commented 1 year ago

Hi Jakob. Thank you for the prompt response.

This is the output that I get if I run the code you mentioned:

0.14.0
['Config',
 'DIELECTRIC_PERMITTIVITY_VACUUM',
 'H',
 'PI',
 'SPEED_OF_LIGHT',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 'channel',
 'config',
 'fec',
 'mapping',
 'mimo',
 'nr',
 'ofdm',
 'rt',
 'signal',
 'utils']
jhoydis commented 1 year ago

Hm, this is strange. It should work. Are you running the notebook without any modifications? I have just tested it locally as well as on Google Colab and cannot reproduce your error.

Could you try this code?

import sionna
import tensorflow as tf
from sionna.utils import matrix_inv
matrix_inv(tf.eye(5))
neilb22 commented 1 year ago

I didn't modify it before I raised the issue here. But, just to be sure, I re-downloaded the notebook and tried again. The config error still shows up for the Equalizer.

For the code you shared, I get an output:

<tf.Tensor: shape=(5, 5), dtype=float32, numpy=
array([[1., 0., 0., 0., 0.],
       [0., 1., 0., 0., 0.],
       [0., 0., 1., 0., 0.],
       [0., 0., 0., 1., 0.],
       [0., 0., 0., 0., 1.]], dtype=float32)>

This may or may not be relevant, but when I installed 0.14.0, the earlier version of Sionna (0.13.1 I think) was still there. So I did a "pip uninstall sionna", which removed the older version but kept 0.14.0. Maybe that is the reason? Uninstalling it may have affected the config file in some way, but this is an assumption, and I could be totally wrong.

Would uninstalling and re-installing Sionna fix this issue?

jhoydis commented 1 year ago

There is no config file or anything like this. The config module has a variable that determines how certain functions are implemented depending on the execution mode (eager, graph, XLA).

I would simply do a clean installation and a new enviroment.

BTW, could you run this code snippet :

import sionna
import tensorflow as tf
from sionna.utils import matrix_sqrt_inv
matrix_sqrt_inv(tf.eye(5))
neilb22 commented 1 year ago

I see. Thank you for the explanation. I will set up a new environment and do a fresh installation then.

I get the following message for the code you shared:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [20], in <cell line: 4>()
      2 import tensorflow as tf
      3 from sionna.utils import matrix_sqrt_inv
----> 4 matrix_sqrt_inv(tf.eye(5))

File ~\Anaconda3\envs\Sionna\lib\site-packages\sionna\utils\tensors.py:242, in matrix_sqrt_inv(tensor)
    216 def matrix_sqrt_inv(tensor):
    217     r""" Computes the inverse square root of a Hermitian matrix.
    218 
    219     Given a batch of Hermitian positive definite matrices
   (...)
    240         See :py:attr:`~sionna.Config.xla_compat`.
    241     """
--> 242     if sn.config.xla_compat and not tf.executing_eagerly():
    243         s, u = tf.linalg.eigh(tensor)
    245         # Compute 1/sqrt of eigenvalues

AttributeError: module 'sionna' has no attribute 'config'

Kind regards, Neil

jhoydis commented 1 year ago

So, there is something strange going on with your installation. When you run dir(sionna), you see the config module but then your code says that I cannot find it. A fresh installation should solve this.

neilb22 commented 1 year ago

I did a fresh installation in a new environment. I now get a different error related to the LLVM backend being inactive, similar to #107 . This is after following the installation steps that were mentioned in the Sionna documentation (pip install --upgrade ipykernel thing) and restarting the Jupyter notebook.

Since that is different from this issue, should I close this issue? The LMMSE Equalizer still shows throws the Attribute error, but all cells before that seem to work.

rahmanhabib010 commented 3 months ago

I also tried to run "5G_NR_PUSCH.ipynb" installing "sionna" in local environment and faced the same issue. Later, I uninstalled the "sionna" module and run"5G_NR_PUSCH.ipynb" downloading source code. It works for me.