Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sionna RT result error #400

Open
fanyimeng0 opened this issue Apr 15, 2024 · 5 comments
Open

Sionna RT result error #400

fanyimeng0 opened this issue Apr 15, 2024 · 5 comments

Comments

@fanyimeng0
Copy link

Hello,I have encountered an issue where the results of ray tracing are inconsistent under the same conditions. When using Sionna RT in Jupyter Notebook, I calculated the phase differences between each antenna for 'rx'. I found that the results of two calculations were inconsistent, despite using the exact same code. The result is shown in the attached file. Could you please help me identify why the ray tracing results vary between these two instances? Thank you for your response.
RTtest.md

@merlinND
Copy link
Collaborator

Hello @fanyimeng0,

I am pasting the contents of your report below for visibility.


%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import time
# Import Sionna RT components
from sionna.rt import load_scene, Transmitter, Receiver, PlanarArray, Camera
# For link-level simulations
from sionna.channel import cir_to_ofdm_channel, subcarrier_frequencies, OFDMChannel, ApplyOFDMChannel, CIRDataset
from sionna.nr import PUSCHConfig, PUSCHTransmitter, PUSCHReceiver
from sionna.utils import compute_ber, ebnodb2no, PlotBER
from sionna.ofdm import KBestDetector, LinearDetector
from sionna.mimo import StreamManagement
import os
gpu_num = 0 # Use "" to use the CPU
os.environ["CUDA_VISIBLE_DEVICES"] = f"{gpu_num}"
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
# Import Sionna
try:
    import sionna
except ImportError as e:
    # Install Sionna if package is not already installed
    import os
    os.system("pip install sionna")
    import sionna
# Load the required Sionna components
from sionna.nr import PUSCHConfig, PUSCHTransmitter, PUSCHReceiver
from sionna.channel import AWGN, RayleighBlockFading, OFDMChannel, TimeChannel, time_lag_discrete_time_channel
from sionna.channel.tr38901 import AntennaArray, UMi, UMa, RMa
from sionna.channel import gen_single_sector_topology as gen_topology
from sionna.utils import compute_ber, ebnodb2no, sim_ber
from sionna.ofdm import KBestDetector, LinearDetector
from sionna.mimo import StreamManagement
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import sys

from sionna.utils import BinarySource, QAMSource, ebnodb2no, compute_ser, compute_ber, PlotBER
from sionna.channel import FlatFadingChannel, KroneckerModel
from sionna.channel.utils import exp_corr_mat
from sionna.mimo import lmmse_equalizer
from sionna.mapping import SymbolDemapper, Mapper, Demapper
from sionna.fec.ldpc.encoding import LDPC5GEncoder
from sionna.fec.ldpc.decoding import LDPC5GDecoder
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pickle
import time

from sionna.mimo import StreamManagement

from sionna.ofdm import ResourceGrid, ResourceGridMapper, LSChannelEstimator, LMMSEEqualizer
from sionna.ofdm import OFDMModulator, OFDMDemodulator, ZFPrecoder, RemoveNulledSubcarriers

from sionna.channel.tr38901 import AntennaArray, CDL, Antenna
from sionna.channel import subcarrier_frequencies, cir_to_ofdm_channel, cir_to_time_channel, time_lag_discrete_time_channel
from sionna.channel import ApplyOFDMChannel, ApplyTimeChannel, OFDMChannel, TimeChannel

from sionna.fec.ldpc.encoding import LDPC5GEncoder
from sionna.fec.ldpc.decoding import LDPC5GDecoder

from sionna.mapping import Mapper, Demapper

from sionna.utils import BinarySource, ebnodb2no, sim_ber
from sionna.utils.metrics import compute_ber
import tensorflow as tf
# Configure the notebook to use only a single GPU and allocate only as much memory as needed
# For more details, see https://www.tensorflow.org/guide/gpu
gpus = tf.config.list_physical_devices('GPU')
if gpus:
    try:
        tf.config.experimental.set_memory_growth(gpus[0], True)
    except RuntimeError as e:
        print(e)
# Avoid warnings from TensorFlow
tf.get_logger().setLevel('ERROR')
scene = load_scene("../test_bg/test.xml") 
scene.remove("tx")
scene.remove("rx")
scene.tx_array = PlanarArray(num_rows=1,
                             num_cols=1,
                             vertical_spacing=0.5,
                             horizontal_spacing=0.5,
                             pattern="tr38901",
                             polarization="V")

# Configure antenna array for all receivers
scene.rx_array = PlanarArray(num_rows=9,
                             num_cols=9,
                             vertical_spacing=0.5,
                             horizontal_spacing=0.5,
                             pattern="tr38901",
                             polarization="V")

# Create transmitter
tx = Transmitter(name="tx",
                 position=[0,-10,17])

# Add transmitter instance to scene
scene.add(tx)

# Create a receiver
rx = Receiver(name="rx",
              position=[0,-10,17],
              orientation=[0,0,0])

# Add receiver instance to scene
scene.add(rx)

#tx.look_at(rx) # Transmitter points towards receiver
scene.frequency = 2.6e9 # in Hz; implicitly updates RadioMaterials
scene.synthetic_array = True # If set to False, ray tracing will be done per antenna element (slower for large arrays)
# Compute propagation paths
paths = scene.compute_paths(max_depth=2,
                            num_samples=1e6)  # Number of rays shot into directions defined
                                              # by a Fibonacci sphere , too few rays can
                                              # lead to missing paths

