start with 400G analysis work

This commit is contained in:
Silas Oettinghaus
2026-07-20 10:22:11 +02:00
parent cae81c0dae
commit 125d8508ca
43 changed files with 4089 additions and 123 deletions

View File

@@ -0,0 +1,343 @@
%% 400G BER over bitrate: best normal algorithms plus duobinary signaling
% Normal algorithms are reduced to the best BER per gross rate across
% db_mode 0/1, pre-emphasis on/off, and BER/BER_precoded result variants.
% Duobinary signaling uses db_mode = 2 and only the sequence-detection BER
% stored in the BER field.
clear; clc;
%% 1) Query data
selectedPamLevel = 8;
selectedFiberLengthKm = 10;
selectedWavelengthNm = 1310;
selectedRopAttenuation = 0; % set [] to use all ROP attenuation values
selectedIsMpi = 0; % set [] to use all entries
normalDbModes = [double(db_mode.no_db), double(db_mode.db_precoded)];
duobinaryDbMode = double(db_mode.db_encoded);
maxBerForPlot = 0.5;
showRawEntries = false;
showBestLine = true;
algoStyles = defaultAlgorithmStyles();
db = DBHandler( ...
"dataBase", "labor_highspeed", ...
"type", "mysql", ...
"server", "192.168.178.192", ...
"user", "silas", ...
"password", "silas");
db.refresh();
fp = QueryFilter();
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
fp.where('Runs', 'pam_level', 'EQUALS', selectedPamLevel);
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelengthNm);
if ~isempty(selectedRopAttenuation)
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
end
if ~isempty(selectedIsMpi)
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
end
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
selectedFields = appendMissingFields(selectedFields, ...
{'Runs.precomp_amp'; 'Runs.is_mpi'});
selectedFields = selectedFields(:);
[rawData, query] = db.queryDB(fp, selectedFields);
disp(query);
fprintf("Fetched %d 400G result rows.\n", height(rawData));
%% 2) Clean data and build the five plotted curves
data = rawData;
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
"rop_attenuation", "precomp_amp", "is_mpi", "numBits", "numBitErr", ...
"BER", "numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
for fieldIdx = 1:numel(numericFields)
fieldName = numericFields(fieldIdx);
if ismember(fieldName, string(data.Properties.VariableNames))
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
end
end
if ~ismember("precomp_amp", string(data.Properties.VariableNames))
warning("plot_best_algos:NoPrecompAmp", ...
"Runs.precomp_amp was not returned. Falling back to pre_emphasis = (db_mode == 0).");
data.pre_emphasis = data.db_mode == double(db_mode.no_db);
else
data.pre_emphasis = derivePreEmphasis(data.precomp_amp, data.db_mode);
end
normalRows = data(ismember(data.db_mode, normalDbModes), :);
normalPlotData = buildNormalMetricRows(normalRows);
normalPlotData = normalPlotData(isfinite(normalPlotData.BER_plot) & ...
normalPlotData.BER_plot > 0 & normalPlotData.BER_plot < maxBerForPlot, :);
duobinaryRows = data(data.db_mode == duobinaryDbMode, :);
if ismember("equalizer_structure", string(duobinaryRows.Properties.VariableNames))
duobinaryRows = duobinaryRows( ...
equalizerMask(duobinaryRows.equalizer_structure, ...
equalizer_structure.db_encoded), :);
end
duobinaryPlotData = buildDuobinarySignalingRows(duobinaryRows);
duobinaryPlotData = duobinaryPlotData(isfinite(duobinaryPlotData.BER_plot) & ...
duobinaryPlotData.BER_plot > 0 & ...
duobinaryPlotData.BER_plot < maxBerForPlot, :);
plotData = [normalPlotData; duobinaryPlotData];
if isempty(plotData)
warning("plot_best_algos:NoRows", ...
"No rows remain after length/PAM/wavelength/BER filtering.");
return
end
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
plotData.grossrate_Gbps = plotData.grossrate .* 1e-9;
fprintf("Remaining candidate BER rows: %d\n", height(plotData));
disp(groupcounts(plotData, ["algorithm_key", "db_mode", "pre_emphasis", "precode"]));
bestPlotData = bestBerByAlgorithmAndGrossRate(plotData);
fprintf("Keeping %d best-BER rows across algorithm/gross-rate groups.\n", ...
height(bestPlotData));
disp(groupcounts(bestPlotData, "algorithm_key"));
%% 3) Plot one figure with five lines
availableStyles = algoStyles(hasAlgorithmRows(bestPlotData, algoStyles), :);
if isempty(availableStyles)
warning("plot_best_algos:NoSelectedAlgorithms", ...
"None of the configured algorithm styles match the queried rows.");
return
end
fig = figure(); clf;
ax = axes(fig); hold(ax, "on");
for styleIdx = 1:height(availableStyles)
style = availableStyles(styleIdx, :);
rowMask = bestPlotData.algorithm_key == style.algorithm_key;
if ~any(rowMask)
continue
end
algoData = sortrows(bestPlotData(rowMask, :), "grossrate_Gbps");
if showRawEntries
scatter(ax, algoData.grossrate_Gbps, algoData.BER_plot, ...
9, ...
"Marker", ".", ...
"MarkerEdgeColor", style.color, ...
"MarkerFaceColor", style.color, ...
"MarkerEdgeAlpha", 0.25, ...
"MarkerFaceAlpha", 0.25, ...
"HandleVisibility", "off");
end
if showBestLine
plot(ax, algoData.grossrate_Gbps, algoData.BER_plot, ...
"LineStyle", style.lineStyle, ...
"Marker", style.marker, ...
"MarkerSize", 5, ...
"LineWidth", 1.5, ...
"Color", style.color, ...
"MarkerFaceColor", style.markerFaceColor, ...
"MarkerEdgeColor", style.color, ...
"DisplayName", style.name);
end
end
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
"LineWidth", 1, ...
"LineStyle", "--", ...
"Color", [0.25 0.25 0.25], ...
"HandleVisibility", "off");
title(ax, sprintf("PAM-%d, %.0f km, %.0f nm", ...
selectedPamLevel, selectedFiberLengthKm, selectedWavelengthNm));
xlabel(ax, "Gross rate [Gb/s]");
ylabel(ax, "BER");
set(ax, "YScale", "log");
ylim(ax, [1e-5, maxBerForPlot]);
grid(ax, "on");
box(ax, "on");
xTicks = unique(bestPlotData.grossrate_Gbps(isfinite(bestPlotData.grossrate_Gbps)));
if ~isempty(xTicks)
xticks(ax, xTicks);
xlim(ax, [min(xTicks), max(xTicks)]);
end
legend(ax, "Location", "best", "Interpreter", "none");
if exist("beautifyBERplot", "file")
beautifyBERplot("logscale", true, "setcolors", false, ...
"setmarkers", false, "changemarkers", false);
end
set(fig, "Position", 1e3 .* [0.1000 0.5500 0.7200 0.4200]);
%% Local helpers
function fields = appendMissingFields(fields, extraFields)
fields = cellstr(fields);
extraFields = cellstr(extraFields);
for idx = 1:numel(extraFields)
if ~any(strcmp(fields, extraFields{idx}))
fields{end+1, 1} = extraFields{idx}; %#ok<AGROW>
end
end
end
function values = numericColumn(values)
if iscell(values)
values = string(values);
end
if isstring(values) || ischar(values)
values = str2double(values);
end
values = double(values);
end
function styles = defaultAlgorithmStyles()
styles = table( ...
["vnle"; ...
"vnle_pf_mlse"; ...
"vnle_db_mlse"; ...
"ml_mlse"; ...
"db_encoded"], ...
[equalizer_structure.vnle; ...
equalizer_structure.vnle_pf_mlse; ...
equalizer_structure.vnle_db_mlse; ...
equalizer_structure.ml_mlse; ...
equalizer_structure.db_encoded], ...
["VNLE"; ...
"VNLE + PF + MLSE"; ...
"VNLE DBt. + MLSE"; ...
"ML pre-EQ + Viterbi"; ...
"Duobinary signaling"], ...
["o"; "square"; "diamond"; "^"; "v"], ...
["-"; "-"; "-"; "-"; "-"], ...
["w"; "w"; "w"; "w"; "w"], ...
[clr.Paired.red; ...
clr.Paired.green; ...
clr.Paired.blue; ...
clr.Paired.purple; ...
clr.Paired.orange], ...
'VariableNames', ["algorithm_key", "eq", "name", "marker", ...
"lineStyle", "markerFaceColor", "color"]);
end
function preEmphasis = derivePreEmphasis(precompAmp, dbMode)
preEmphasis = false(size(dbMode));
validPrecomp = isfinite(precompAmp);
preEmphasis(validPrecomp) = precompAmp(validPrecomp) > -45;
missingPrecomp = ~validPrecomp;
preEmphasis(missingPrecomp) = dbMode(missingPrecomp) == double(db_mode.no_db);
end
function plotData = buildNormalMetricRows(data)
baseRows = data(isfinite(data.BER), :);
baseRows.precode = false(height(baseRows), 1);
baseRows.BER_plot = baseRows.BER;
baseRows.algorithm_key = algorithmKeyFromEqualizer(baseRows.equalizer_structure);
baseRows = baseRows(baseRows.algorithm_key ~= "", :);
if ismember("BER_precoded", string(data.Properties.VariableNames))
precodedRows = data(isfinite(data.BER_precoded), :);
precodedRows.precode = true(height(precodedRows), 1);
precodedRows.BER_plot = precodedRows.BER_precoded;
precodedRows.algorithm_key = algorithmKeyFromEqualizer( ...
precodedRows.equalizer_structure);
precodedRows = precodedRows(precodedRows.algorithm_key ~= "", :);
plotData = [baseRows; precodedRows];
else
warning("plot_best_algos:NoPrecodedBer", ...
"BER_precoded was not returned. Plotting only BER rows for normal algorithms.");
plotData = baseRows;
end
end
function plotData = buildDuobinarySignalingRows(data)
plotData = data(isfinite(data.BER), :);
plotData.precode = false(height(plotData), 1);
plotData.BER_plot = plotData.BER;
plotData.algorithm_key = repmat("db_encoded", height(plotData), 1);
end
function algorithmKey = algorithmKeyFromEqualizer(equalizerColumn)
eqNumeric = equalizerNumeric(equalizerColumn);
algorithmKey = strings(size(eqNumeric));
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle)) = "vnle";
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle_pf_mlse)) = ...
"vnle_pf_mlse";
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle_db_mlse)) = ...
"vnle_db_mlse";
algorithmKey(eqNumeric == enumValue(equalizer_structure.ml_mlse)) = "ml_mlse";
end
function mask = equalizerMask(equalizerColumn, eqValue)
eqNumeric = equalizerNumeric(equalizerColumn);
mask = eqNumeric == enumValue(eqValue);
end
function eqNumeric = equalizerNumeric(equalizerColumn)
if isa(equalizerColumn, "equalizer_structure")
eqNumeric = double(equalizerColumn);
elseif isnumeric(equalizerColumn)
eqNumeric = double(equalizerColumn);
else
equalizerString = string(equalizerColumn);
eqNumeric = str2double(equalizerString);
enumNames = ["vnle", "ffe", "dfe", "vnle_pf_mlse", ...
"vnle_db_mlse", "db_encoded", "ml_mlse"];
enumValues = [ ...
enumValue(equalizer_structure.vnle), ...
enumValue(equalizer_structure.ffe), ...
enumValue(equalizer_structure.dfe), ...
enumValue(equalizer_structure.vnle_pf_mlse), ...
enumValue(equalizer_structure.vnle_db_mlse), ...
enumValue(equalizer_structure.db_encoded), ...
enumValue(equalizer_structure.ml_mlse)];
for idx = 1:numel(enumNames)
missingNumeric = isnan(eqNumeric);
eqNumeric(missingNumeric & equalizerString == enumNames(idx)) = ...
enumValues(idx);
end
end
end
function value = enumValue(enumEntry)
value = double(enumEntry);
end
function bestData = bestBerByAlgorithmAndGrossRate(data)
groupVars = ["algorithm_key", "grossrate_Gbps"];
groupId = findgroups(data(:, groupVars));
keepIdx = NaN(max(groupId), 1);
for curGroup = 1:max(groupId)
rowIdx = find(groupId == curGroup);
[~, localBestIdx] = min(data.BER_plot(rowIdx));
keepIdx(curGroup) = rowIdx(localBestIdx);
end
bestData = sortrows(data(keepIdx, :), groupVars);
end
function keep = hasAlgorithmRows(data, algoStyles)
keep = false(height(algoStyles), 1);
for idx = 1:height(algoStyles)
keep(idx) = any(data.algorithm_key == algoStyles.algorithm_key(idx));
end
end

