Repository navigation
Expand file tree
/
Copy pathevaluate.py
More file actions
executable file
·359 lines (315 loc) · 15.5 KB
/
Copy pathevaluate.py
File metadata and controls
executable file
·359 lines (315 loc) · 15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/python3
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
# evaluate BLER of NRX and baseline systems
# results are saved in files and can be visualized with the corresponding
# jupyter notebooks
####################################################################
# Parse args
####################################################################
import argparse
parser = argparse.ArgumentParser()
# the config defines the sys parameters
parser.add_argument("-config_name", help="config filename", type=str)
# limits the number of target of block errors during the simulation
parser.add_argument("-num_target_block_errors",
help="Number of target block errors", type=int, default=500)
parser.add_argument("-max_mc_iter",
help="Maximum Monte Carlo iterations",
type=int, default=500)
parser.add_argument("-target_bler",
help="Early stop BLER simulations at a specific target BLER",
type=float, default=0.001)
parser.add_argument("-num_cov_samples",
help="Number of samples for covariance generation", type=int, default=100000)
parser.add_argument("-gpu", help="GPU to use", type=int, default=0)
parser.add_argument("-num_tx_eval",
help="Number of active users",
type=int, nargs='+', default=-1)
parser.add_argument("-mcs_arr_eval_idx",
help="Select the MCS array index for evaluation. Use -1 to evaluate all MCSs.", type=int, default=-1)
parser.add_argument("-eval_nrx_only", help="Only evaluate the NN",
action="store_true", default=False)
parser.add_argument("-debug", help="Set debugging configuration", action="store_true", default=False)
# Parse all arguments
args = parser.parse_args()
config_name = args.config_name
max_mc_iter = args.max_mc_iter
num_target_block_errors = args.num_target_block_errors
eval_nrx_only = args.eval_nrx_only
num_cov_samples = args.num_cov_samples
gpu = args.gpu
target_bler = args.target_bler
num_tx_eval = args.num_tx_eval
mcs_arr_eval_idx = args.mcs_arr_eval_idx
distribute = None # use "all" to distribute over multiple GPUs
####################################################################
# Imports and GPU configuration
####################################################################
import os
# Avoid warnings from TensorFlow
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.get_logger().setLevel('ERROR')
gpus = tf.config.list_physical_devices('GPU')
if distribute != "all":
try:
tf.config.set_visible_devices(gpus[args.gpu], 'GPU')
print('Only GPU number', args.gpu, 'used.')
tf.config.experimental.set_memory_growth(gpus[args.gpu], True)
except RuntimeError as e:
print(e)
import sys
sys.path.append('../')
import sionna as sn
from sionna.utils import sim_ber
from utils import E2E_Model, Parameters, load_weights
import numpy as np
import pickle
from os.path import exists
if args.debug:
tf.config.run_functions_eagerly(True)
##################################################################
# Run evaluations
##################################################################
# dummy parameters to access filename and to load results
sys_parameters = Parameters(config_name,
training=True,
system='dummy') # dummy system only to load config
# two different batch sizes can be configured
# the small one is used for the highly complex K-best-based receivers
# otherwise OOM errors occur
batch_size = sys_parameters.batch_size_eval
batch_size_small = sys_parameters.batch_size_eval_small
# results are directly saved in files
results_filename = f"{sys_parameters.label}_results"
results_filename = "../results/" + results_filename
if exists(results_filename):
print(f"### File '{results_filename}' found. " \
"It will be updated with the new results.")
with open(results_filename, 'rb') as f:
ebno_db, BERs, BLERs = pickle.load(f)
else:
print(f"### No file '{results_filename}' found. One will be created.")
ebno_db = np.arange(sys_parameters.snr_db_eval_min,
sys_parameters.snr_db_eval_max,
sys_parameters.snr_db_eval_stepsize)
BERs = {}
BLERs = {}
# evaluate for different number of active transmitters
if num_tx_eval == -1:
num_tx_evals = np.arange(sys_parameters.min_num_tx,
sys_parameters.max_num_tx+1, 1)
else:
if isinstance(num_tx_eval, int):
num_tx_evals = [num_tx_eval]
elif isinstance(num_tx_eval, (list, tuple)):
num_tx_evals = num_tx_eval
else:
raise ValueError("num_tx_eval must be int or list of ints.")
if mcs_arr_eval_idx == -1:
mcs_arr_eval_idxs = list(range(len(sys_parameters.mcs_index)))
else:
if isinstance(mcs_arr_eval_idx, int):
mcs_arr_eval_idxs = [mcs_arr_eval_idx]
elif isinstance(mcs_arr_eval_idx, (list, tuple)):
mcs_arr_eval_idxs = mcs_arr_eval_idx
else:
raise ValueError("mcs_arr_eval_idx must be int or list of ints.")
print(f"Evaluating for {num_tx_evals} active users and mcs_index elements {mcs_arr_eval_idxs}.")
# the evaluation can loop over multiple number of active DMRS ports / users
for num_tx_eval in num_tx_evals:
# Generate covariance matrices for LMMSE-based baselines
if not eval_nrx_only:
print("Generating cov matrix.")
os.system(f"python compute_cov_mat.py -config_name {config_name} -gpu {gpu} -num_samples {num_cov_samples} -num_tx_eval {num_tx_eval}")
# Loop over all evaluation MCS indices
for mcs_arr_eval_idx in mcs_arr_eval_idxs:
#
# Neural receiver
#
sn.Config.xla_compat = True
sys_parameters = Parameters(config_name,
training=False,
num_tx_eval=num_tx_eval,
system='nrx')
# check channel types for consistency
if sys_parameters.channel_type == 'TDL-B100':
assert num_tx_eval == 1,\
"Channel model 'TDL-B100' only works with one transmitter"
elif sys_parameters.channel_type in ("DoubleTDLlow", "DoubleTDLmedium",
"DoubleTDLhigh"):
assert num_tx_eval == 2,\
"Channel model 'DoubleTDL' only works with two transmitters exactly"
e2e_nn = E2E_Model(sys_parameters, training=False, mcs_arr_eval_idx=mcs_arr_eval_idx)
print("\nRunning: " + sys_parameters.system)
# Run once and load the weights
e2e_nn(1, 1.)
filename = f'../weights/{sys_parameters.label}_weights'
load_weights(e2e_nn, filename)
# and set number iterations for evaluation
e2e_nn._receiver._neural_rx.num_it = sys_parameters.num_nrx_iter_eval
# Start sim
ber, bler = sim_ber(e2e_nn,
graph_mode="xla",
ebno_dbs=ebno_db,
max_mc_iter=max_mc_iter,
num_target_block_errors=num_target_block_errors,
batch_size=batch_size,
distribute=distribute,
target_bler=target_bler,
early_stop=True,
forward_keyboard_interrupt=True)
BERs[e2e_nn._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
BLERs[e2e_nn._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
with open(results_filename, "wb") as f:
pickle.dump([ebno_db, BERs, BLERs], f)
sn.Config.xla_compat = False
#
# Baseline: LS estimation/lin interpolation + LMMSE detection
#
if not eval_nrx_only:
sn.Config.xla_compat = True
sys_parameters = Parameters(config_name,
training=False,
num_tx_eval=num_tx_eval,
system='baseline_lslin_lmmse')
e2e_baseline = E2E_Model(sys_parameters, training=False,
mcs_arr_eval_idx=mcs_arr_eval_idx)
print("\nRunning: " + sys_parameters.system)
ber, bler = sim_ber(e2e_baseline,
graph_mode="xla",
ebno_dbs=ebno_db,
max_mc_iter=max_mc_iter,
num_target_block_errors=num_target_block_errors,
target_bler=target_bler,
batch_size=batch_size,
distribute=distribute,
early_stop=True,
forward_keyboard_interrupt=True)
BERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
BLERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
with open(results_filename, "wb") as f:
pickle.dump([ebno_db, BERs, BLERs], f)
sn.Config.xla_compat = False
else:
print("skipping LSlin & LMMSE")
#
# Baseline: LMMSE estimation/interpolation + K-Best detection
#
if not eval_nrx_only:
sn.Config.xla_compat = False
sys_parameters = Parameters(config_name,
training=False,
num_tx_eval=num_tx_eval,
system = 'baseline_lmmse_kbest')
e2e_baseline = E2E_Model(sys_parameters, training=False,
mcs_arr_eval_idx=mcs_arr_eval_idx)
print("\nRunning: " + sys_parameters.system)
ber, bler = sim_ber(e2e_baseline,
graph_mode="graph",
ebno_dbs=ebno_db,
max_mc_iter=max_mc_iter,
num_target_block_errors=num_target_block_errors,
target_bler=target_bler,
batch_size=batch_size_small, # must be small for large PRBs
#distribute=distribute, # somehow does not compile
early_stop=True,
forward_keyboard_interrupt=True)
BERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
BLERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
with open(results_filename, "wb") as f:
pickle.dump([ebno_db, BERs, BLERs], f)
sn.Config.xla_compat = False
else:
print("skipping LMMSE & KBest")
# Uncomment to simulate other baselines
#
# Baseline: Perfect CSI + LMMSE
#
# currently not evaluated
# if not eval_nrx_only:
# sys_parameters = Parameters(config_name,
# training=False,
# num_tx_eval=num_tx_eval,
# system='baseline_perf_csi_lmmse')
# e2e_baseline = E2E_Model(sys_parameters, training=False, mcs_arr_eval_idx=mcs_arr_eval_idx)
# print("\nRunning: " + sys_parameters.system)
# ber, bler = sim_ber(e2e_baseline,
# graph_mode="graph",
# ebno_dbs=ebno_db,
# max_mc_iter=max_mc_iter, # account for reduced bs
# num_target_block_errors=num_target_block_errors,
# batch_size=batch_size, # must be small due to TF bug in K-best
# early_stop=True)
# BERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
# BLERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
# with open(results_filename, "wb") as f:
# pickle.dump([ebno_db, BERs, BLERs], f)
# else:
# print("skipping Perfect CSI & LMMSE")
#
# Baseline: LMMSE estimation/interpolation + LMMSE detection
#
# if not eval_nrx_only:
# sn.Config.xla_compat = False
# sys_parameters = Parameters(config_name,
# training=False,
# num_tx_eval=num_tx_eval,
# system='baseline_lmmse_lmmse')
# e2e_baseline = E2E_Model(sys_parameters, training=False, mcs_arr_eval_idx=mcs_arr_eval_idx)
# print("Running: " + sys_parameters.system)
# ber, bler = sim_ber(e2e_baseline,
# graph_mode="graph",
# ebno_dbs=ebno_db,
# max_mc_iter=max_mc_iter, # account for reduced bs
# num_target_block_errors=num_target_block_errors,
# #target_bler=target_bler,
# batch_size=batch_size_small, # must be small due to TF bug in K-best
# #distribute=distribute,
# early_stop=True,
# forward_keyboard_interrupt=True)
# BERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
# BLERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
# with open(results_filename, "wb") as f:
# pickle.dump([ebno_db, BERs, BLERs], f)
# sn.Config.xla_compat = False
# else:
# print("skipping LMMSE")
# sys_name = f"Baseline - LMMSE+LMMSE"
#
# Baseline: Perfect CSI + K-Best detection
#
if not eval_nrx_only:
sn.Config.xla_compat = False
sys_parameters = Parameters(config_name,
training=False,
num_tx_eval=num_tx_eval,
system='baseline_perf_csi_kbest')
e2e_baseline = E2E_Model(sys_parameters, training=False,
mcs_arr_eval_idx=mcs_arr_eval_idx)
print("\nRunning: " + sys_parameters.system)
ber, bler = sim_ber(e2e_baseline,
graph_mode="graph",
ebno_dbs=ebno_db,
max_mc_iter=max_mc_iter, # account for reduced bs
num_target_block_errors=num_target_block_errors,
target_bler=target_bler,
batch_size=batch_size_small, # must be small due to TF bug in K-best
distribute=distribute,
early_stop=True,
forward_keyboard_interrupt=True)
BERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = ber
BLERs[e2e_baseline._sys_name, num_tx_eval, mcs_arr_eval_idx] = bler
with open(results_filename, "wb") as f:
pickle.dump([ebno_db, BERs, BLERs], f)
sn.Config.xla_compat = False
else:
print("skipping Perfect CSI & K-Best")