pbar = progressbar.ProgressbarText( rep_max, message="Simulating for SNR: {0}".format(SNR_dB)) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Dependent parameters (don't change these) xxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Path loss (in linear scale) from the cell center to path_loss_border = path_loss_obj.calc_path_loss(cell_radius) noise_var = conversion.dBm2Linear(N0_dBm) snr = conversion.dB2Linear(SNR_dB) transmit_power = snr * noise_var / path_loss_border # External interference power pe = conversion.dBm2Linear(Pe_dBm) # Cell Grid cell_grid = cell.Grid() cell_grid.create_clusters(num_clusters, num_cells, cell_radius) # noinspection PyProtectedMember cluster0 = cell_grid._clusters[0] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Create the scenario xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx cell_ids = np.arange(1, num_cells + 1) angles = np.array([210, -30, 90]) cluster0.delete_all_users() cluster0.add_border_users(cell_ids, angles, 0.7) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
def __init__(self, read_command_line_args=True, save_parsed_file=False): default_config_file = 'bd_config_file.txt' # xxxxxxxxxx Simulation Parameters Specification xxxxxxxxxxxxxxxxxx spec = """[Grid] cell_radius=float(min=0.01, default=1.0) num_cells=integer(min=3,default=3) num_clusters=integer(min=1,default=1) [Scenario] NSymbs=integer(min=10, max=1000000, default=500) SNR=real_numpy_array(min=-50, max=100, default=0:3:31) Pe_dBm=real_numpy_array(min=-50, max=100, default=[-10. 0. 10.]) Nr=integer(default=2) Nt=integer(default=2) N0=float(default=-116.4) ext_int_rank=integer(min=1,default=1) user_positioning_method=option("Random", 'Symmetric Far Away', default="Symmetric Far Away") [Modulation] M=integer(min=4, max=512, default=4) modulator=option('QPSK', 'PSK', 'QAM', 'BPSK', default="PSK") packet_length=integer(min=1,default=60) [General] rep_max=integer(min=1, default=5000) unpacked_parameters=string_list(default=list('SNR','Pe_dBm')) """.split("\n") # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Initialize parameters configuration xxxxxxxxxxxxxxxxxx # Among other things, this will create the self.params object with # the simulation parameters read from the config file. SimulationRunner.__init__( self, default_config_file=default_config_file, config_spec=spec, read_command_line_args=read_command_line_args, save_parsed_file=save_parsed_file) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Channel Parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx self.path_loss_obj = pathloss.PathLoss3GPP1() self.multiuser_channel = multiuser.MultiUserChannelMatrixExtInt() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx RandomState objects seeds xxxxxxxxxxxxxxxxxxxxxxxxxxxx # This is only useful to reproduce a simulation for debugging # purposed channel_seed = None # 22522 self.noise_seed = None # 4445 self.data_gen_seed = np.random.randint(10000) # 2105 ext_data_gen_seed = None # 6114 # self.multiuser_channel.set_channel_seed(channel_seed) self.multiuser_channel.set_noise_seed(self.noise_seed) self.data_RS = np.random.RandomState(self.data_gen_seed) self.ext_data_RS = np.random.RandomState(ext_data_gen_seed) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Creates the modulator object xxxxxxxxxxxxxxxxxxxxxxxxx M = self.params['M'] modulator_options = { 'PSK': fundamental.PSK, 'QPSK': fundamental.QPSK, 'QAM': fundamental.QAM, 'BPSK': fundamental.BPSK } self.modulator = modulator_options[self.params['modulator']](M) ":type: fundamental.PSK | fundamental.QPSK | fundamental.QAM | fundamental.BPSK" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx General Parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Maximum number of repetitions for each unpacked parameters set # self.params self.results self.rep_max = self.params['rep_max'] # # max_bit_errors is used in the _keep_going method to stop the # # simulation earlier if possible. We stop the simulation if the # # accumulated number of bit errors becomes greater then 5% of the # # total number of simulated bits # self.max_bit_errors = self.rep_max * NSymbs * 5. / 100. self.progressbar_message = "SNR: {SNR}, Pe_dBm: {Pe_dBm}" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Dependent parameters (don't change these) xxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # These two will be set in the _on_simulate_current_params_start # method self.pe = 0 # Path loss (in linear scale) from the cell center to # self.path_loss_border = self.path_loss_obj.calc_path_loss( # self.cell_radius) # Cell Grid self.cell_grid = cell.Grid() self.cell_grid.create_clusters(self.params['num_clusters'], self.params['num_cells'], self.params['cell_radius']) self.noise_var = dBm2Linear(self.params['N0']) self.multiuser_channel.noise_var = self.noise_var # This can be either 'screen' or 'file'. If it is 'file' then the # progressbar will write the progress to a file with appropriated # filename self.progress_output_type = 'screen'
def __init__(self, default_config_file, read_command_line_args=True): """ Constructor of the IASimulationRunner class. """ spec = """[Grid] cell_radius=float(min=0.01, default=1.0) num_cells=integer(min=3,default=3) num_clusters=integer(min=1,default=1) [Scenario] NSymbs=integer(min=10, max=1000000, default=200) SNR=real_numpy_array(min=-50, max=100, default=0:5:31) M=integer(min=4, max=512, default=4) modulator=option('QPSK', 'PSK', 'QAM', 'BPSK', default="PSK") Nr=integer_scalar_or_integer_numpy_array_check(min=2,default=3) Nt=integer_scalar_or_integer_numpy_array_check(min=2,default=3) Ns=integer_scalar_or_integer_numpy_array_check(min=1,default=3) N0=float(default=-116.4) scenario=string_list(default=list('Random', 'NoPathLoss')) [IA Algorithm] max_iterations=integer(min=1, default=120) initialize_with=string_list(default=list('random')) stream_sel_method=string_list(default=list('greedy', 'brute')) [General] rep_max=integer(min=1, default=2000) max_bit_errors=integer(min=1, default=3000) unpacked_parameters=string_list(default=list('SNR','stream_sel_method','scenario','initialize_with')) """.split("\n") SimulationRunner.__init__(self, default_config_file, spec, read_command_line_args) # xxxxxxxxxx General Parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Maximum number of repetitions for each unpacked parameters set self.rep_max = self.params['rep_max'] # # max_bit_errors is used in the _keep_going method to stop the # # simulation earlier if possible. We stop the simulation if the # # accumulated number of bit errors becomes greater then 5% of the # # total number of simulated bits # self.max_bit_errors = self.params['max_bit_errors'] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Channel and Path Loss Parameters xxxxxxxxxxxxxxxxxxxxx # Create the channel object self.multiUserChannel = multiuser.MultiUserChannelMatrix() # Create the Path loss object self.path_loss_obj = pathloss.PathLoss3GPP1() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx RandomState objects seeds xxxxxxxxxxxxxxxxxxxxxxxxxxxx # This is only useful to reproduce a simulation for debugging # purposed self.channel_seed = None # 22522 self.noise_seed = None # 4445 self.data_gen_seed = np.random.randint(10000) # 2105 # self.multiUserChannel.set_channel_seed(self.channel_seed) self.multiUserChannel.set_noise_seed(self.noise_seed) self.data_RS = np.random.RandomState(self.data_gen_seed) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Create the modulator object xxxxxxxxxxxxxxxxxxxxxxxxxx M = self.params['M'] modulator_options = { 'PSK': fundamental.PSK, 'QPSK': fundamental.QPSK, 'QAM': fundamental.QAM, 'BPSK': fundamental.BPSK } self.modulator = modulator_options[self.params['modulator']](M) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Progress Bar xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # This can be either 'screen' or 'file'. If it is 'file' then the # progressbar will write the progress to a file with appropriated # filename self.progress_output_type = 'screen' # Set the progressbar message self.progressbar_message = "SNR: {{SNR}}".format(self.modulator.name) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Dependent parameters (don't change these) xxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Cell Grid self.cell_grid = cell.Grid() self.cell_grid.create_clusters(self.params['num_clusters'], self.params['num_cells'], self.params['cell_radius']) # Note that the Noise variance will be set in the # _on_simulate_current_params_start method. In the NoPathLoss # scenario it will be set as 1.0 regardless of the value of # params['N0'] to avoid problems in the IA algorithms. In the other # scenarios it will be set to self.params['N0']. # # In any case the transmit power will be calculated accordingly in # the _run_simulation method and the simulation results will still # be correct. self.noise_var = None # Linear path loss from cell center to cell border. self._path_loss_border = self.path_loss_obj.calc_path_loss( self.params['cell_radius']) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # TODO: Move code below to the _on_simulate_current_params_start # method # xxxxxxxxxx Interference Alignment objects xxxxxxxxxxxxxxxxxxxxxxx # Create the basic IA Solver object self.ia_solver = algorithms.MMSEIASolver(self.multiUserChannel) # This will be created in the _on_simulate_current_params_start # method. The class of self.ia_top_object will depend on the value # of the 'stream_sel_method' parameter self.ia_top_object = None