config.py (1744B)
1 # 2 # SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 # SPDX-License-Identifier: Apache-2.0 4 # 5 """Abstract class for configuration of Sionna's (NR) sub-package. 6 """ 7 8 from abc import ABC 9 import copy 10 import numpy as np 11 12 class Config(ABC): 13 # pylint: disable=line-too-long 14 """Abstract configuration class for the nr (5G) sub-package of the Sionna library. 15 """ 16 def __init__(self, **kwargs): 17 for key, value in kwargs.items(): 18 if key in dir(self): 19 setattr(self, key, value) 20 21 def _ifndef(self, name, value): 22 if not hasattr(self, f"_{name}"): 23 setattr(self, f"_{name}", value) 24 25 def clone(self, deep=True): 26 """Returns a copy of the Config object 27 28 Input 29 ----- 30 deep : bool 31 If `True`, a deep copy will be returned. 32 Defaults to `True`. 33 """ 34 if deep: 35 return copy.deepcopy(self) 36 else: 37 return copy.copy(self) 38 39 def check_config(self): 40 pass 41 42 def show(self): 43 """Print all properties of a configuration""" 44 self.check_config() 45 print(self._name) 46 print("="*len(self._name)) 47 for a in dir(self): 48 val = getattr(self, a) 49 if a[0]!="_" and a not in ["show", "name", "check_config", \ 50 "check_config_precoded", "clone", \ 51 "c_init", "dmrs", "tb", "carrier"]: 52 if a in ["dmrs_grid", "dmrs_grid_precoded", "dmrs_mask", "n"]: 53 print(f"{a} : shape {np.array(val).shape}") 54 else: 55 print(f"{a} : {val}") 56 print("\r")