# Visualize paths in the 3D preview
a, tau = paths.cir()
print("Shape of `a` after applying Doppler shifts: ", paths.a.shape)
re = np.diff(np.angle(a[0,0,:,0,0,1,0]))*180/np.pi
re[re < 0] += 360
print(re)
#scene.preview(paths, show_devices=True, show_paths=True) # Use the mouse to focus on the visualized paths
Shape of `a` after applying Doppler shifts:  (1, 1, 81, 1, 1, 2, 1)
[106.611206 106.611275 106.61128  106.6113   106.61126  106.61131
 106.61127  106.61126  300.78107  106.611275 106.611275 106.61127
 106.61126  106.611275 106.61131  106.61127  106.61126  300.78104
 106.611275 106.61131  106.61125  106.61128  106.61126  106.61133
 106.61126  106.611244 300.7811   106.61124  106.6113   106.611305
 106.61125  106.61127  106.611305 106.611305 106.611244 300.78104
 106.61127  106.611275 106.61128  106.61125  106.61127  106.61131
 106.611244 106.61127  300.78104  106.61125  106.61131  106.61128
 106.61127  106.61125  106.611305 106.6113   106.611244 300.7811
 106.61126  106.611275 106.6113   106.61126  106.611275 106.6113
 106.611244 106.611275 300.78104  106.61126  106.6113   106.61128
 106.611275 106.61126  106.6113   106.611244 106.611275 300.78107
 106.611275 106.6113   106.61128  106.61126  106.6113   106.611275
 106.611275 106.611206]
scene.remove("tx")
scene.remove("rx")
scene.tx_array = PlanarArray(num_rows=1,
                             num_cols=1,
                             vertical_spacing=0.5,
                             horizontal_spacing=0.5,
                             pattern="tr38901",
                             polarization="V")

# Configure antenna array for all receivers
scene.rx_array = PlanarArray(num_rows=9,
                             num_cols=9,
                             vertical_spacing=0.5,
                             horizontal_spacing=0.5,
                             pattern="tr38901",
                             polarization="V")

# Create transmitter
tx = Transmitter(name="tx",
                 position=[0,-10,17])

# Add transmitter instance to scene
scene.add(tx)

# Create a receiver
rx = Receiver(name="rx",
              position=[0,-10,17],
              orientation=[0,0,0])

# Add receiver instance to scene
scene.add(rx)

#tx.look_at(rx) # Transmitter points towards receiver
scene.frequency = 2.6e9 # in Hz; implicitly updates RadioMaterials
scene.synthetic_array = True # If set to False, ray tracing will be done per antenna element (slower for large arrays)
# Compute propagation paths
paths = scene.compute_paths(max_depth=2,
                            num_samples=1e6)  # Number of rays shot into directions defined
                                              # by a Fibonacci sphere , too few rays can
                                              # lead to missing paths

# Visualize paths in the 3D preview
a, tau = paths.cir()
print("Shape of `a` after applying Doppler shifts: ", paths.a.shape)
re = np.diff(np.angle(a[0,0,:,0,0,1,0]))*180/np.pi
re[re < 0] += 360
print(re)
#scene.preview(paths, show_devices=True, show_paths=True) # Use the mouse to focus on the visualized paths
Shape of `a` after applying Doppler shifts:  (1, 1, 81, 1, 1, 2, 1)
[143.51534  143.51512  143.51521  143.51517  143.51523  143.51517
 143.51524  143.51515   31.051336 143.51517  143.51517  143.5152
 143.51518  143.5152   143.51518  143.51526  143.51515   31.051294
 143.51517  143.51517  143.51523  143.5152   143.51521  143.51518
 143.51524  143.51518   31.05131  143.51524  143.51508  143.51523
 143.5152   143.51521  143.51517  143.51526  143.51515   31.05129
 143.51521  143.51518  143.5152   143.5152   143.51521  143.51517
 143.51526  143.51517   31.051292 143.51517  143.51521  143.5152
 143.51518  143.5152   143.51515  143.51521  143.51517   31.051323
 143.51518  143.5152   143.51518  143.51521  143.5152   143.51518
 143.51527  143.5151    31.05133  143.51521  143.51518  143.51518
 143.51521  143.51517  143.5152   143.51529  143.51517   31.051224
 143.51521  143.51518  143.5152   143.51523  143.51517  143.51517
 143.51529  143.51521 ]

@jhoydis
Copy link
Collaborator

jhoydis commented Apr 23, 2024

Hi @fanyimeng0,

I was trying to look into your issue but I do not have access to the scene that you are using.
Could you please provide a minimal code example reproducing the issue, using one of the scenes integrated with Sionna?

@fanyimeng0
Copy link
Author

Hello,I reproduced this issue in sionna.rt.scene.munich. The third code cell in the Jupyter notebook is the same as the second one. I'm running the same code twice to demonstrate that the same code can lead to different results. The printed results are the phase difference between antennas.

`a, tau = paths.cir()

print("Shape of a : ", paths.a.shape)

re = np.diff(np.angle(a[0,0,:,0,0,1,0]))*180/np.pi

re[re < 0] += 360

print(re)`

And the attacked file is the result in munich scene.
RTtest.md

@faycalaa
Copy link
Collaborator

Hi,

The reason you observe different outputs is because the frequency is set before defining the antenna arrays in your code, leading to using an antenna spacing that does not match the frequency you set but the default one in the first run.
Setting the frequency before defining the antenna arrays should ensure that the correct frequency is used.

@fanyimeng0
Copy link
Author

Hi,

The reason you observe different outputs is because the frequency is set before defining the antenna arrays in your code, leading to using an antenna spacing that does not match the frequency you set but the default one in the first run. Setting the frequency before defining the antenna arrays should ensure that the correct frequency is used.

Thanks for your response. Setting frequency correctly works well. But I find the tutorial Sionna_Ray_Tracing_Introduction have the same problem, scene.frequency is defined before antenna array. Therefore I suggest changing this tutorial or making a modification if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants