Files
imdd_silas/projects/Diss/MPI_revisit/investigate_mpi_algorithms.m
Silas Oettinghaus cae81c0dae Sync with Mac
2026-07-16 21:52:26 +02:00

166 lines
5.7 KiB
Matlab
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
% === DSP settings ===
dsp_options = struct();
dsp_options.mode = "run_id";
dsp_options.recipe = @mpi_recipe_dev;
dsp_options.append_to_db = false;
dsp_options.start_occurence = 5;
dsp_options.max_occurences = 1;
dsp_options.debug_plots = false;
write_mpi_reduction_db = 0;
stream_mpi_reduction_db = write_mpi_reduction_db;
mpi_reduction_study_name = "pam6_8_sweep";
mpi_reduction_writer_path = fullfile(fileparts(mfilename('fullpath')),"db");
addpath(mpi_reduction_writer_path);
dsp_options.database_type = "mysql";
dsp_options.dataBase = "labor";
if ismac
dsp_options.storage_path = "/Volumes/media/labdata/ECOC Silas/ecoc_2025";
else
dsp_options.storage_path = "W:\labdata\ECOC Silas\ecoc_2025";
end
dsp_options.server = "192.168.178.192";
dsp_options.port = 3306;
dsp_options.user = "silas";
dsp_options.password = "silas";
dsp_options.append_mpi_reduction_db = write_mpi_reduction_db && stream_mpi_reduction_db;
dsp_options.mpi_reduction_study_name = mpi_reduction_study_name;
dsp_options.mpi_reduction_writer_path = mpi_reduction_writer_path;
db = DBHandler("dataBase", [dsp_options.dataBase],...
"type", dsp_options.database_type,...
"server", dsp_options.server,...
"user", dsp_options.user, "password", dsp_options.password);
%%
pamformats = [4,6,8];
baudrates = [112e9,96e9,72e9];
for i = 1
B = baudrates(i);
M = pamformats(i);
fp = QueryFilter();
fp.where('Runs','run_id','GREATER_EQUAL',3153);
fp.where('Runs', 'symbolrate','EQUALS',B); % 72 96 112
fp.where('Runs', 'fiber_length', 'EQUALS', 0);
fp.where('Runs', 'interference_path_length', 'EQUALS', 1000);
fp.where('Runs', 'sir', 'LESS_EQUAL', 20);
fp.where('Runs', 'db_mode', 'EQUALS', '"no_db"');
% fp.where('Runs', 'is_mpi', 'EQUALS', 1);
fp.where('Runs', 'pam_level', 'EQUALS', M);
% fp.where('Runs', 'v_bias', 'EQUALS', 2.65);
[dataTable,~] = db.queryDB(fp, db.getTableFieldNames('Runs'));
[~, sortIdx] = sort(dataTable.sir, 'descend');
dataTable = dataTable(sortIdx, :);
desired_sir = [15,22,26,30,38];
desired_sir = [22,38];
% exclude_sr = [112e9];
% % Filter dataTable to only keep rows with sir in desired_sir
isDesired = ~ismember(dataTable.symbolrate, desired_sir);
dataTable = dataTable(isDesired, :);
% dataTable = dataTable(1,:);
run_ids = dataTable.run_id;
%% === Warehouse setup ===
dsp_options.userParameters = struct();
dsp_options.userParameters.block_update = 1;%[1,2,4,8,16,32,64,112,224,448,448*2,1024,2048,4096,8192,16384];%%logspace(-3.8,-1,22);%[linspace(2,4096,22)];
% dsp_options.userParameters.hpf = [2e6:0.5e6:10e6];
% dsp_options.userParameters.bufferlen = [112,224,448,448*2,1024,2048,4096,8192,16384];
wh = DataStorage(dsp_options.userParameters);
%%
n_realizations = (dsp_options.max_occurences - dsp_options.start_occurence + 1);
n_userparams = prod(wh.dim);
n_run_ids = numel(run_ids);
parallel_jobs = n_userparams * n_run_ids;
queried_jobs = n_realizations * n_userparams * n_run_ids;
fprintf("-> [ %d run_id(s) × %d userParam combination(s) = %d parallel job(s) ] × %d realizations = %d total jobs \n", ...
n_run_ids, n_userparams, parallel_jobs, n_realizations, queried_jobs);
%% === Run ===
% submitJobs returns the raw per-job results and the filled Warehouse. For a
% single run_id and remove_dc = [0, 1], results is a 2-by-1 cell array.
[results, wh] = submitJobs(run_ids, dsp_options, processingMode.serial, ...
"wh", wh, ...
"waitbar", true);
%%
if write_mpi_reduction_db && ~stream_mpi_reduction_db
db.refresh();
appendMpiReductionWarehouse(db, wh, run_ids, dsp_options, ...
"study_name", mpi_reduction_study_name);
end
% savepath = fullfile("C:","Users","Silas","Documents","MATLAB","imdd_simulation","projects","Diss","MPI_revisit","algorithms",sprintf("pam_%d_results.mat",M));
% save(wh,savepath)
end
%% Analyze
storageNames = fieldnames(wh.sto);
x_base = dataTable.sir(:).';
x_base = dsp_options.userParameters.block_update;
x_base = dsp_options.userParameters.bufferlen;
% x_base = dsp_options.userParameters.hpf;
figure(2029); hold on
for storage_idx = 1:numel(storageNames)
storageName = storageNames{storage_idx};
result = wh.sto.(storageName);
result = result(:).';
% Each stored entry is a package cell containing one or more occurrences.
ber_all = cell(1,numel(result));
for result_idx = 1:numel(result)
packageCell = result{result_idx};
if isempty(packageCell)
ber_all{result_idx} = NaN;
continue
end
ber_values = nan(1,numel(packageCell));
for package_idx = 1:numel(packageCell)
if isstruct(packageCell{package_idx}) && isfield(packageCell{package_idx},"metrics")
ber_values(package_idx) = packageCell{package_idx}.metrics.BER;
end
end
ber_all{result_idx} = ber_values;
end
maxPackages = max(cellfun(@numel,ber_all));
ber_mat = nan(maxPackages,numel(ber_all));
for k = 1:numel(ber_all)
ber_mat(1:numel(ber_all{k}),k) = ber_all{k};
end
ber = mean(ber_mat,1,"omitnan");
x = x_base;
if numel(x) ~= numel(ber)
x = 1:numel(ber);
end
h = plot(x,ber,"DisplayName",storageName);
for k = 1:numel(x)
scatter(repmat(x(k),maxPackages,1),ber_mat(:,k), ...
"MarkerEdgeColor",h.Color, ...
"HandleVisibility","off");
end
end
beautifyBERplot("logscale",true,"setcolors",false,"setmarkers",true);
legend("Location","best","Interpreter","none");