This notebook simulates the Alternating Minimizations Interference Alignment algorithm.
In [ ]:
# xxxxxxxxxx Add the parent folder to the python path. xxxxxxxxxxxxxxxxxxxx
import sys
import os
pyphysim_folder = "~/cvs_files/pyphysim/"
pyphysim_folder = os.path.expanduser(pyphysim_folder)
sys.path.append(pyphysim_folder)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Import the simulation runner
from apps.simulate_ia import AlternatingSimulationRunner
from util import simulations
# We will use clear_output to erase the progressbar after the simulation has finished.
from IPython.display import clear_output
# We will use pprint to print the simulation parameters
from pprint import pprint
The configuration of the simulation is in the 'ia_config_file.txt' file. You can edit and run the cell below to update the configuration file.
In [ ]:
%%file ia_config_file_120.txt
[Scenario]
SNR = [ 0. 5. 10. 15. 20. 25. 30.]
M = 4
modulator = PSK
NSymbs = 100
K = 3
Nr = 2
Nt = 2
Ns = 1
[IA Algorithm]
max_iterations = 120
[General]
rep_max = 5000
max_bit_errors = 10000
unpacked_parameters = SNR,
First we need to create a "view" of the engines. Note that you need to start the engines before calling the code below.
In [ ]:
from IPython.parallel import Client
cl = Client()
dview = cl.direct_view()
dview.execute('%reset') # Reset the engines so that we don't have
# variables there from last computations
# Add the folder containing PyPhysim to the python path in all the
# engines
dview.execute('import sys')
dview.execute('sys.path.append("{0}")'.format(pyphysim_folder))
# For the actual simulation we are better using a load balanced view
lview = cl.load_balanced_view()
All we need to do now is creating the runner object, call its "simulate" method (or the simulate_in_parallel method) and save the results to a file.
In [ ]:
runner_120_parallel = AlternatingSimulationRunner('ia_config_file_120.txt')
pprint(runner_120_parallel.params.parameters)
runner_120_parallel.simulate_in_parallel(lview)
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_120_parallel.params["K"]
Nr = runner_120_parallel.params["Nr"]
Nt = runner_120_parallel.params["Nt"]
Ns = runner_120_parallel.params["Ns"]
modulator_name = runner_120_parallel.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_120_parallel = 'ia_alt_min_results_{0}_{1}x{2}({3})_120_parallel'.format(
modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_120_parallel.results.save_to_file('{0}.pickle'.format(results_filename_120_parallel))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_120_parallel.runned_reps)
print "Elapsed Time: {0}".format(runner_120_parallel.elapsed_time)
In [ ]:
results_120_parallel = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_120_parallel))
# Get the BER and SER from the results object
ber_parallel = results_120_parallel.get_result_values_list('ber')
ser_parallel = results_120_parallel.get_result_values_list('ser')
ia_iterations_parallel = results_120_parallel.params['max_iterations']
# Get the SNR from the simulation parameters
SNR_parallel = np.array(results_120_parallel.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR_parallel.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR_parallel, ber_parallel, '--g*', label='BER')
semilogy(SNR_parallel, ser_parallel, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Alt. Min IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations_parallel))
legend()
grid(True, which='both', axis='both')
show()