Max SINR IA Algorithm

This notebook simulates the Closed Form Interference Alignment algorithm.

Some initialization code


In [1]:
%pylab inline
# 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 numpy as np

# Import the simulation runner
from apps.simulate_ia import MaxSINRSimulationRunner
from pyphysim.simulations import results

# 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


Populating the interactive namespace from numpy and matplotlib

Run the algorithm with 120 iterations

The configuration of the simulation is in the 'ia_config_file_120.txt' file. You can edit and run the cell below to update the configuration file.


In [2]:
%%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 = 50
        max_bit_errors = 10000
        unpacked_parameters = SNR,


Overwriting ia_config_file_120.txt

First we need to create a "view" of the engines. Note that you need to start the engines before calling the code below.


In [3]:
from IPython.parallel import Client
cl = Client()
dview = cl.direct_view()

# 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))


Out[3]:
<AsyncResult: execute>

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 [4]:
runner_parallel = MaxSINRSimulationRunner('ia_config_file_120.txt', read_command_line_args=False)
pprint(runner_parallel.params.parameters)
runner_parallel.simulate_in_parallel(dview)

# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = 3  # Always 3 form the closed form IA algorithm
Nr = runner_parallel.params["Nr"]
Nt = runner_parallel.params["Nt"]
Ns = runner_parallel.params["Ns"]
modulator_name = runner_parallel.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_parallel = 'ia_maxsinr_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_parallel.results.save_to_file('{0}.pickle'.format(results_filename_parallel))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

print "Runned iterations: {0}".format(runner_parallel.runned_reps)
print "Elapsed Time: {0}".format(runner_parallel.elapsed_time)


{'K': 3,
 'M': 4,
 'NSymbs': 100,
 'Nr': 2,
 'Ns': 1,
 'Nt': 2,
 'SNR': array([  0.,   5.,  10.,  15.,  20.,  25.,  30.]),
 'max_bit_errors': 10000,
 'max_iterations': array([120]),
 'modulator': 'PSK',
 'rep_max': 50,
 'unpacked_parameters': ['SNR']}
Runned iterations: [50, 50, 50, 50, 50, 50, 50]
Elapsed Time: 14.90s
[**********************100%**********************]  SNR: [  0.   5.  10.  15.  20.  25.  30.]

Plot the results


In [5]:
results_parallel = results.SimulationResults.load_from_file('{0}.pickle'.format(
    results_filename_parallel))

# Get the BER and SER from the results object
ber_parallel = results_parallel.get_result_values_list('ber')
ser_parallel = results_parallel.get_result_values_list('ser')
ia_iterations_parallel = results_parallel.params['max_iterations']

# Get the SNR from the simulation parameters
SNR_parallel = np.array(results_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('Min Leakage 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()