Add independent series fit planner

This commit is contained in:
salman committed 2026-08-29 21:11:23 +02:00
1 parent 6a197ea0ba
commit dae874084a
3 files changed
+153 -1

No files matched your search

+64
View File
@@ -4851,6 +4851,70 @@ function parseRunSelection(runNumbers) {
return dataSets;
}
// Describe how a run selection should eventually be executed without starting
// any file or process work. Keeping this decision pure lets the independent
// series workflow be introduced and tested before prepareMSRRunFiles() changes.
// A `+` group is one logical data set; only comma/range-separated data sets can
// be coupled through shared fit parameters.
function planFitExecution(runSelection, sharedFlags, options = {}) {
let dataSets = typeof runSelection === "string"
? parseRunSelection(runSelection) : runSelection;
let validSelection = Array.isArray(dataSets) && dataSets.length > 0
&& dataSets.every(function(dataSet) {
return dataSet && Number.isInteger(dataSet.main) && dataSet.main > 0
&& Array.isArray(dataSet.add)
&& dataSet.add.every(function(run) {
return Number.isInteger(run) && run > 0;
});
});
let sharedParameters = [];
if (sharedFlags && typeof sharedFlags === "object") {
sharedParameters = Object.keys(sharedFlags).filter(function(name) {
return sharedFlags[name] === true;
});
}
sharedParameters.sort();
if (!validSelection) {
return {
mode: "invalid",
dataSetCount: 0,
sharedParameters: sharedParameters,
reason: "invalid-run-selection"
};
}
if (dataSets.length === 1) {
return {
mode: "single",
dataSetCount: 1,
sharedParameters: sharedParameters,
reason: "one-logical-data-set"
};
}
// Explicit cross-run constraints are another form of coupling even if they
// did not originate from a GUI Shared checkbox. This hook will be used for
// editor-owned/custom MSRs when their constraint inspection is added.
if (sharedParameters.length > 0 || options.crossRunCoupling === true) {
return {
mode: "global",
dataSetCount: dataSets.length,
sharedParameters: sharedParameters,
reason: sharedParameters.length > 0
? "shared-fit-parameters" : "cross-run-constraint"
};
}
return {
mode: "series",
dataSetCount: dataSets.length,
sharedParameters: [],
reason: "independent-data-sets"
};
}
function arrayRunNumbers(runNumbers) {
// Existing callers need the list of logical/main runs. Added physical runs are
// deliberately omitted here so parameter tables, msr2data, and PLOT indexing
+1 -1
View File
@@ -10,7 +10,7 @@
"dist:linux": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux rpm AppImage --x64",
"dist:rpm": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux rpm --x64",
"dist:appimage": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux AppImage --x64",
"test:electron": "node tests/log-highlighting.test.js && node tests/action-state.test.js && node tests/electron-missing-data.test.js && node tests/window-layering.test.js && node tests/msr-generation.test.js && node tests/web-runner.test.js && node tests/root-plot-clean.test.js && node tests/parameter-plot.test.js && node tests/help-window.test.js && node tests/release-packaging.test.js && node tests/addrun.test.js && node tests/fit-statistic.test.js && node tests/singlehist-parity.test.js && node tests/url-parameters.test.js && node tests/shared-configuration.test.js"
"test:electron": "node tests/log-highlighting.test.js && node tests/action-state.test.js && node tests/electron-missing-data.test.js && node tests/window-layering.test.js && node tests/msr-generation.test.js && node tests/web-runner.test.js && node tests/root-plot-clean.test.js && node tests/parameter-plot.test.js && node tests/help-window.test.js && node tests/release-packaging.test.js && node tests/addrun.test.js && node tests/fit-statistic.test.js && node tests/series-fit-planner.test.js && node tests/singlehist-parity.test.js && node tests/url-parameters.test.js && node tests/shared-configuration.test.js"
},
"repository": {
"type": "git",
+88
View File
@@ -0,0 +1,88 @@
// Copyright (C) 2026 Zaher Salman
// SPDX-License-Identifier: GPL-3.0-or-later
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const repoRoot = path.resolve(__dirname, "..");
function loadLibrary() {
const code = fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8");
const sandbox = {
console: console,
window: { MSREditor: {} }
};
sandbox.global = sandbox;
vm.runInNewContext(code, sandbox, { filename: "muSRFitlib.js" });
return sandbox;
}
function plain(value) {
return JSON.parse(JSON.stringify(value));
}
function testExecutionModes(lib) {
assert.deepStrictEqual(plain(lib.planFitExecution("", {})), {
mode: "invalid",
dataSetCount: 0,
sharedParameters: [],
reason: "invalid-run-selection"
});
// ADDRUN members belong to one logical data set and do not create a global
// or series fit by themselves.
assert.deepStrictEqual(plain(lib.planFitExecution("2274+2275", {})), {
mode: "single",
dataSetCount: 1,
sharedParameters: [],
reason: "one-logical-data-set"
});
assert.deepStrictEqual(plain(lib.planFitExecution("2274-2280", {
Asy: false,
Lam: false
})), {
mode: "series",
dataSetCount: 7,
sharedParameters: [],
reason: "independent-data-sets"
});
assert.deepStrictEqual(plain(lib.planFitExecution("2274-2280", {
Lam: true,
Asy: false,
Field: true
})), {
mode: "global",
dataSetCount: 7,
sharedParameters: ["Field", "Lam"],
reason: "shared-fit-parameters"
});
assert.deepStrictEqual(plain(lib.planFitExecution("2274,2275", {}, {
crossRunCoupling: true
})), {
mode: "global",
dataSetCount: 2,
sharedParameters: [],
reason: "cross-run-constraint"
});
}
function testStructuredSelection(lib) {
const selection = lib.parseRunSelection("2274+2275,2276");
const plan = plain(lib.planFitExecution(selection, {}));
assert.strictEqual(plan.mode, "series");
assert.strictEqual(plan.dataSetCount, 2);
assert.strictEqual(lib.planFitExecution([{ main: 0, add: [] }], {}).mode, "invalid");
assert.strictEqual(lib.planFitExecution([{ main: 2274, add: [0] }], {}).mode, "invalid");
}
const lib = loadLibrary();
testExecutionModes(lib);
testStructuredSelection(lib);
console.log("series fit planner tests passed");