/** * Pure sweep runner — runs a DcSweepSpec or TempSweepSpec headlessly against * the real SimEngine without any UI or WebWorker dependency. * * WHY cold-start per point: * Element state (capacitor voltages, failure stress, latched failures) * carries across load() calls by design. If we reused one engine instance * across sweep points, hysteresis from capacitor charge at point N would * corrupt the transient at point N+1 — a voltage-divider would look * "correct" only because caps from a previous point happened to pre-charge * to the right level. coldLoad() zeros all element state so every point * starts from the same known condition. * * WHY tail averaging: * Averaging the final 20% of the settle window filters AC ripple from sine * sources (the mean over whole cycles is the DC offset) while remaining * computationally trivial. min/max over the same window expose the ripple * amplitude. This is teaching-grade rather than SPICE-grade but gives * honest, interpretable numbers for the circuits we target. * * WHY a fixed analysis step of 5e-5 s: * The live worker uses an adaptive step (1e-8..1e-2 s). For analysis we * want reproducible, deterministic results across runs, so we use a fixed * step. 5e-5 s (20 kHz) is fast enough to resolve 1 kHz waveforms with * ~20 samples per cycle while keeping the per-point step count bounded: * max settle 0.5 s / 5e-5 s = 10 000 steps per point, × 201 points = 2 M * total steps — acceptable on a modern browser core. * * WHY an engine abstraction (engine.ts): * The sweep steps an AnalysisEngine, not a SimEngine, so the same loop runs * on classic's checked step or on the core (advanced to each grid point). * One engine is chosen per RUN after compiling every point, and the result * reports it with the reasons for any fallback; see engine.ts. * * WHY two run variants: * runSweep (synchronous) is the testable core loop. runSweepAsync yields a * macrotask between points; the analysis worker MUST use it, because a * fully synchronous run inside one message handler would never return to * the worker's event loop, so a queued "cancel" message could never be * processed and cooperative cancellation would be a no-op. */ import type { SimCircuit } from "../sim/engine/sim-engine.js"; import { type DcSweepSpec, type TempSweepSpec, type AnalysisJobResult } from "./jobs.js"; import { type AnalysisEngineOptions, type AnalysisRestartHook } from "./engine.js"; type DcOrTempSweepSpec = DcSweepSpec | TempSweepSpec; /** Fixed simulation step for analysis runs. See module-level why comment. */ export declare const ANALYSIS_STEP_S = 0.00005; export interface SweepHooks extends AnalysisEngineOptions, AnalysisRestartHook { onPoint?: (index: number, total: number) => void; shouldCancel?: () => boolean; } /** * Run a sweep job synchronously and return the result. * * Intended for tests and non-worker callers. Inside the analysis worker use * runSweepAsync instead — a synchronous run never returns to the worker's * event loop, so cooperative cancellation could not work. * * @param spec - Validated sweep specification (call validateJobSpec first). * @param circuit - The circuit to sweep. Mutated via structuredClone per point. * @param hooks - Optional callbacks: onPoint(i, total) for progress, * shouldCancel() checked after each point. */ export declare function runSweep(spec: DcOrTempSweepSpec, circuit: SimCircuit, hooks?: SweepHooks): AnalysisJobResult; /** * Async sweep runner: identical semantics to runSweep, but yields a macrotask * between points so a hosting worker's event loop can process queued messages * — in particular "cancel", which sets the flag behind shouldCancel(). * Without this yield, a cancel posted mid-run would only be handled after the * final point, making cooperative cancellation a no-op. */ export declare function runSweepAsync(spec: DcOrTempSweepSpec, circuit: SimCircuit, hooks?: SweepHooks): Promise; export {};