Skip to content

pyAmpliCol: import upstream main (profile --measured-precisions, #507 review follow-up) - #521

Merged
oliviermattelaer merged 23 commits into
mainfrom
pyamplicol-import-measured-precisions
Nov 23, 2026
Merged

oliviermattelaer merged 23 commits into
mainfrom
pyamplicol-import-measured-precisions

Conversation

@ValentinHirschi

Copy link
Copy Markdown
Contributor

Follows #507, now merged; MadGraph7 main is merged into this branch. This PR
adds the delta from pyAmpliCol 3300bdc16 to upstream main
1b9aada8dc0f7bdc37da3f7a0e8cb7d1bc3a28ac (13 commits), plus #507's review
nits.

What changes for MadGraph7 users

  • [amplicol] (tree level): nothing. The delta has no tree-level,
    generation or UMAMI change.
  • For direct users of the one-loop tools:
    • pyamplicol profile --measured-precisions (benchmark.measured_precisions):
      stability and runtime tables for each precision given, e.g.
      double dd. The tables gain a 100 % row and lose the "class" column.
    • Runtime-options strings: a one-line string is a path only when it
      names an existing file; otherwise it is read as TOML, so
      "[evaluation]" is an empty options table.
    • Profile stage times: "Time per point and stage" no longer shows 0 ns
      for every stage when binary64 has a single timed call; with
      --measured-precisions, binary64's runtime and checks tables are now
      titled ", binary64" like the other precisions'.
    • Tests only: the SDK thread-count test waits for Symbolica's
      short-lived licence-check threads to exit before it counts.
  • Wheel: 109.9 MB (limit 237.5 MB).

#507's review nits

  1. NinjaRS records after a failed evaluation: no code change was needed.
    NinjaRS clears a thread's records when an evaluation starts:
    FastAmplitude::evaluate calls clear_instabilities(), and
    Amplitude::evaluate_batch_with_inputs and BoxReducer::evaluate_batch
    call clear_box_gram_refusals(). A failed
    evaluation's records therefore never reach the next one. Upstream added
    this explanation as comments at the three places the review names.
  2. One-line TOML read as a path: fixed upstream by the rule above.
    rusticol_virtual_set_options takes TOML text only, so it has no such
    ambiguity (the C++ wrapper reads a file only through its explicit set_options_file).
  3. Misplaced doc paragraph in the loop-plan reader: moved upstream to
    read_bounded, and the over-long doc line rewrapped (comments only).
  4. Duplicate "about 70 s" in pyamplicol.yml: each group of the light
    one-loop step now has its own measured figure, about 20 s and about 30 s.

How it was imported

The same procedure as #507 (import_pyamplicol.sh, a real merge). The SHAs
imported earlier are reproduced. One conflict, in the earlier part of the
delta: the registry count in tests/unit/test_config_models.py. Upstream
now has 160 fields; with MadGraph7's two it is 162. The other files that
MadGraph7 changes locally merged cleanly, with their MadGraph7 lines
unchanged. The delta adds no test file and does not change upstream's CI
selection, so the test lists are unchanged apart from nit 4.

Tested (Linux x86_64, SYMBOLICA_LICENSE unset)

Run on this head:

  • Build through MadGraph7's installer path.
  • Version, dependency and lock checks; the CI typing and ruff steps; the
    registry count (162); every test path in pyamplicol.yml exists.
  • Self-test 8/8.
  • CI's light one-loop step, its whole selection in one pytest process:
    465 passed, 48 skipped, 24 deselected.
  • The changed upstream test files, one process each:
    • loop_profile_statistics 43, loop_v2_orders_profile 67, cli_parser 99
      passed;
    • runtime_options 44 passed, 7 failed. Six of the failures are its SDK
      tests, which need the developer SDK library that MadGraph7 does not
      stage, as in pyAmpliCol: import upstream main (lane rescue, runtime options, faster loads and profiles) #507. The seventh,
      test_the_thread_bound_and_its_fallback, counts the process's threads
      and fails on the 384-core test host, where it finds 63 more than it
      allows. They are not pyAmpliCol's: importing numpy alone starts them
      there (its BLAS pool), and with OPENBLAS_NUM_THREADS=1 upstream's copy
      of the test counts 3 threads. It failed the same way before this delta.
      The file is not in MadGraph7's CI.
  • MadGraph7's pyAmpliCol unit tests: 205 of 206 OK. The failure,
    test_mg7_launch test_the_run_card_only_takes_known_validation_types,
    passes on its own and fails only when its whole module runs. It is
    MadGraph7 main's own test: this branch changes nothing outside
    pyamplicol/ and pyamplicol.yml.
  • Through MadGraph7's installed copy,
    pyamplicol profile <u u~ > d d~ g [QCD]> --measured-precisions double dd --ground-truth arb:60 --completion-time 20s
    finishes in 23 s. Its tables are titled "Runtime per reduction backend,
    binary64" and "..., double-double", and binary64's "Time per point and
    stage" has non-zero stage rows (1.1 ms per point in total).

Not rerun, since the delta changes no Rust, tree-level or SDK code: the
loop-value comparison, the Rust tests, the C client against the SDK,
test_amplicol_syntax and the test_mg7_amplicol cases. Their results on
the previous head and on #507 stand.

🤖 Generated with Claude Code

ValentinHirschi and others added 18 commits November 20, 2026 13:43
- 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 <noreply@anthropic.com>
…y CI host has

test_the_sdk_sets_every_key_on_its_own asked for 5 threads and expected 5
back. On a 4-core runner the count is reduced to the usable cores (threads 4,
threads_requested 5), so the loop tier's shard 7 failed on main. Two more
tests asked for 3 threads and failed on a 2-core host. They now ask for
counts of at most 2; the reduction itself is covered by the affinity tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read against the truth

- With --runtime every --measured-precisions entry other than binary64 gets
  its own "Runtime per reduction backend, <precision>" and "Time per point
  and stage, <precision>" tables after binary64's: the same optimistic
  pass per backend in its arithmetic (profile_virtual(precision=), its own
  process), from binary64's counts and budget for that backend
  (--target-runtime per precision), its batch fitted to its measured cost
  down to one point (benchmarking._fitted_calls; a --batch-size given
  honoured), the ground truth's multiplier against it (none for the
  truth's own precision). --json: runtime_measured, absent by default
  (LoopProfileReport.cli_json).
- Fix: a measured precision below the ground truth lost its truth in its
  per-sample records (a local shadowed it).
- Tests: the 100 % row in the CLI profile test; the fitted batch; the
  measured runtime rows and their JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…truth evaluated once

- Root cause of the runtime inflation: _profile_virtual_calls drew each
  call with batches(k), whose size is the batch the point batches were
  built with (binary64's 16), while a measured precision's batch is fitted
  smaller (_fitted_calls) and the time per point divides by the fitted
  size: gg_ggg NinjaRS double-double 7.17 s for a 16-point call reported as
  3.59 s per point (16 / 2 = 8 x its 0.448 s), TIRust 3.48 s / 4. The calls
  now take batches(k, batch_size); the measuring call is the fitted
  precision's warm-up (no other).
- The ground truth listed: its runtime stream is timed once (the multiplier
  of binary64's rows and of the others, no multiplier pass; rule B leaves a
  given precision in); its stability stream (the default checks) is also
  its reference (accepted values; the same value bit for bit as the plain
  evaluation on g g > g g g in dd and arb(60)), the certification of an
  arbitrary-precision truth unchanged (one backend: its checked references).
- A precision not listed is not evaluated (binary64 included); binary64's
  runtime worker only for the ground truth's multiplier another listed
  precision shows when the truth itself is not listed.
- Each precision's failure causes under its own tables.
- Tests: the fitted batch's calls (fails on 2c25bfe), the listed ground
  truth evaluated once and an unlisted binary64 not at all, the reference
  from the truth's stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e scope rules

- lower_bound(binary64=, extra=): binary64's calls only when listed, every
  other measured precision's stream at least two binary64 points in the
  runtime timing (its measuring call and one timed call) and one binary64
  point per stability point; rules A and B (and the decider's bound) pass
  them, a listed ground truth counted as the reference it is.
- The whole command's ETA counts each other precision's runtime calls of
  every backend (its measuring point and its budget, at its lower bound)
  until they run; binary64's runtime entries only when it is timed.
- --completion-time: binary64's share keeps the other precisions'
  estimates out; each of their calls gets the time left when it starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n evaluation

MadGraph7 #507 review nit: the thread-local instability and box-Gram
records are taken only after a successful evaluate. At the pinned
NinjaRS (a2546170) that suffices: FastAmplitude::evaluate starts with
clear_instabilities() and Amplitude::evaluate_batch_with_inputs (every
evaluate_batch* goes through it) with clear_box_gram_refusals(), before
anything can fail, so a failed evaluation's records never reach the
next one. Comments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s TOML

MadGraph7 #507 review nit: a one-line TOML text without "=" ("[evaluation]",
a valid empty table) was taken for a path and refused with "cannot read
runtime options". The rule is now: a one-line string naming an existing
file is a path, else TOML; one that is neither is refused naming both
readings (a mistyped path included). The native readers take TOML texts
only (files through set_options_file) and already read "[evaluation]" as
an empty table; the parity tests cover "[evaluation]", "[evaluation]\n",
a bare word and an existing file whose name has no "=".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MadGraph7 #507 review nit: the paragraph describing read_bounded sat above
read_binary_bounded, so rustdoc merged two descriptions; moved, and
read_threads' over-long doc line rewrapped. Comments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ies; typing gate

- mpreview's 0001: the typing gate (tools/typing/check_public_typing.py)
  passes again on reporting/loop_profile.py.
- mpreview's 0002, extended: a measured precision whose cap is what an
  arbitrary-precision truth certifies (arb(60) against arb(140)) is read
  per point to what that point's reference certifies: the agreement the
  backends' references reached, or (one backend, or the checked re-run)
  that reference's own checked estimate, which now travels in its record;
  at most the precision's and the truth's range. b9fb969 read every such
  point at 2^-106 (31.91 digits, est-true 0.00). binary64 and double-double
  readings unchanged.
- A listed ground truth's stability stream priced at its checks'
  evaluations per point; the progress log names a measured precision's
  calls; docs: 31.91, the multiplier with a listed truth, what rule A sees
  of a listed truth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A one-line runtime-options string is a path only when it names an existing
file, else TOML; comments on NinjaRS's lane records and on read_bounded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ns, review nits of #507)

Imports MadGraphTeam/pyamplicol main b8d028ca1 (11 commits over 3300bdc16):
`pyamplicol profile --measured-precisions` (benchmark.measured_precisions:
stability and runtime tables per measured precision, a 100 % row, the
"class" column removed); a one-line runtime-options string is a path only
when it names an existing file, else TOML; comments in the loop runtime
(rust/loop-reduction runtime, rusticol-core loop plan) answering #507's
review; runtime-options read-back tests with at most two threads.

One conflict, resolved by hand:
- tests/unit/test_config_models.py: upstream's registry grew 159 -> 160
  (benchmark.measured_precisions); with MadGraph7's
  process.flavor_blind_strict and generation.pack_payloads the registry has
  162.
The six other files MadGraph7 edits locally auto-merged with their MadGraph7
lines unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #507: the two comment blocks above the light one-loop step both
said "about 70 s together". Each group now has its own figure, measured
locally with one pytest process per group: the four files of the
lane-rescue / runtime-options import take about 45 s, the seven fastest
restored engine tests about 30 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry out of the unlicensed step)

One conflict, the comment above the light one-loop step: nit 4's per-group
timings are kept, with the new-file group now three files (about 20 s,
measured: test_relative_text, test_loop_v2_wide, test_loop_v2_tracked_precision)
and #507's sentence on why test_loop_v2_process_history is not listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_the_sdk_thread_bound_counted failed on CI's 4-core runners with
(count, before, after) = (1, 2, 5). The two extra threads are Symbolica's
licence checks, started by the SDK open: each waits for its server's answer
and then exits. On a near host that takes about 20 ms; on the runner they
outlived the 0.3 s settling window.

The child now takes its count once it is steady and within the caller's
limit, waiting up to a minute for that. A pool never exits, so a pool above
the bound still fails the test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two display defects of `pyamplicol profile` reported from a run with
`--measured-precisions double dd --completion-time 30s`:

- "Time per point and stage" showed 0 ns for every stage and the whole time
  under "rest" when binary64 had one timed call and no warm-up call before
  it (a warm entry). The stage collector looked for the executor's report
  attribute, which existed only after the executor's first call. The native
  executor now has it from construction.
- With a list of measured precisions, binary64's runtime and checks tables
  had bare titles while every other precision's named it. They now end in
  ", binary64". Without a list the titles are unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…sions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Imports upstream 1b9aada8dc0f7bdc37da3f7a0e8cb7d1bc3a28ac: two commits over
b8d028ca12 (profile: stage times of a first call and binary64 named in the
listed tables; tests: the thread-count tests wait for Symbolica's
licence-check threads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ValentinHirschi ValentinHirschi added this to the Feature freeze milestone Nov 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-21T13:46:26.764512Z
We couldn’t complete this review. Comment @codex review to try again.
4fc11c8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown
Contributor

How CI reacts to this PR

  • Not a draft: the full CI runs automatically when the PR is opened and on every push.
  • Draft: only the unittest and IOtest workflows run. Mark the PR "Ready for review" to start the full CI.
  • run-ci label: while this label is on the PR, every job keeps running after a failure, so you see all failures. Without it, the first failing job cancels the other runs of that commit.
  • Closing or merging: the unfinished CI runs of this PR are cancelled. A merge gets its own run on main.
  • Pushes to main: the full CI runs after each merge.
  • Other branches: run CI only through workflow_dispatch.
  • Forks: the runs use a read-only token, so they cannot cancel each other.
  • Merge: a green CI and one approval are required to merge.

@ValentinHirschi

ValentinHirschi commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

The two red jobs, acceptancetest_core_1 and acceptancetest_mg7_uncovered, are not caused by this PR. Each stops in the restore_delphes step with "No delphes-ubuntu24 cache from main, and only main builds Delphes", and its Delphes test then has no Delphes.

Update: re-running will not help. The warm job on main saves the Delphes cache under delphes-root-ubuntu24-<run> instead of delphes-ubuntu24-<run>, so no pull request finds it. Details and a possible fix are in #522.

🤖 Generated with Claude Code

The job mounted only pyamplicol/ into its container. There
src/pyamplicol/assets/api_templates/umami/umami.h, a symlink into
madspace/, has no target, and the build stops with "build inputs must be
regular files". The job ran only for releases until pull requests started
running the full workflow, so the failure appeared on every non-draft pull
request.

The container now mounts the repository root and works in pyamplicol/, as
the macOS wheel jobs do on their runners.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ValentinHirschi

ValentinHirschi commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

The cancelled pyAmpliCol jobs came from one real failure: manylinux release wheel and native deployment stopped, and the fail-fast step then cancelled the rest of the run.

The cause is not this import. Besides the wheel from the retained sdist, that job builds a second wheel from the checkout, and in MadGraph7 this cannot work:

  • api_templates/umami/umami.h is a symlink into madspace/, and the job mounts only pyamplicol/ into its container ("build inputs must be regular files");
  • the checkout has no prepared models, which only the sdist carries ("release prepared-model source store inventory is invalid").

The job used to run only for releases. Since pull requests run the full workflow it fails at the same step on other pull requests too (for example #520).

Fix here, f297258: the job passes --skip-checkout-wheel, as the macOS wheel jobs already do, so the wheel is built and audited from the retained sdist only. My first attempt, 1a6a4b9 (mounting the whole checkout), only moved the failure to the second point and is undone by that commit. If you would rather have this fix as its own PR, say so and I will move it.

I also added the run-ci label, so that the two Delphes failures (#522) do not cancel the remaining jobs.

🤖 Generated with Claude Code

The manylinux job also built a wheel from the checkout, to compare it with
the one from the retained sdist. In MadGraph7 that build cannot work: the
checkout has no prepared models (only the sdist carries them, "release
prepared-model source store inventory is invalid"), and umami.h is a symlink
into madspace/, which the container does not mount.

The job now passes --skip-checkout-wheel, as the macOS wheel jobs do: the
shipped wheel is the one built and audited from the retained sdist. This
replaces the mount change of the previous commit, which is undone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ValentinHirschi ValentinHirschi added the run-ci Start the full PR CI on this PR's current head commit label Nov 21, 2026

@oliviermattelaer oliviermattelaer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. No correctness bugs found. One nit inline.

raise TypeError("options takes a TOML path, a TOML text or a mapping")
one_line = bool(source.strip()) and "\n" not in source
if one_line and (Path(source).expanduser().is_file() or "=" not in source):
if one_line and Path(source).expanduser().is_file():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: with the or "=" not in source clause removed, a mistyped one-line options path (no =, not an existing file) now falls through to the TOML parser and fails with a TOML syntax error, not "no such file". The error no longer says the input was meant as a path. Fix: when a one-line string is neither an existing file nor valid TOML and has no =, report that the file does not exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. This case is already covered a few lines below, in the except branch (lines 101–106): a one-line string that is neither an existing file nor valid TOML is refused with

runtime options '<text>' are not an existing file and not valid TOML: <TOML error>

so the message does say that the input may have been meant as a path. test_a_one_line_options_string_is_an_existing_file_or_toml checks it for a path in a missing directory, a bare word (opts) and x=y.toml. No change made; say if you would prefer a different wording.

🤖 Generated with Claude Code

- test_log_heartbeat_breaks_every_silence failed once on a loaded CI
  runner: with the test's 0.6 s cadence, the start line (due after 1 s) and
  the first status line were both due at the second beat, and the status
  line could come first. The test now sets the start delay to 0.2 s, so the
  start line is written at the first beat.
- The thread-count children of test_runtime_options count every thread of
  their process. On a many-core host numpy's BLAS pool added up to 63 and
  failed test_the_thread_bound_and_its_fallback unless OMP_NUM_THREADS was
  set outside. The children now set OPENBLAS_NUM_THREADS=1 and
  OMP_NUM_THREADS=1 themselves.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ValentinHirschi

Copy link
Copy Markdown
Contributor Author

Status of the run on f297258:

🤖 Generated with Claude Code

Upstream 27d880f8e, tests only:
- test_progress_eta.py::test_log_heartbeat_breaks_every_silence no longer
  depends on the order of two lines due at the same heartbeat (it failed
  twice in this pull request's CI);
- the thread-count children of test_runtime_options.py set numpy's BLAS
  threads to one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ValentinHirschi

Copy link
Copy Markdown
Contributor Author

Thanks for re-running the job. It failed the same way again, so this is not a one-off in this CI, and I pushed the fix (966b588); sorry that this dismisses the approval.

  • Cause: test_log_heartbeat_breaks_every_silence expects a step's start line before its first status line. With the test's shortened cadence both fall due at the same heartbeat, and the start line wins only if the step began within a fraction of a millisecond of the heartbeat thread. In this job the test runs late in one large pytest process, where that margin is not met. A 20 ms delay reproduces the failure every time; with the fix it passes.
  • Fix: upstream pyAmpliCol 27d880f8e, imported the usual way (tests only, two files). The test now lets the start line fall due well before the first heartbeat. Upstream's CI is green on that commit.
  • The same upstream commit makes the thread-count tests of test_runtime_options.py independent of numpy's BLAS threads, which removes the many-core failure mentioned in the description.

Nothing outside pyamplicol/tests/unit/ changes in this push. The two Delphes jobs will still fail until #522 is fixed on main.

🤖 Generated with Claude Code

@oliviermattelaer
oliviermattelaer merged commit c8da586 into main Nov 23, 2026
129 of 133 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM (wait ci) run-ci Start the full PR CI on this PR's current head commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants