turbo_moc.progress module

turbo_moc.progress module#

turbo_moc.progress – combines each solver stage’s own progress callback (fraction: float, stage_label: str) into ONE overall (fraction, message) stream, for a UI progress bar – e.g. Dash’s set_progress(…) inside a background=True callback.

Stage weights below are rough, from profiling the reference case (Stage 3, the kernel marching, dominates runtime by far; Stage 1/2/4 are comparatively quick) – meant to make the bar move at roughly the rate work is actually happening, not to be exact. Every turbo_moc solver stage method (run_stage_1_sauer, run_stage_2_ivp/…, run_stage_3_kernel/_mln, run_stage_4_reflex) accepts progress_callback=<callable(fraction, label)>, called with the label it already prints to the terminal (“1 of 4”, “2 of 4”, “3 of 4”, “4 of 4”/”4A of 4”) – only the leading digit is used here to route to a stage weight, so both solvers’ label variants work unchanged. A parenthesized qualifier in the label – “(retry 2 of 6)” from design_nozzle’s automatic retries, “(finished, not converged)” on its final update – is kept in the displayed message. A retry restarts at Stage 1, so the overall fraction intentionally drops back for the new attempt; the reporter itself holds no state between calls.

turbo_moc.progress.make_progress_reporter(set_progress, weights=None)[source]#

Create a callback that combines progress from all solver stages.

Parameters:
set_progresscallable

Receives the (percent_string, message_string) tuple expected by a Dash background callback.

weightsdict, optional

Relative weights for solver stages 1 through 4. The defaults reflect their approximate runtime.

Returns:
callable

A reporter accepting (fraction, stage_label), suitable for a solver’s progress_callback argument.

Examples

Use the returned reporter inside a Dash background callback:

reporter = make_progress_reporter(set_progress)
data = design_nozzle(..., progress_callback=reporter)