/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / test / matlab-test.ts
66 lines · 2.0 KBBlameHistoryRaw
1// Convergence test for the MATLAB-runtime solvers, run where real MATLAB
2// exists (not in CI): npx tsx test/matlab-test.ts
3// Exits quietly with a notice when no matlab is on the PATH.
5import { readFileSync } from "fs";
6import { fileURLToPath } from "url";
7import { dirname, join } from "path";
8import { getInstance } from "../src/problems/laplace2d/spec";
9import { getSolver } from "../src/solvers";
10import {
11 ensureChunkie,
12 matlabAvailable,
13 runMatlabSweep,
14} from "../src/cli/matlabRun";
16if (!matlabAvailable()) {
17 console.log("matlab not found on PATH; skipping MATLAB solver tests");
18 process.exit(0);
21const root = join(dirname(fileURLToPath(import.meta.url)), "..");
22const read = (p: string) => readFileSync(join(root, p), "utf-8");
23const sources = {
24 buildProblem: read("src/problems/laplace2d/matlab/build_problem.m"),
25 bdata: read("src/problems/laplace2d/matlab/laplace2d_bdata.m"),
26 solver: read("src/solvers/chunkie-dlp/solver.m"),
27};
29const mustReach: Record<string, number> = {
30 "disk-easy": 1e-10,
31 "star-hard": 1e-9,
32};
34let failures = 0;
35for (const [instId, reach] of Object.entries(mustReach)) {
36 console.log(`\n== ${instId} / chunkie-dlp (MATLAB)`);
37 console.log(" n relMax relL2 solve(s)");
38 let best = Infinity;
39 const { points, matlabVersion } = runMatlabSweep({
40 instance: getInstance(instId),
41 ns: getSolver("chunkie-dlp").sweepN,
42 repeats: 1,
43 sources,
44 setup: ensureChunkie(),
45 });
46 for (const p of points) {
47 best = Math.min(best, p.relMax);
48 console.log(
49 ` ${String(p.n).padStart(4)} ${p.relMax.toExponential(3)} ` +
50 `${p.relL2.toExponential(3)} ${p.solveSeconds.toFixed(4)}`
51 );
52 }
53 console.log(` (MATLAB ${matlabVersion})`);
54 if (best > reach) {
55 console.log(` FAIL: best relMax ${best.toExponential(2)} > ${reach}`);
56 failures++;
57 } else {
58 console.log(` ok (best relMax ${best.toExponential(2)})`);
59 }
62if (failures > 0) {
63 console.error(`\n${failures} failure(s)`);
64 process.exit(1);
66console.log("\nall MATLAB checks passed");
moveopenescclose