View File

@@ -0,0 +1,294 @@
%% 400G BER over bitrate from labor_highspeed.dashboard_ungrouped_alltime
% 1) gather all BER entries for one PAM format and fiber length
% 2) derive pre-emphasis and precoding groups
% 3) plot one bitrate-vs-BER tile per equalizer structure
clear; clc;
%% 1) Gather data
selectedPamLevel = 4;
selectedFiberLengthKm = 10;
selectedWavelength =1310; % set [] to use all wavelengths
selectedRopAttenuation = []; % set [] to use all ROP attenuation values
selectedIsMpi = []; % set [] to use all entries
maxBerForPlot = 0.5;
showRawEntries = true;
showMedianLine = true;
eqStyles = defaultEqualizerStyles();
comboStyles = defaultCombinationStyles();
db = DBHandler( ...
"dataBase", "labor_highspeed", ...
"type", "mysql");
db.refresh();
fp = QueryFilter();
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
fp.where('Runs', 'pam_level', 'EQUALS', selectedPamLevel);
if ~isempty(selectedWavelength)
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelength);
end
if ~isempty(selectedRopAttenuation)
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
end
if ~isempty(selectedIsMpi)
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
end
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
selectedFields = [selectedFields; {'Runs.precomp_amp'; 'Runs.is_mpi'}];
selectedFields = selectedFields(:);
[rawData, query] = db.queryDB(fp, selectedFields);
disp(query);
fprintf("Fetched %d 400G result rows.\n", height(rawData));
%% 2) Clean data and derive analysis groups
data = rawData;
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
"rop_attenuation", "precomp_amp", "is_mpi", "numBits", "numBitErr", ...
"BER", "numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
for fieldIdx = 1:numel(numericFields)
fieldName = numericFields(fieldIdx);
if ismember(fieldName, string(data.Properties.VariableNames))
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
end
end
if ~ismember("precomp_amp", string(data.Properties.VariableNames))
warning("analyze_db:NoPrecompAmp", ...
"Runs.precomp_amp was not returned. Falling back to pre_emphasis = (db_mode == 0).");
data.pre_emphasis = data.db_mode == 0;
else
data.pre_emphasis = derivePreEmphasis(data.precomp_amp, data.db_mode);
end
plotData = buildBerMetricRows(data);
plotData = plotData(isfinite(plotData.BER_plot) & ...
plotData.BER_plot > 0 & plotData.BER_plot < maxBerForPlot, :);
if isempty(plotData)
warning("analyze_db:NoRows", ...
"No rows remain after fiber/PAM/BER filtering.");
return
end
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
plotData.grossrate_Gbps = plotData.grossrate .* 1e-9;
fprintf("Remaining plotted BER rows: %d\n", height(plotData));
disp(groupcounts(plotData, ["equalizer_structure", "pre_emphasis", "precode"]));
bestPlotData = bestBerByBitrateAndGroup(plotData);
fprintf("Keeping %d best-BER rows across bitrate/EQ/pre-emphasis/precode groups.\n", ...
height(bestPlotData));
%% 3) Plot bitrate versus BER
availableEqStyles = eqStyles(hasEqualizerRows(bestPlotData, eqStyles), :);
if isempty(availableEqStyles)
warning("analyze_db:NoSelectedEqualizers", ...
"None of the configured equalizer styles match the queried rows.");
return
end
fig = figure(401); clf;
tiledlayout(1, height(availableEqStyles), ...
"TileSpacing", "compact", ...
"Padding", "compact");
for eqIdx = 1:height(availableEqStyles)
eqStyle = availableEqStyles(eqIdx, :);
ax = nexttile; hold(ax, "on");
eqMask = equalizerMask(bestPlotData.equalizer_structure, eqStyle.eq);
for comboIdx = 1:height(comboStyles)
comboStyle = comboStyles(comboIdx, :);
rowMask = eqMask & ...
bestPlotData.pre_emphasis == comboStyle.pre_emphasis & ...
bestPlotData.precode == comboStyle.precode;
if ~any(rowMask)
continue
end
comboData = sortrows(bestPlotData(rowMask, :), "bitrate_Gbps");
comboColor = emphasisColor(eqStyle.color, comboStyle.pre_emphasis);
label = sprintf("%s, %s", eqStyle.name, comboStyle.name);
if showRawEntries
scatter(ax, comboData.bitrate_Gbps, comboData.BER_plot, ...
5, ...
"Marker", '.', ...
"MarkerEdgeColor", comboColor, ...
"MarkerFaceColor", comboColor, ...
"MarkerEdgeAlpha", 0.25, ...
"MarkerFaceAlpha", 0.25, ...
"HandleVisibility", "off");
end
if showMedianLine
summaryTable = summarizeBerByBitrate(comboData);
plot(ax, summaryTable.bitrate_Gbps, summaryTable.median_BER_plot, ...
"LineStyle", comboStyle.lineStyle, ...
"Marker", eqStyle.marker, ...
"MarkerSize", 4, ...
"LineWidth", 1.4, ...
"Color", comboColor, ...
"MarkerFaceColor", comboStyle.markerFaceColor, ...
"MarkerEdgeColor", comboColor, ...
"DisplayName", label);
end
end
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
"LineWidth", 1, ...
"LineStyle", "--", ...
"Color", [0.25 0.25 0.25], ...
"HandleVisibility", "off");
title(ax, sprintf("PAM-%d, %s", selectedPamLevel, eqStyle.name));
xlabel(ax, "Gross rate [Gb/s]");
ylabel(ax, "BER");
set(ax, "YScale", "log");
ylim(ax, [1e-5, maxBerForPlot]);
grid(ax, "on");
box(ax, "on");
xTicks = unique(bestPlotData.bitrate_Gbps(isfinite(bestPlotData.bitrate_Gbps)));
if ~isempty(xTicks)
xticks(ax, xTicks);
xlim(ax, [min(xTicks), max(xTicks)]);
end
legend(ax, "Location", "best", "Interpreter", "none");
if exist("beautifyBERplot", "file")
beautifyBERplot("logscale", true, "setcolors", false, ...
"setmarkers", false, "changemarkers", false);
end
end
set(fig, "Position", 1e3 .* [0.1000 0.5500 1.4113 0.3200]);
%% Local helpers
function values = numericColumn(values)
if iscell(values)
values = string(values);
end
if isstring(values) || ischar(values)
values = str2double(values);
end
values = double(values);
end
function styles = defaultEqualizerStyles()
styles = table( ...
[equalizer_structure.vnle; ...
equalizer_structure.vnle_pf_mlse; ...
equalizer_structure.vnle_db_mlse; ...
equalizer_structure.ml_mlse], ...
["VNLE"; ...
"VNLE + PF + MLSE"; ...
"VNLE DBt. + MLSE"; ...
"ML pre-EQ + Viterbi"], ...
["o"; "square"; "diamond"; "^"], ...
[clr.Paired.red; ...
clr.Paired.green; ...
clr.Paired.blue; ...
clr.Paired.purple], ...
'VariableNames', ["eq", "name", "marker", "color"]);
end
function styles = defaultCombinationStyles()
styles = table( ...
[true; true; false; false], ...
[true; false; true; false], ...
["w/ pre-emph., w/ precode"; ...
"w/ pre-emph., w/o precode"; ...
"w/o pre-emph., w/ precode"; ...
"w/o pre-emph., w/o precode"], ...
["--"; "-"; "--"; "-"], ...
["w"; "w"; "none"; "none"], ...
'VariableNames', ["pre_emphasis", "precode", "name", ...
"lineStyle", "markerFaceColor"]);
end
function preEmphasis = derivePreEmphasis(precompAmp, dbMode)
preEmphasis = false(size(dbMode));
validPrecomp = isfinite(precompAmp);
% In the 400G measurement scripts, -50 dB is the low/no-pre-emphasis
% setting, while -38/-37/-34 dB are the active pre-emphasis settings.
preEmphasis(validPrecomp) = precompAmp(validPrecomp) > -45;
missingPrecomp = ~validPrecomp;
preEmphasis(missingPrecomp) = dbMode(missingPrecomp) == 0;
end
function plotData = buildBerMetricRows(data)
baseRows = data(isfinite(data.BER), :);
baseRows.precode = false(height(baseRows), 1);
baseRows.BER_plot = baseRows.BER;
if ismember("BER_precoded", string(data.Properties.VariableNames))
precodedRows = data(isfinite(data.BER_precoded), :);
precodedRows.precode = true(height(precodedRows), 1);
precodedRows.BER_plot = precodedRows.BER_precoded;
plotData = [baseRows; precodedRows];
else
warning("analyze_db:NoPrecodedBer", ...
"BER_precoded was not returned. Plotting only precode = 0 rows.");
plotData = baseRows;
end
end
function mask = equalizerMask(equalizerColumn, eqValue)
if isa(equalizerColumn, "equalizer_structure")
mask = equalizerColumn == eqValue;
elseif isnumeric(equalizerColumn)
mask = double(equalizerColumn) == double(int32(eqValue));
else
mask = string(equalizerColumn) == string(eqValue);
end
end
function keep = hasEqualizerRows(data, eqStyles)
keep = false(height(eqStyles), 1);
for idx = 1:height(eqStyles)
keep(idx) = any(equalizerMask(data.equalizer_structure, eqStyles.eq(idx)));
end
end
function summaryTable = summarizeBerByBitrate(data)
summaryTable = groupsummary(data, "bitrate_Gbps", "median", "BER_plot");
summaryTable = sortrows(summaryTable, "bitrate_Gbps");
end
function bestData = bestBerByBitrateAndGroup(data)
groupVars = ["equalizer_structure", "pre_emphasis", "precode", "bitrate_Gbps"];
groupId = findgroups(data(:, groupVars));
keepIdx = NaN(max(groupId), 1);
for curGroup = 1:max(groupId)
rowIdx = find(groupId == curGroup);
[~, localBestIdx] = min(data.BER_plot(rowIdx));
keepIdx(curGroup) = rowIdx(localBestIdx);
end
bestData = sortrows(data(keepIdx, :), groupVars);
end
function color = emphasisColor(baseColor, preEmphasis)
if preEmphasis
color = 0.65 .* baseColor + 0.35;
else
color = baseColor;
end
end

