1// A work-precision sweep: run one solver across its resolution list on
2// one instance, reporting each point as it lands.
4import { runPoint, type MatlabSources, type RunPoint } from "./runner";
5import { DEFAULT_TIMING, type TimingPolicy } from "./timing";
6import type { Laplace2dInstance } from "../problems/laplace2d/spec";
7import { sweepNFor, type SolverManifest } from "../solvers";
9export interface SweepOptions {
10 instance: Laplace2dInstance;
11 solver: SolverManifest;
12 sources: MatlabSources;
13 timing?: TimingPolicy;
14 /** Restrict the sweep to n values <= this (for quick runs). */
15 maxN?: number;
16 onPoint?: (point: RunPoint, index: number, total: number) => void;
17}
19export function runSweep(opts: SweepOptions): RunPoint[] {
20 const ns = sweepNFor(opts.solver, opts.instance.id).filter(
21 (n) => opts.maxN === undefined || n <= opts.maxN
22 );
23 const points: RunPoint[] = [];
24 ns.forEach((n, i) => {
25 const p = runPoint({
26 instance: opts.instance,
27 n,
28 timing: opts.timing ?? DEFAULT_TIMING,
29 sources: opts.sources,
30 });
31 points.push(p);
32 opts.onPoint?.(p, i, ns.length);
33 });
34 return points;
35}