/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / src / harness / runner.ts
92 lines · 3.2 KBCodeBlameHistory
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 1// Runs one solver at one resolution on one instance and measures it.
2f05269Connect work-precision curves by resolution, not time; strengthen the timing protocolJeremy Magland 2// The timing protocol (see docs/problems/laplace-dirichlet-2d.md): two
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 3// untimed warmup runs absorb JIT compilation, then timed runs under the
4// policy in ./timing (a floor on the count, then as many more as fit in a
5// time budget), of which the fastest is reported. The minimum is the least
6// contaminated estimator of the solver's own cost, since everything that
7// interferes (scheduling, residual compilation, other load) only ever adds
8// time; all the individual timings are recorded too. The first warmup is
9// timed and reported separately as the cold time. All timing is MATLAB
10// tic/toc inside the numbl session, so browser and node measure the same
11// thing.
13import { runNumblScript } from "./numblRun";
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 14import { DEFAULT_TIMING, timedRunLines, type TimingPolicy } from "./timing";
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 15import type { Laplace2dInstance } from "../problems/laplace2d/spec";
16import { evalErrors } from "../problems/laplace2d/exact";
18export interface MatlabSources {
19 /** build_problem.m source */
20 buildProblem: string;
21 /** laplace2d_bdata.m source */
22 bdata: string;
23 /** solver.m source of the solver under test */
24 solver: string;
27export interface RunPointRequest {
28 instance: Laplace2dInstance;
29 n: number;
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 30 /** How the timed runs are counted (default DEFAULT_TIMING). */
31 timing?: TimingPolicy;
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 32 /** Also evaluate the solution on the visualization grid. */
33 wantGrid?: boolean;
34 sources: MatlabSources;
37export interface RunPoint {
38 n: number;
2f05269Connect work-precision curves by resolution, not time; strengthen the timing protocolJeremy Magland 39 /** The fastest of the timed runs. */
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 41 /** Every timed run, in order; its length is how many the policy ran. */
43 coldSeconds: number;
44 relMax: number;
45 relL2: number;
46 uEval: Float64Array;
47 uGrid: Float64Array | null;
50function numLiteral(x: number): string {
51 if (!Number.isFinite(x)) throw new Error(`bad numeric literal: ${x}`);
52 return String(x);
55export function runPoint(req: RunPointRequest): RunPoint {
56 const { instance, n } = req;
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 57 const timing = req.timing ?? DEFAULT_TIMING;
59 const main = [
60 "% generated by the fastandaccurate harness",
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 61 `prob = build_problem(${numLiteral(instance.a)}, ${numLiteral(instance.k)}, ` +
62 `${numLiteral(instance.p ?? 0)}, ${numLiteral(instance.d)}, ${wantGrid ? 1 : 0}, ` +
63 `${instance.nearBoundary ? 1 : 0});`,
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 64 `tic; out = solver(prob, ${n}); res_cold = toc;`,
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 66 ...timedRunLines(`out = solver(prob, ${n})`, "res_times", timing),
68 "res_ugrid = out.uGrid;",
69 "",
70 ].join("\n");
71 const { vars } = runNumblScript(
72 main,
73 {
74 "build_problem.m": req.sources.buildProblem,
75 "laplace2d_bdata.m": req.sources.bdata,
76 "solver.m": req.sources.solver,
77 },
78 ["res_cold", "res_times", "res_ueval", "res_ugrid"]
79 );
80 const times = Array.from(vars.res_times);
81 const { relMax, relL2 } = evalErrors(instance, vars.res_ueval);
82 return {
83 n,
86 coldSeconds: vars.res_cold[0],
87 relMax,
88 relL2,
89 uEval: vars.res_ueval,
90 uGrid: wantGrid ? vars.res_ugrid : null,
91 };
moveopenescclose