View File

@@ -0,0 +1,242 @@
%% Duobinary transmission: BER over bitrate for detection algorithms
% DB transmission means the sequence was precoded and encoded at the Tx
% (Runs.db_mode = db_mode.db_encoded). In this stored-result convention:
% BER -> VNLE + MLSE
% BER_precoded -> VNLE + memoryless detection
clear; clc;
%% 1) Query data
selectedPamLevels = [4, 6, 8];
selectedFiberLengthKm = 10;
selectedWavelengthNm = 1310;
selectedRopAttenuation = 0;
selectedIsMpi = 0;
selectedDbMode = db_mode.db_encoded;
selectedEqualizerStructure = equalizer_structure.db_encoded;
maxBerForPlot = 0.5;
showRawEntries = false;
showBestLine = true;
db = DBHandler( ...
"dataBase", "labor_highspeed", ...
"type", "mysql", ...
"server", "192.168.178.192", ...
"user", "silas", ...
"password", "silas");
db.refresh();
fp = QueryFilter();
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelengthNm);
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
fp.where('Runs', 'db_mode', 'EQUALS', double(selectedDbMode));
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
selectedFields = appendMissingFields(selectedFields, {'Runs.is_mpi'});
selectedFields = selectedFields(:);
[rawData, query] = db.queryDB(fp, selectedFields);
disp(query);
fprintf("Fetched %d duobinary result rows.\n", height(rawData));
%% 2) Clean and reshape BER metrics
data = rawData;
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
"rop_attenuation", "is_mpi", "numBits", "numBitErr", "BER", ...
"numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
for fieldIdx = 1:numel(numericFields)
fieldName = numericFields(fieldIdx);
if ismember(fieldName, string(data.Properties.VariableNames))
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
end
end
data = data(ismember(data.pam_level, selectedPamLevels), :);
if ismember("equalizer_structure", string(data.Properties.VariableNames)) && ...
~isempty(selectedEqualizerStructure)
data = data(equalizerMask(data.equalizer_structure, selectedEqualizerStructure), :);
end
plotData = buildDetectionMetricRows(data);
plotData = plotData(isfinite(plotData.BER_plot) & ...
plotData.BER_plot > 0 & plotData.BER_plot < maxBerForPlot, :);
if isempty(plotData)
warning("plot_duobinary_detection:NoRows", ...
"No rows remain after duobinary/PAM/wavelength/BER filtering.");
return
end
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
plotData = sortrows(plotData, ...
["pam_level", "wavelength", "detection_type", "bitrate_Gbps", "run_id"]);
fprintf("Remaining plotted BER rows: %d\n", height(plotData));
disp(groupcounts(plotData, ["pam_level", "wavelength", "detection_type"]));
%% 3) Plot BER versus bitrate
detectionStyles = defaultDetectionStyles();
availablePamLevels = selectedPamLevels(ismember(selectedPamLevels, unique(plotData.pam_level).'));
fig = figure(430); clf;
tiledlayout(1, numel(availablePamLevels), ...
"TileSpacing", "compact", ...
"Padding", "compact");
for pamIdx = 1:numel(availablePamLevels)
pamLevel = availablePamLevels(pamIdx);
ax = nexttile; hold(ax, "on");
pamMask = plotData.pam_level == pamLevel;
for styleIdx = 1:height(detectionStyles)
style = detectionStyles(styleIdx, :);
rowMask = pamMask & plotData.detection_type == style.detection_type;
if ~any(rowMask)
continue
end
detectionData = sortrows(plotData(rowMask, :), "bitrate_Gbps");
summaryTable = summarizeBerByBitrate(detectionData);
if showRawEntries
scatter(ax, detectionData.bitrate_Gbps, detectionData.BER_plot, ...
9, ...
"Marker", ".", ...
"MarkerEdgeColor", style.color, ...
"MarkerFaceColor", style.color, ...
"MarkerEdgeAlpha", 0.25, ...
"MarkerFaceAlpha", 0.25, ...
"HandleVisibility", "off");
end
if showBestLine
plot(ax, summaryTable.bitrate_Gbps, summaryTable.BER_plot, ...
"LineStyle", style.lineStyle, ...
"Marker", style.marker, ...
"MarkerSize", 5, ...
"LineWidth", 1.4, ...
"Color", style.color, ...
"MarkerFaceColor", style.markerFaceColor, ...
"MarkerEdgeColor", style.color, ...
"DisplayName", style.name);
end
end
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
"LineWidth", 1, ...
"LineStyle", "--", ...
"Color", [0.25 0.25 0.25], ...
"HandleVisibility", "off");
title(ax, sprintf("PAM-%d, %.0f nm", pamLevel, selectedWavelengthNm));
xlabel(ax, "Bitrate [Gb/s]");
ylabel(ax, "BER");
set(ax, "YScale", "log");
ylim(ax, [1e-5, maxBerForPlot]);
grid(ax, "on");
box(ax, "on");
xTicks = unique(plotData.bitrate_Gbps(pamMask & isfinite(plotData.bitrate_Gbps)));
if ~isempty(xTicks)
xticks(ax, xTicks);
xlim(ax, [min(xTicks), max(xTicks)]);
end
legend(ax, "Location", "best", "Interpreter", "none");
if exist("beautifyBERplot", "file")
beautifyBERplot("logscale", true, "setcolors", false, ...
"setmarkers", false, "changemarkers", false);
end
end
set(fig, "Position", 1e3 .* [0.1000 0.5500 1.4113 0.3200]);
%% Local helpers
function fields = appendMissingFields(fields, extraFields)
fields = cellstr(fields);
extraFields = cellstr(extraFields);
for idx = 1:numel(extraFields)
if ~any(strcmp(fields, extraFields{idx}))
fields{end+1, 1} = extraFields{idx}; %#ok<AGROW>
end
end
end
function values = numericColumn(values)
if iscell(values)
values = string(values);
end
if isstring(values) || ischar(values)
values = str2double(values);
end
values = double(values);
end
function plotData = buildDetectionMetricRows(data)
baseRows = data(isfinite(data.BER), :);
baseRows.detection_type = repmat("VNLE + MLSE", height(baseRows), 1);
baseRows.BER_plot = baseRows.BER;
if ismember("BER_precoded", string(data.Properties.VariableNames))
memorylessRows = data(isfinite(data.BER_precoded), :);
memorylessRows.detection_type = repmat("VNLE + memoryless", ...
height(memorylessRows), 1);
memorylessRows.BER_plot = memorylessRows.BER_precoded;
plotData = [baseRows; memorylessRows];
else
warning("plot_duobinary_detection:NoPrecodedBer", ...
"BER_precoded was not returned. Plotting only VNLE + MLSE rows.");
plotData = baseRows;
end
end
function styles = defaultDetectionStyles()
styles = table( ...
["VNLE + MLSE"; "VNLE + memoryless"], ...
["VNLE + MLSE"; "VNLE + memoryless"], ...
["o"; "square"], ...
["-"; "--"], ...
["w"; "none"], ...
[clr.Paired.blue; clr.Paired.orange], ...
'VariableNames', ["detection_type", "name", "marker", ...
"lineStyle", "markerFaceColor", "color"]);
end
function mask = equalizerMask(equalizerColumn, eqValue)
if isa(equalizerColumn, "equalizer_structure")
mask = equalizerColumn == eqValue;
elseif isnumeric(equalizerColumn)
mask = double(equalizerColumn) == enumValue(eqValue);
else
equalizerString = string(equalizerColumn);
numericEqualizer = str2double(equalizerString);
mask = equalizerString == string(eqValue) | numericEqualizer == enumValue(eqValue);
end
end
function value = enumValue(enumEntry)
value = double(enumEntry);
end
function summaryTable = summarizeBerByBitrate(data)
groupId = findgroups(data.bitrate_Gbps);
keepIdx = NaN(max(groupId), 1);
for curGroup = 1:max(groupId)
rowIdx = find(groupId == curGroup);
[~, localBestIdx] = min(data.BER_plot(rowIdx));
keepIdx(curGroup) = rowIdx(localBestIdx);
end
summaryTable = data(keepIdx, :);
summaryTable = sortrows(summaryTable, "bitrate_Gbps");
end

Binary file not shown.

View File

@@ -0,0 +1,361 @@
% === 400G DSP settings ===
dsp_options = struct();
dsp_options.mode = "run_id";
dsp_options.recipe = @dsp_400g_recipe;
dsp_options.append_to_db = false;
% dsp_options.append_mpi_reduction_db = false;
dsp_options.start_occurence = 1;
dsp_options.max_occurences = 1;
dsp_options.debug_plots = false;
dsp_options.database_type = "mysql";
dsp_options.dataBase = "labor_highspeed";
if ismac
dsp_options.storage_path = "/Volumes/media/labdata/sioe_labor";
else
dsp_options.storage_path = "W:\labdata\sioe_labor";
end
dsp_options.server = "192.168.178.192";
dsp_options.port = 3306;
dsp_options.user = "silas";
dsp_options.password = "silas";
db = DBHandler("dataBase", [dsp_options.dataBase], ...
"type", dsp_options.database_type, ...
"server", dsp_options.server, ...
"user", dsp_options.user, ...
"password", dsp_options.password);
%% Select runs
maxRunIds = 1; % keep small until the recipe settings are settled
fp = QueryFilter();
fp.where('Runs','fiber_length','EQUALS', 10);
fp.where('Runs','wavelength','EQUALS', 1310);
fp.where('Runs','bitrate','EQUALS', 330e9);
fp.where('Runs','pam_level','EQUALS', 4);
fp.where('Runs','rop_attenuation','EQUALS', 0);
fp.where('Runs','is_mpi','EQUALS', 0);
fp.where('Runs', 'db_mode','EQUALS', 2);
fields = db.getTableFieldNames('Runs');
[dataTable, query] = db.queryDB(fp, fields);
disp(query);
dataTable = sortrows(dataTable, {'bitrate', 'run_id'});
% dataTable = dataTable(1:maxRunIds, :);
run_ids = dataTable.run_id(:).';
if isempty(run_ids)
error("investigate_400g_algorithms:MissingRunIds", ...
"No 400G runs match the current filters.");
end
fprintf("Selected %d run_id(s): %s\n", numel(run_ids), mat2str(run_ids));
%% Parameter sweep
dsp_options.userParameters = struct();
dsp_options.userParameters.run_ml_mlse_db = true;
dsp_options.userParameters.run_mlse_db = true;
% Enable/disable equalizer branches.
% dsp_options.userParameters.run_ffe = false;
% dsp_options.userParameters.run_vnle = false;
% dsp_options.userParameters.run_dfe = false;
% dsp_options.userParameters.run_vnle_mlse = true;
% dsp_options.userParameters.run_dbtgt = true;
% Examples for parameter loops. DataStorage expands every vector-valued field.
% dsp_options.userParameters.len_tr = 4096*2;
% dsp_options.userParameters.pf_ncoeffs = 1;
% dsp_options.userParameters.decoding_mode = [db_decoder.memoryless,db_decoder.sequencedetection];
% dsp_options.userParameters.pf_ncoeffs = [1, 2, 3];
% dsp_options.userParameters.mu_dc = [0, 1e-5, 1e-4];
% dsp_options.userParameters.run_ml_mlse_db = [false, true];
% dsp_options.userParameters.run_mlse_db = [false, true];
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) x %d userParam combination(s) = %d job(s) ] x %d realizations = %d total jobs \n", ...
n_run_ids, n_userparams, parallel_jobs, n_realizations, queried_jobs);
%% Run
[results, wh] = submitJobs(run_ids, dsp_options, processingMode.serial, ...
"wh", wh, ...
"waitbar", true);
%% Quick result overview
printBerSummary(wh);
plotBerVsBitrateQuick(wh, dataTable);
function printBerSummary(wh)
storageNames = fieldnames(wh.sto);
if isempty(storageNames)
fprintf("No non-empty recipe outputs were stored.\n");
return
end
fprintf("\nBER summary by stored package:\n");
for storageIdx = 1:numel(storageNames)
storageName = storageNames{storageIdx};
values = wh.sto.(storageName)(:).';
berValues = extractBerValues(values);
if isempty(berValues)
fprintf(" %-18s no BER values\n", storageName);
else
fprintf(" %-18s min %.3e | median %.3e | n %d\n", ...
storageName, min(berValues), median(berValues), numel(berValues));
end
end
end
function berValues = extractBerValues(values)
berValues = [];
for valueIdx = 1:numel(values)
packageCell = values{valueIdx};
if isempty(packageCell)
continue
end
if ~iscell(packageCell)
packageCell = {packageCell};
end
for packageIdx = 1:numel(packageCell)
package = packageCell{packageIdx};
if isstruct(package) && isfield(package, "metrics")
metrics = package.metrics;
if isprop(metrics, "BER")
berValues(end+1) = metrics.BER; %#ok<AGROW>
elseif isstruct(metrics) && isfield(metrics, "BER")
berValues(end+1) = metrics.BER; %#ok<AGROW>
end
end
end
end
berValues = berValues(isfinite(berValues));
end
function plotBerVsBitrateQuick(wh, dataTable)
plotData = buildQuickBerTable(wh, dataTable);
if isempty(plotData)
fprintf("No BER values available for quick BER-vs-bitrate plot.\n");
return
end
storageNames = unique(plotData.storage_name, "stable");
decodingModes = [db_decoder.memoryless, db_decoder.sequencedetection];
berMetrics = ["BER", "BER_precoded"];
lineStyles = ["-", ":"];
rawMarkers = [".", "x"];
markers = ["o", "square", "diamond", "^", "v", ">"];
fig = figure(402); clf;
ax = axes(fig); hold(ax, "on");
for storageIdx = 1:numel(storageNames)
storageName = storageNames(storageIdx);
for modeIdx = 1:numel(decodingModes)
decodingMode = decodingModes(modeIdx);
for metricIdx = 1:numel(berMetrics)
metricName = berMetrics(metricIdx);
rowMask = plotData.storage_name == storageName & ...
plotData.decoding_mode == decodingMode & ...
plotData.metric_name == metricName;
if ~any(rowMask)
continue
end
modeData = sortrows(plotData(rowMask, :), "bitrate_Gbps");
summaryData = groupsummary(modeData, "bitrate_Gbps", "median", "BER");
summaryData = sortrows(summaryData, "bitrate_Gbps");
color = quickPlotColor(modeIdx);
marker = markers(1 + mod(storageIdx - 1, numel(markers)));
label = sprintf("%s, %s, %s", storageName, ...
decodingModeLabel(decodingMode), metricName);
scatter(ax, modeData.bitrate_Gbps, modeData.BER, ...
12, ...
"Marker", rawMarkers(metricIdx), ...
"MarkerEdgeColor", color, ...
"MarkerEdgeAlpha", 0.25, ...
"HandleVisibility", "off");
plot(ax, summaryData.bitrate_Gbps, summaryData.median_BER, ...
"LineStyle", lineStyles(metricIdx), ...
"Marker", marker, ...
"MarkerSize", 5, ...
"LineWidth", 1.4, ...
"Color", color, ...
"DisplayName", label);
end
end
end
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
"LineWidth", 1, ...
"LineStyle", "--", ...
"Color", [0.25 0.25 0.25], ...
"HandleVisibility", "off");
xlabel(ax, "Bitrate [Gb/s]");
ylabel(ax, "BER");
title(ax, "Quick BER vs bitrate");
set(ax, "YScale", "log");
grid(ax, "on");
box(ax, "on");
legend(ax, "Location", "best", "Interpreter", "none");
if exist("beautifyBERplot", "file")
beautifyBERplot("logscale", true, "setcolors", false, ...
"setmarkers", false, "changemarkers", false);
end
end
function plotData = buildQuickBerTable(wh, dataTable)
storageNames = fieldnames(wh.sto);
if isempty(storageNames)
plotData = table();
return
end
runIds = dataTable.run_id(:);
bitrates = dataTable.bitrate(:);
storageCol = strings(0, 1);
runIdCol = zeros(0, 1);
bitrateCol = zeros(0, 1);
decodingCol = db_decoder.empty(0, 1);
metricCol = strings(0, 1);
berCol = zeros(0, 1);
for storageIdx = 1:numel(storageNames)
storageName = storageNames{storageIdx};
storageValues = wh.sto.(storageName);
for linIdx = 1:numel(storageValues)
[phys, storedValue] = wh.getPhysAndValueByLinIndex(storageName, linIdx);
metricRows = extractBerMetricRows({storedValue});
if isempty(metricRows) || ~isfield(phys, "decoding_mode")
continue
end
runId = resolveRunId(phys, runIds);
bitrate = resolveBitrate(runId, runIds, bitrates);
if ~isfinite(bitrate)
continue
end
nRows = height(metricRows);
storageCol(end+1:end+nRows, 1) = string(storageName);
runIdCol(end+1:end+nRows, 1) = double(runId);
bitrateCol(end+1:end+nRows, 1) = double(bitrate);
decodingCol(end+1:end+nRows, 1) = phys.decoding_mode;
metricCol(end+1:end+nRows, 1) = metricRows.metric_name;
berCol(end+1:end+nRows, 1) = metricRows.BER;
end
end
plotData = table(storageCol, runIdCol, bitrateCol, decodingCol, metricCol, berCol, ...
'VariableNames', ["storage_name", "run_id", "bitrate", ...
"decoding_mode", "metric_name", "BER"]);
if ~isempty(plotData)
plotData = plotData(isfinite(plotData.BER) & plotData.BER > 0, :);
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
end
end
function metricRows = extractBerMetricRows(values)
metricNames = strings(0, 1);
berValues = zeros(0, 1);
requestedMetrics = ["BER", "BER_precoded"];
for valueIdx = 1:numel(values)
packageCell = values{valueIdx};
if isempty(packageCell)
continue
end
if ~iscell(packageCell)
packageCell = {packageCell};
end
for packageIdx = 1:numel(packageCell)
package = packageCell{packageIdx};
if ~isstruct(package) || ~isfield(package, "metrics")
continue
end
metrics = package.metrics;
for metricIdx = 1:numel(requestedMetrics)
metricName = requestedMetrics(metricIdx);
value = readMetricValue(metrics, metricName);
if isfinite(value)
metricNames(end+1, 1) = metricName; %#ok<AGROW>
berValues(end+1, 1) = value; %#ok<AGROW>
end
end
end
end
metricRows = table(metricNames, berValues, ...
'VariableNames', ["metric_name", "BER"]);
end
function value = readMetricValue(metrics, metricName)
value = NaN;
fieldName = char(metricName);
if isstruct(metrics) && isfield(metrics, fieldName)
value = metrics.(fieldName);
elseif isobject(metrics) && isprop(metrics, fieldName)
value = metrics.(fieldName);
end
end
function runId = resolveRunId(phys, runIds)
if isfield(phys, "run_id")
runId = phys.run_id;
else
runId = runIds(1);
end
end
function bitrate = resolveBitrate(runId, runIds, bitrates)
rowIdx = find(double(runIds) == double(runId), 1, "first");
if isempty(rowIdx)
bitrate = NaN;
else
bitrate = bitrates(rowIdx);
end
end
function color = quickPlotColor(modeIdx)
colors = [ ...
0.1059 0.6196 0.4667; ...
0.8510 0.3725 0.0078];
color = colors(1 + mod(modeIdx - 1, size(colors, 1)), :);
end
function label = decodingModeLabel(decodingMode)
switch decodingMode
case db_decoder.memoryless
label = "memoryless";
case db_decoder.sequencedetection
label = "sequence detection";
otherwise
label = string(decodingMode);
end
end