/ concept-collection / stan-remote-sampling
Sign in
concept-collection / stan-remote-sampling
stan-remote-sampling / src / parseProgress.ts
14 lines · 606 BBlameHistoryRaw
1import type { ChainProgress } from "./types";
3// Stan progress lines for a single chain look like:
4// "Iteration: 800 / 2000 [ 40%] (Warmup)"
5export const parseProgress = (msg: string): ChainProgress | undefined => {
6 if (!msg.startsWith("Iteration:")) return undefined;
7 const cleaned = msg.replace(/\[|\]/g, "");
8 const parts = cleaned.split(/\s+/);
9 const iteration = parseInt(parts[1]);
10 const totalIterations = parseInt(parts[3]);
11 const warmup = parts[5] === "(Warmup)";
12 if (isNaN(iteration) || isNaN(totalIterations)) return undefined;
13 return { iteration, totalIterations, warmup };
14};
moveopenescclose