From 7da52d618b9056365e221d81dfd93eb89684392b Mon Sep 17 00:00:00 2001 From: Valentin Hirschi Date: Fri, 20 Nov 2026 13:43:17 +0000 Subject: [PATCH 01/15] profile: --measured-precisions, a 100 % row, no class column - The stable-digits tables gain a 100 % row (the best point; the classes add up to N) and lose their class column (a class holds floor(p N) - floor(p' N) points; --json keeps count and failed; a class's failed points follow its digits, "0.00 (2 failed)"). - benchmark.measured_precisions / --measured-precisions (space- or comma-separated; binary64/double/b64, double-double/dd, arb[:DIGITS]): each entry its own pair of stability tables in the order given; default ["binary64"] (config.models.DEFAULT_MEASURED_PRECISIONS), today's tables. An entry below the ground truth is evaluated as binary64 is, in its arithmetic with the default checks, read against the truth, its digits capped to its range and to what the truth certifies; the ground truth's own precision gets its estimates-only pair; above it or twice: refused before any work. Each extra precision is a stream of its own; the plan counts it at a lower bound until measured, the deadline at its measured cost. - --json: the other precisions under stability_setup.measured_precisions (absent by default); per-sample records of a wider precision with its value and sectors as exact decimal text, every precision's with estimate_digits_uncapped and true_digits_uncapped (new last fields); --samples-output gains measured_precisions. - Config registry 160; docs, all_options, descriptions, tests. Co-Authored-By: Claude Opus 5.5 --- .../docs/user/command-line-interface.md | 61 +- .../docs/user/profiling-and-benchmarking.md | 4 +- pyamplicol/examples/all_options.toml | 8 + .../src/pyamplicol/cli/profile_options.py | 16 + pyamplicol/src/pyamplicol/config/models.py | 70 +++ pyamplicol/src/pyamplicol/loop_profile.py | 538 ++++++++++++++++-- .../src/pyamplicol/reporting/descriptions.py | 40 +- .../src/pyamplicol/reporting/loop_profile.py | 127 ++++- pyamplicol/tests/unit/test_cli_parser.py | 64 +++ pyamplicol/tests/unit/test_config_models.py | 6 +- .../unit/test_loop_profile_statistics.py | 168 +++++- 11 files changed, 992 insertions(+), 110 deletions(-) diff --git a/pyamplicol/docs/user/command-line-interface.md b/pyamplicol/docs/user/command-line-interface.md index 0716e87eb3..912da0e85e 100644 --- a/pyamplicol/docs/user/command-line-interface.md +++ b/pyamplicol/docs/user/command-line-interface.md @@ -1149,6 +1149,47 @@ best-effort counts with the binary64 time, without the truth-based columns; the header says `none (estimates only)` and the JSON's `ground_truth` `{"arithmetic": "none", "label": "none"}`. +**Measured precisions.** `--measured-precisions` (`benchmark.measured_precisions`, +a list; on the command line space- or comma-separated, +`--measured-precisions double dd arb:60`) names the precisions whose +stability the stability run measures, each its own pair of tables in the +order given; the default is `binary64` alone (today's tables). An entry is +`binary64` (`double`, `b64`) or what `--ground-truth` accepts +(`double-double`/`dd`, `arbitrary`/`arb`, `arbitrary:DIGITS`/`arb:DIGITS`). +Each entry's points are evaluated as binary64's are, in its arithmetic: the +default checks (one default rotation; on TIRust's points also the rescaled +reduction-direction check), a refused point served best-effort, lane rescue +as that arithmetic has it (`--no-lane-rescue` turns it off). An entry below +the ground truth is read against it ("Stable digits of double-double vs +arb(60)"): its true and estimated digits capped to its own range +(double-double -log10(2^-106) = 31.92, arbitrary precision its digits) and +to what the ground truth certifies (its range; an arbitrary-precision truth +at most its cross-check's 2^-106), the title adding "capped at the ground +truth's D digits" when that is the lower. The ground truth's own precision +has its estimates-only tables ("Estimated digits of arb(60) (the ground +truth)" and "Default checks, estimates only, arb(60)"): its points are +evaluated in it with the default checks, a stream of its own beside the +reference's evaluations. A ground truth not listed gets no table and no +checks beyond its certification above (with an arbitrary-precision truth +the cross-check between the backends and the checked re-run of a reference +it does not certify; with one backend one checked evaluation per point). An +entry above the ground truth (or listed twice) is refused before any work; +with `--ground-truth none` every entry is estimates-only. binary64's stream +always runs (its tables only when listed). The precisions given are +honoured; the stability plan and its ETA count each extra stream at a lower +bound of its point (a checked binary64 point below the ground truth, the +plain reference point for the ground truth's own) until the run measures it, +and the default budget's deadline admits points at the measured costs of +every stream. The runtime timing is not changed by the option. In `--json` +the other precisions' rows are under `stability_setup.measured_precisions` +(each entry its precision, `estimates_only`, `digits_cap`, +`capped_by_truth` and `stability`, the same rows as `stability`; binary64's +entry `stability: null`, its rows where they always are); the key is absent +with the default. The per-sample records (`--json`, `--samples-output`: its +`measured_precisions`) of a wider precision hold its value and sectors as +the exact decimal text of its carrier's value; every precision's records +also carry `estimate_digits_uncapped` and `true_digits_uncapped`. + **Stability.** Over N flat points (`benchmark.stability_points` / `--stability-points`; by default as many as one minute per worker affords, at least five; with `--completion-time` what is left of it; drawn with @@ -1201,15 +1242,19 @@ reference failed has an unknown truth and is left out (shown as "no ref."). The measured points (N in what follows) are all others. The measured points are sorted by true digits from worst to best. At the -percentiles 1 per mil, 1 %, 10 % and 50 % the table shows the true digits of -the point of rank floor(p N) (1-based; the 50 % row is the median, the lower -middle point for an even N), and over the class of points of rank -floor(p' N) < rank <= floor(p N) (p' the previous percentile, 0 for the -first) the point count (with its failed points), the min, median and max of -|estimated - true| and the median of estimated - true (positive: the -estimate is optimistic), both over the class's points with an estimate. At +percentiles 1 per mil, 1 %, 10 %, 50 % and 100 % the table shows the true +digits of the point of rank floor(p N) (1-based; the 50 % row is the median, +the lower middle point for an even N; the 100 % row the best point), and +over the class of points of rank floor(p' N) < rank <= floor(p N) (p' the +previous percentile, 0 for the first; the classes add up to N) the min, +median and max of |estimated - true| and the median of estimated - true +(positive: the estimate is optimistic), both over the class's points with +an estimate. A class holds floor(p N) - floor(p' N) points, so the table +shows no count (`--json` keeps each class's `count` and `failed`); a class +with points without a value says so after its digits, `0.00 (2 failed)`. At small N a class can be empty (`-`; the table prints the N a populated class -needs: 1000 measured points for the 1 per mil class, 2 for the median). +needs: 1000 measured points for the 1 per mil class, 2 for the median, 1 +for the 100 % row). A second table compares the default checks with the truth, per backend: the measured points, those served best-effort / without a value in binary64, the points flagged unstable diff --git a/pyamplicol/docs/user/profiling-and-benchmarking.md b/pyamplicol/docs/user/profiling-and-benchmarking.md index 8d03b3f7c6..11c89ffa25 100644 --- a/pyamplicol/docs/user/profiling-and-benchmarking.md +++ b/pyamplicol/docs/user/profiling-and-benchmarking.md @@ -247,7 +247,9 @@ group) with the ratio between the backends (the faster highlighted), and the stable digits of pure binary64 against a re-run in the reference precision (`--ground-truth`: double-double by default, or arbitrary precision) over flat points at the percentiles 1 per mil, -1 %, 10 % and 50 % (a point a backend refuses in binary64 measured with its +1 %, 10 %, 50 % and 100 % (other precisions too with `--measured-precisions`, +each its own tables, e.g. `--measured-precisions double dd --ground-truth +arb:60`; a point a backend refuses in binary64 measured with its best-effort value at its true digits; only a point with no binary64 value ranked at 0 digits), with the accuracy of the default estimate against that truth (one default rotation on NinjaRS's points; one default rotation and diff --git a/pyamplicol/examples/all_options.toml b/pyamplicol/examples/all_options.toml index b46a3cf5f5..cfe087a6ad 100644 --- a/pyamplicol/examples/all_options.toml +++ b/pyamplicol/examples/all_options.toml @@ -568,6 +568,14 @@ n_core = 10 # the runtime timing then times its multiplier even when its minimal counts # exceed the budget. ground_truth = "double-double" +# benchmark.measured_precisions: Loop artifacts: the precisions whose +# stability the stability run measures (`--measured-precisions`), each its +# own pair of tables in this order: "binary64" ("double", "b64"; the default +# ["binary64"]), "double-double" ("dd"), "arbitrary[:DIGITS]" ("arb"), each +# strictly below ground_truth (true digits against it) or ground_truth itself +# (its estimates only, with the default checks); with ground_truth "none" +# every entry is estimates only. +measured_precisions = ["binary64"] # benchmark.checked: Loop artifacts: time the checked mode (`--checked`): the # backends' own acceptance checks, a refused point served best-effort, the # default backend as auto. Default false: one fully optimistic binary64 pass diff --git a/pyamplicol/src/pyamplicol/cli/profile_options.py b/pyamplicol/src/pyamplicol/cli/profile_options.py index 3c8bd3630c..75d0ad563c 100644 --- a/pyamplicol/src/pyamplicol/cli/profile_options.py +++ b/pyamplicol/src/pyamplicol/cli/profile_options.py @@ -88,6 +88,22 @@ def add_profile_mode_options(parser: argparse.ArgumentParser) -> None: "at its minimal counts; --no-all-backends: the default only)" ), ) + parser.add_argument( + "--measured-precisions", + dest="benchmark.measured_precisions", + action="extend", + nargs="+", + default=argparse.SUPPRESS, + metavar="PRECISION", + help=( + "loop artifacts: the precisions whose stability --stability " + "measures (benchmark.measured_precisions), each its own pair of " + "tables in the order given: binary64 (double, b64; the default), " + "double-double (dd), arbitrary (arb) or arbitrary:DIGITS, at most " + "the --ground-truth precision (that one: its estimates only, with " + "the default checks); space- or comma-separated" + ), + ) parser.add_argument( "--ground-truth", dest="benchmark.ground_truth", diff --git a/pyamplicol/src/pyamplicol/config/models.py b/pyamplicol/src/pyamplicol/config/models.py index 58abbd7a87..5a8b8514fc 100644 --- a/pyamplicol/src/pyamplicol/config/models.py +++ b/pyamplicol/src/pyamplicol/config/models.py @@ -542,6 +542,62 @@ def _ground_truth(value: object) -> str: ) +# The precisions a loop profile's stability run measures by default +# (``benchmark.measured_precisions``, ``--measured-precisions``): this one +# line sets the default. +DEFAULT_MEASURED_PRECISIONS: tuple[str, ...] = ("binary64",) + + +def _measured_precision(value: object) -> str: + """A ``benchmark.measured_precisions`` entry in its canonical spelling: + "binary64" (also "double", "b64"), or a reference precision as + ``_ground_truth`` spells it ("double-double", "arbitrary", + "arbitrary:DIGITS"; "none" is no precision).""" + + text = value.strip().lower() if isinstance(value, str) else "" + if text in ("binary64", "double", "b64"): + return "binary64" + try: + canonical = _ground_truth(text) + except ConfigurationError: + canonical = "none" + if canonical == "none": + raise ConfigurationError( + "benchmark.measured_precisions entries must be binary64 (double, " + "b64), double-double (dd), arbitrary (arb) or arbitrary:DIGITS " + f"(arb:DIGITS); got {value!r}" + ) + return canonical + + +def _measured_precisions(value: object) -> tuple[str, ...]: + """``benchmark.measured_precisions`` canonical, in the order given: at + least one entry, no duplicate.""" + + if isinstance(value, str): + value = [value] + if isinstance(value, (list, tuple)): + # An entry may hold several, comma-separated (``--measured-precisions + # b64,dd``). + value = [ + part + for entry in value + for part in (entry.split(",") if isinstance(entry, str) else [entry]) + if not isinstance(part, str) or part.strip() + ] + if not isinstance(value, (list, tuple)) or not value: + raise ConfigurationError( + "benchmark.measured_precisions must be a non-empty list of precisions" + ) + canonical = tuple(_measured_precision(entry) for entry in value) + for position, entry in enumerate(canonical): + if entry in canonical[:position]: + raise ConfigurationError( + f"benchmark.measured_precisions lists {entry} twice" + ) + return canonical + + def _finite_float( value: float, name: str, *, minimum: float, exclusive: bool = False ) -> float: @@ -1810,6 +1866,15 @@ class BenchmarkConfig: ground_truth: str = field( default=DefaultStr("double-double"), metadata=_setting("str") ) + # The precisions whose stability the stability run measures + # (``--measured-precisions``), each its own pair of tables in this + # order: binary64 (the default, ``DEFAULT_MEASURED_PRECISIONS``) and + # the reference precisions up to the ground truth's (the ground truth's + # own: its estimates only); "dd", "arb[:DIGITS]", "double", "b64" + # accepted. + measured_precisions: tuple[str, ...] = field( + default=DEFAULT_MEASURED_PRECISIONS, metadata=_setting("list_str") + ) # The runtime timing of a loop profile in the checked mode (``--checked``): # the backends' own acceptance checks, a refused point served best-effort # and the default backend as "auto". False (the default): one fully @@ -1861,6 +1926,11 @@ def __post_init__(self) -> None: "ground_truth", DefaultStr(truth) if isinstance(self.ground_truth, DefaultStr) else truth, ) + object.__setattr__( + self, + "measured_precisions", + _measured_precisions(self.measured_precisions), + ) if self.all_backends is not None and type(self.all_backends) is not bool: raise ConfigurationError("benchmark.all_backends must be a boolean") if self.completion_time is not None: diff --git a/pyamplicol/src/pyamplicol/loop_profile.py b/pyamplicol/src/pyamplicol/loop_profile.py index b096f44889..b791f7e443 100644 --- a/pyamplicol/src/pyamplicol/loop_profile.py +++ b/pyamplicol/src/pyamplicol/loop_profile.py @@ -46,21 +46,23 @@ Both are read on the finite part of the total (the sum over the squared-order sectors; the poles are not computed) and capped to binary64's range [0, -log10(2^-53)] (``stable_digits``). The MEASURED points are those -whose reference exists and those that failed in binary64 (no -value, whatever the reference); a binary64 value without a reference leaves -the truth unknown and is counted apart. They are sorted by true digits from -worst to best; at each percentile p of ``PERCENTILES`` the true digits of -the point of rank floor(p N) (1-based, N measured points; 50 %: the lower -middle point) are reported, with the deviation |estimated - true| (min, -median, max) and the signed median (estimated - true: positive when the -estimate is optimistic) over the points with an estimate in the class of the -points of rank floor(p' N) < rank <= floor(p N), p' the previous percentile -(0 for the first). A class may be empty at small N (``needed_points``). The -default checks flag a point unstable when its estimate exceeds the default -target (the relative metric of the rescue, per sector) or when it failed in -binary64 (a failure is reported, so detected); a point is truly inaccurate -when its true relative error exceeds the same target or it has no binary64 -value. +whose reference exists and those that failed in binary64 (no value, whatever +the reference); a binary64 value without a reference leaves the truth +unknown and is counted apart. They are sorted by true digits from worst to +best; at each percentile p of ``PERCENTILES`` the true digits of the point +of rank floor(p N) (1-based, N measured points; 50 %: the lower middle +point; 100 %: the best point) are reported, with the deviation |estimated - +true| (min, median, max) and the signed median (estimated - true: positive +when the estimate is optimistic) over the points with an estimate in the +class of the points of rank floor(p' N) < rank <= floor(p N), p' the +previous percentile (0 for the first); the classes add up to N. The +--measured-precisions other than binary64 are read the same way at their own +precision (``MeasuredPrecision``). A class may be empty at small N +(``needed_points``). The default checks flag a point unstable when its +estimate exceeds the default target (the relative metric of the rescue, per +sector) or when it failed in binary64 (a failure is reported, so detected); +a point is truly inaccurate when its true relative error exceeds the same +target or it has no binary64 value. Every evaluation goes through the public ``Runtime.evaluate`` with explicit ``reduction=``; a backend that refuses the process (``ReductionUnavailable``) @@ -92,8 +94,15 @@ # with the stability run asked for sets its points). STABILITY_FALLBACK = 5 # The percentiles of the sorted true digits (worst first): 1 per mil, 1 %, -# 10 % and 50 % (the median). -PERCENTILES = (Fraction(1, 1000), Fraction(1, 100), Fraction(1, 10), Fraction(1, 2)) +# 10 %, 50 % (the median) and 100 % (the best point); their classes add up +# to every measured point. +PERCENTILES = ( + Fraction(1, 1000), + Fraction(1, 100), + Fraction(1, 10), + Fraction(1, 2), + Fraction(1, 1), +) # binary64's range of stable digits: -log10 of its unit roundoff. BINARY64_DIGITS = 53 * math.log10(2.0) @@ -178,19 +187,153 @@ def ground_truth(text: str) -> GroundTruth: return GroundTruth("arbitrary", default_arbitrary_digits()) -def stable_digits(relative_error: float) -> float: - """-log10(relative error), capped to [0, ``BINARY64_DIGITS``]: an exact - agreement (or one below binary64's roundoff) counts all of binary64's - digits, an error of 100 % or more (or a non-finite one) none.""" +# The stream key prefix of a measured precision other than binary64 +# (``MeasuredPrecision.stream``): "measured: